0
点赞
收藏
分享

微信扫一扫

基于形态学处理算法的迷宫路线搜索matlab仿真

1.算法描述 形态学是图像处理中应用最为广泛的技术之一,主要用于从图像中提取对表达和描绘区域形状有意义的图像分量,使后续的识别工作能够抓住目标对象最为本质的形状特征,如边界和连通区域等。同时像细化、像素化和修剪毛刺等技术也常应用于图像的预处理和后处理中,成为图像增强技术的有力补充。形态学的基本思想是利用一种特殊的结构元来测量或提取输入图像中相应的形状或特征,以便进一步进行图像分析和目标识别。

形态学处理

腐蚀:对核范围内的像素,只要有一个是非前景,则设置为背景;比如对于33的核函数,如果当前像素的33邻域内像素全是前景则保留,否者设置为背景;常用于去除较小噪声,分离物体。

膨胀:对核范围内的像素,只要有一个是前景,则设置为前景;比如对于33的核函数,如果当前像素的33邻域内像素有一个是前景则当前像素设置为前景,否者设置为背景;通常膨胀会用在腐蚀之后,腐蚀会去除小的噪声,但也会把前景变瘦,而膨胀则会再变胖。

开运算:先腐蚀,再膨胀;主要处理噪点在前景外的图像。

闭运算:先膨胀,再腐蚀;主要处理噪点在前景内的图像。

如果图像前景内外都有噪点,先开再闭 或 先闭再开 都可以得到前景图像。

形态学梯度:膨胀-腐蚀;可以得到前景轮廓。

顶帽运算:原图-开运算;可以得到前景外的噪点。

黑帽运算:闭运算-原图;可以得到前景内的噪点。

   这个课题适用于“完美迷宫”。 不使用搜索或优化方法,仅使用形态学和标准图像处理方法。 仅针对彩色和单色图像进行了测试。 包括演示迷宫,但您可以指定自己的迷宫图像。 迷宫图像应该在浅色背景上有深色墙壁。 迷宫可能会被白色包围,或者直接走到图像的边缘,并将外墙作为图像的外边界。

2.仿真效果预览 matlab2022a仿真结果如下:

2.png1.png3.png4.png

3.MATLAB核心程序

	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
 
	binaryImage2 = (labeledImage == 1);
	% Display the results of this step.
	subplot(2, 2, 4);
	imshow(binaryImage2, []);
	title('One of the walls', 'FontSize', fontSize);
 
	% Dilate the walls by a few pixels
	dilationAmount = 7; % Number of pixels to dilate and erode.
 
	dilatedImage = imdilate(binaryImage2, ones(dilationAmount));
 
	figure;  % Create another, new figure window.
	set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
	% Display the results of this step.
	subplot(2, 2, 1);
	imshow(dilatedImage, []);
	title('Dilation of one wall', 'FontSize', fontSize);
 
	filledImage = imfill(dilatedImage, 'holes');
	% Display the results of this step.
	subplot(2, 2, 2);
	imshow(filledImage, []);
	title('Now filled to get rid of holes', 'FontSize', fontSize);

举报

相关推荐

0 条评论