-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshape.m
31 lines (29 loc) · 1.03 KB
/
shape.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
%We have seven steps:
%1 - Read the RGB (colored) image in from user.
image= imread(img);
%2 - Convert image from (RGB) colored to gray image.
grayimg= im2gray(image);
%3 - Threshold the image (convert gray image to binary image)
%4 - Invert the binary image (in order to speed up the time of processing).
imgbin= ~imbinarize(grayimg);
%5 - Find the boundaries concentrate.
B = bwboundaries(imgbin,'no holes');
%6 - Determine shapes properties (ratio of dimensions, roundness).
stats= regionprops(B,'all');
%7 - Classify shapes according to its properties.
% Square = 3 = (1 + 2) = (X=Y + Extent = 1)
% Rectangular = 2 = (0 + 2) = (only Extent = 1)
% Circle = 1 = (1 + 0) = (X=Y , Extent < 1)
% UNKNOWN = 0
W = uint8(abs(stats.BoundingBox(3)-stats.BoundingBox(4));
W= W+ 2 * uint8((stats.Extent - 1);
switch W(i)
case 1
printf("The shape is a circle");
case 2
printf("The shape is a rectangle");
case 3
printf("The shape is a square");
otherwise
printf("unknown")
end