Mapping A Maze Using MATLAB Image Processing Toolbox

Recently I saw an article about mapping a maze and I thought to myself; how could this be achieved using my favorite tool MATLAB :-)? Well it turns out that its a pretty simple task. Some functions used in this post require that you have MATLAB 2012a or higher installed, so if u do not then go away and get it.

Wow you are back, ok so lets begin, first we will look at the code that was used and then further down we will look at individual functions and what they were used to do.

The maze:

The code:

%% Map Maze
im = imread('maze.png');
bw = im2bw(im(1:287, 1:400), 0.45);
cc = bwconncomp(bw, 8);
obj = false(size(bw));
obj(cc.PixelIdxList{13}) = true;
sln = bwmorph(bwmorph(obj,'thin',Inf),'spur', Inf);
figure, imshow(imfuse(im,sln,'blend','Scaling','joint'))

clear Clears all variables from the MATLAB workspace.
im = imread(‘maze.png’);
Reads the maze image and stores it.
bw = im2bw(im(1:287, 1:400), 0.45); Converts the image to binary, scales it and stores it.
cc = bwconncomp(bw, 8); Find connecting components within the image.
obj(cc.PixelIdxList{13}) = true; Find the largest component and select it.
sln = bwmorph(bwmorph(obj,’thin’,Inf),’spur’,Inf); Use Morphological functions to refine image.
figure, imshow(imfuse(im,sln,’blend’,’Scaling’,’joint’)); Overlay and display images


solved maze

The end :-)

Wheatstone Bridge In MATLAB Simulink

The diagram below describes a Wheatstone bridge designed with MATLAB Simulink, The resistor designated [R x] can be replaced with a variable resistance material and used in the construction of a strain gauge.

Wheatstone bridge is an electrical circuit used to measure an unknown electrical resistance by balancing two legs of a bridge circuit, one leg of which includes the unknown component. Its operation is similar to the original potentiometer. It was invented by Samuel Hunter Christie in 1833 and improved and popularized by Sir Charles Wheatstone in 1843. One of the Wheatstone bridge’s initial uses was for the purpose of soils analysis and comparison read more

Simulink Circuit Schematic:
wheatstone bridge

DC Voltage = 100 v
R 1 = 10 ohm, R 2 = 10 ohm, R 3 = 10 ohm, R x = 5 ohm
Connect the components as seen in the diagram then run the simulation, let [R x] be the variable resistance material; vary the resistance to see the difference in current.

NB: Resistors were taken from the  powerlib Simulink components [Parallel RLC Branch]