From: abhi abhi on
I need to recognize square , rectangle , circle , triangle.... how can i recognise these objects? plz send me the code to recognise the object shapes.


rgbImage = imread('squ.png');
[rows columns numberOfColorBands] = size(rgbImage);
subplot(3, 2, 1);
imshow(rgbImage, []);
title('Original color Image');
set(gcf, 'Position', get(0,'Screensize'));
grayImage = rgb2gray(rgbImage);
subplot(3, 2, 2);
imshow(grayImage, []);
title('Converted to gray scale');
cannyImage = edge(grayImage,'canny');
subplot(3, 2, 3);
imshow(cannyImage, []);
title('Canny Edge Image');
windowSize =10;
halfWidth = floor(windowSize/2);
dilatedImage = zeros(rows, columns);
for col = (halfWidth+1) : columns - halfWidth
x1 = col - halfWidth;
x2= col + halfWidth;
for row = (halfWidth+1) : rows - halfWidth
y1 = row - halfWidth;
y2 = row + halfWidth;
dilatedImage(row, col) = max(max(cannyImage(y1:y2, x1:x2)));
end
end
subplot(3, 2, 4);
imshow(dilatedImage, []);
caption = sprintf('Dilated with a window size of %d',windowSize);
title(caption);
% erosion is local minimum
windowSize = 10;
halfWidth = floor(windowSize/2);
erodedImage = zeros(rows, columns);
for col = (halfWidth+1) : columns - halfWidth
x1 = col - halfWidth;
x2= col + halfWidth;
for row = (halfWidth+1) : rows - halfWidth
y1 = row - halfWidth;
y2 = row + halfWidth;
erodedImage(row, col) = min(min(dilatedImage(y1:y2, x1:x2)));
end
end
subplot(3, 2, 5);
imshow(erodedImage, []);
caption = sprintf('Eroded image with a window size of %d',windowSize);
title(caption);
[B,L] = bwboundaries(erodedImage, 'noholes');
stats=regionprops(L,'all');
 | 
Pages: 1
Prev: synchronize.m for Timeseries
Next: sortrows