-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathShapesIndex.m
84 lines (63 loc) · 1.4 KB
/
ShapesIndex.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
clearvars;
clc;
close all;
img = imread('shapes.png');
figure;
imshow(img,[]);
title("Orginal");
idx_4 = bwlabel(img,4);
figure;
imshow(idx_4);
title("After Matlab Indexation");
shape_index_values = obliczWspolczynniki(idx_4);
[Y, X] = size(idx_4);
r=regionprops(shape_index_values,'Centroid');
for i=1:length(r)
text(r(i).Centroid(1),r(i).Centroid(2),['\color{magenta}',num2str(i)]);
end
for y = 1:Y
for x = 1:X
pixel = idx_4(y,x);
if (pixel ~= 0 && ~(shape_index_values(pixel,2) > 0.33 && shape_index_values(pixel,2) < 0.66))
idx_4(y,x) = 0;
end
end
end
figure;
imshow(idx_4);
title("After removing squares");
%%
close all;
figure;
real_img = imread('shapesReal.png');
imshow(real_img);
title("Real Orginal");
figure;
real_bw=im2bw(real_img,0.23);
imshow(real_bw);
title("Bin Img");
figure;
real_cmp=imcomplement(real_bw);
imshow(real_cmp);
title("Competed");
mask=strel('rectangle',[5,5])
real_erod = imerode(real_cmp,mask);
figure;
imshow(real_erod);
title("After Erosion");
idx_4 = bwlabel(real_erod,4);
figure;
imshow(idx_4,[]);
title("After Indexation");
shape_index_values = obliczWspolczynniki(idx_4);
[Y, X] = size(idx_4);
for y = 1:Y
for x = 1:X
pixel = idx_4(y,x);
if (pixel ~= 0 && (shape_index_values(pixel,1) < 0.75) && ~(shape_index_values(pixel,2) <0.00001))
idx_4(y,x) = 0;
end
end
end
figure;
imshow(idx_4);