迷宫路线寻找算法的matlab仿真
1.问题描述:
迷宫创建算法和迷宫路径寻找算法
2.部分程序:
% Clean up.
clc;
close all;
clear all;
fontSize = 20; % Font size for image captions.
% Change the current folder to the folder of this m-file.
% (The line of code below is from Brett Shoelson of The Mathworks.)
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = 'C:\Documents and Settings\tk2013\My Documents\My Pictures\MISC\Mazes';
if ~exist(startingFolder, 'dir')
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
continueWithAnother = true;
promptMessage = sprintf('Please specify a maze image (in the next window).\nThis program will attempt to solve the maze.');
button = questdlg(promptMessage, 'maze_solution', 'OK', 'Cancel', 'OK');
if strcmpi(button, 'Cancel')
continueWithAnother = false;
end
while continueWithAnother
% Get the name of the maze image file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select maze image file');
if baseFileName == 0
% User hit cancel. Bail out.
return;
end
fullFileName = fullfile(folder, baseFileName);
% Here are some hard coded file names for ease in developing and debugging,
% so we don't have to use uigetfile() all the time.
% Gotten from http://www.erclc.org/StaffPages/David/Mazes/Maze1.gif
% This maze works fine.
% fullFileName = fullfile(folder, 'Maze1.gif');
% Gotten from http://www.mattneuman.com/maze.htm
% This is a test maze that won't work because it is not a "non-perfect maze."
% fullFileName = fullfile(folder, 'Maze of Sisyphus.gif');
% Open the maze image file.
originalImage = imread(fullFileName);
[rows cols numberOfColorBands] = size(originalImage);
% Convert to monochrome for processing.
if numberOfColorBands > 1
% Convert to monochrome.
redPlane = originalImage(:, :, 1);
greenPlane = originalImage(:, :, 2);
bluePlane = originalImage(:, :, 3);
% Find the standard deviation of each color channel.
redStdDev = std(single(redPlane(:)));
greenStdDev = std(single(greenPlane(:)));
blueStdDev = std(single(bluePlane(:)));
% Take the color channel with the highest contrast.
% Transfer it into a monochrome image. This will be the one that we use.
if redStdDev >= greenStdDev && redStdDev >= blueStdDev
% Red has most contrast - use that channel.
monoImage = single(redPlane);
elseif greenStdDev >= redStdDev && greenStdDev >= blueStdDev
% Green has most contrast - use that channel.
monoImage = single(greenPlane);
else
% Blue has most contrast - use that channel.
monoImage = single(bluePlane);
end
else
monoImage = single(originalImage);
end
% Now we have a monochrome image that we can use to solve the maze.
% Display the results of this step.
close all; % Close any prior windows that are open from a prior run.
subplot(2, 2, 1);
imshow(monoImage, []);
title('Original Image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
% Scale image to 0-255.
maxValue = max(max(monoImage));
minValue = min(min(monoImage));
monoImage = uint8(255 * (single(monoImage) - minValue) / (maxValue - minValue));
% Threshold to get the walls. This will also sharpen up blurry, fuzzy wall edges.
thresholdValue = uint8((maxValue + minValue) / 2);
binaryImage = 255 * (monoImage < thresholdValue);
% Display the results of this step.
subplot(2, 2, 2);
imshow(binaryImage, []);
title('Binary Image - The walls are white here, instead of black', 'FontSize', fontSize);
% Label the image to identify discrete, separate walls.
[labeledImage numberOfWalls] = bwlabel(binaryImage, 4); % Label each blob so we can make measurements of it
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels
% Display the results of this step.
subplot(2, 2, 3);
imshow(coloredLabels);
caption = sprintf('Labeled image of the %d walls, each a different color', numberOfWalls);
title(caption, 'FontSize', fontSize);
if numberOfWalls ~= 2
message = sprintf('This is not a "perfect maze" with just 2 walls.\nThis maze appears to have %d walls,\nso you may get unexpected results.', numberOfWalls);
uiwait(msgbox(message));
end
3.仿真结论:
C67
相关文章
- 基于遗传优化算法和模拟退火法求解TSP问题(Matlab代码实现)
- 基于蜜蜂算法的资源受限项目优化调度(Matlab代码实现)
- 【图像处理】基于matlab萤火虫算法图像对比度增强
- m基于多用户MIMO系统的分布式可重构注水算法的matlab仿真
- m基于基站休眠的LTE-A异构网络中节能算法matlab仿真
- m基于rbf神经网络和遗传算法优化的MIMO-OFDM系统信道估计算法matlab仿真
- m基于PTS+TR的OFDM系统PAPR联合抑制算法matlab仿真
- 基于模拟退火算法的车间调度优化matlab仿真,输出甘特图
- 基于遗传优化算法小车避障问题matlab仿真,地图为栅格地图
- m基于优化算法的多车辆的路径规划matlab仿真,对比GA,PSO以及烟花算法
- 基于互信息和归一化互信息的医学图像配准算法matlab仿真
- m基于sift特征提取和模板匹配的车标识别算法matlab仿真
- 基于形态学处理算法的迷宫路线搜索matlab仿真
- 基于meanshift算法的目标聚类和目标跟踪matlab仿真
- 《智能优化算法及其MATLAB实现》书籍出版啦
- 传感器|基于改进贪心算法的最佳传感器位置选择(Matlab代码实现)
- 基于6自由度飞行器的EKF和INS融合算法的MATLAB仿真
- m移动通信系统中越区切换算法的matlab仿真,对比MASN,ASUR,OP
- 基于平均不同分辨率的共振峰跟踪算法matlab仿真
- m基于SPA和积译码算法的LDPC误码率matlab仿真
- 基于Astar算法的栅格地图最优路径搜索matlab仿真,可以修改任意数量栅格
- m基于ICP和网格拉普拉斯变形算法的三维模型配准matlab仿真
- m基于LK光流提取算法的三维医学图像运动估计matlab仿真
- 大气湍流自适应光学校正算法matlab仿真,包括涡旋光束,大气湍流影响,不同轨道角动量OAM态之间的串扰,校正等