필터 지우기
필터 지우기

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개)

카테고리

Help CenterFile Exchange에서 Labyrinth problems에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by