Getting the maze solution to not wrap around the maze itself, and be centered off the walls.
2 次查看(过去 30 天)
显示 更早的评论
function C = solvemaze(A)
A = imread('maze09.png');
[rows cols numberOfColorBands] = size(A);
monoImage = single(A);
maxValue = max(max(monoImage));
minValue = min(min(monoImage));
monoImage = uint8(255 * (single(monoImage) - minValue) / (maxValue - minValue));
thresholdValue = uint8((maxValue + minValue) / 2);
binaryImage = 255 * (A < thresholdValue);
subplot(2, 2, 2);
imshow(binaryImage, []);
[labeledImage numberOfWalls] = bwlabel(binaryImage, 4);
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle');
subplot(2, 2, 3);
imshow(coloredLabels);
binaryImage2 = (labeledImage == 1);
subplot(2, 2, 4);
imshow(binaryImage2, []);
dilationAmount = 7;
dilatedImage = imdilate(binaryImage2, ones(dilationAmount));
figure;
subplot(2, 2, 1);
imshow(dilatedImage, []);
filledImage = imfill(dilatedImage, 'holes');
subplot(2, 2, 2);
imshow(filledImage, []);
erodedImage = imerode(filledImage, ones(dilationAmount));
subplot(2, 2, 3);
imshow(erodedImage, []);
solutionA = filledImage;
solutionA(erodedImage) = 0;
subplot(2, 2, 4);
imshow(solutionA, []);
if numberOfColorBands == 1
redPlane = monoImage;
greenPlane = monoImage;
bluePlane = monoImage;
end
redPlane(solutionA) = 255;
greenPlane(solutionA) = 0;
bluePlane(solutionA) = 0;
solvedImage = cat(3, redPlane, greenPlane, bluePlane);
figure;
imshow(solvedImage);
C = solvedImage;
if logical(C) == 0
C = [];
else
C = C;
end
end
The solution path hugs the walls and I need it to not wrap around the entire maze and be centered. Using only morphological commands.
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Labyrinth problems 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!