Make black and white pixel image of a grid

3 views (last 30 days)
I have this function which generates a 12x12 maze with lines as borders of the maze. I need to convert it into a monochromatic image of 25x25 with each black pixel being boundary and each white pixel being the available path.
As maze is generated randomly, I need to update the monochromatic image maze with the original maze.
Actual maze (randomly generated from code) is attached.
Kindly help me out in this regard.
function show_maze(row, col, rr, cc, ptr_left, ptr_up, ptr_right, ptr_down,h)
figure(h)
line([.5,col+.5],[.5,.5]) % draw top border
line([.5,col+.5],[row+.5,row+.5]) % draw bottom border
line([.5,.5],[1.5,row+.5]) % draw left border
line([col+.5,col+.5],[.5,row-.5]) % draw right border
for ii=1:length(ptr_right)
if ptr_right(ii)>0 % right passage blocked
line([cc(ii)+.5,cc(ii)+.5],[rr(ii)-.5,rr(ii)+.5]);
hold on
end
if ptr_down(ii)>0 % down passage blocked
line([cc(ii)-.5,cc(ii)+.5],[rr(ii)+.5,rr(ii)+.5]);
hold on
end
end
axis equal
axis([.5,col+.5,.5,row+.5])
axis off
set(gca,'YDir','reverse')
return

Answers (1)

Walter Roberson
Walter Roberson on 29 May 2017
If you have the Computer Vision toolbox, then: https://www.mathworks.com/help/vision/ref/insertshape.html

Community Treasure Hunt

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

Start Hunting!