1
- % Hakan Kurtulus
2
- % HXMKGP
3
-
4
1
clear all ; close all ; clc ; % clear defined variable from previous run
5
2
6
3
im = imread(' objects.jpg' ); % circles are greater than rectangles
7
4
% im = imread('objects_1.jpg'); %circles and rectangles are equal
8
5
9
6
[h , w , ~ ] = size(im ); % get height and width of image
10
7
11
- distR = double(im(: , : , 1 )) - 0 ; % since we have only one dimention , first dimention of image will be enough
8
+ distR = double(im(: , : , 1 )) - 0 ; % since we have only one dimension , first dimension of image will be enough
12
9
13
10
% L2 distance
14
- d2 = (distR .^ 2 ); % highlited to background, at the end we will have so big number for background but white parts will be close to 0
11
+ d2 = (distR .^ 2 ); % highlighted to background, at the end we will have so big number for background but white parts will be close to 0
15
12
16
13
thres = 13000 ;
17
14
results = d2 <= thres ; % we set the boundary for image not to detect image itself but objects
21
18
results = bwmorph(results , ' close' , 2 );
22
19
23
20
24
- stats = regionprops(results , ' BoundingBox' ); % this gets the stats of each object, we used this with Gabor
21
+ stats = regionprops(results , ' BoundingBox' ); % this gets the stats of each object
25
22
26
23
figure , imshow(results );
27
24
hold on
30
27
rec_num = 0 ;
31
28
for i = 1 : length(stats )
32
29
33
- dimentions = stats(i ).BoundingBox;
30
+ dimensions = stats(i ).BoundingBox;
34
31
35
- YourText = sprintf(int2str(i )); % put the iteration numbe rto variable to print as string
32
+ YourText = sprintf(int2str(i )); % put the iteration number to variable to print as string
36
33
37
- if dimentions (3 )== dimentions (4 ) % 3 and 4 stand for height and width of object, if the values are equal it is circle ortherwise ellipse
34
+ if dimensions (3 )== dimensions (4 ) % 3 and 4 stand for height and width of object, if the values are equal it is circle otherwise ellipse
38
35
circle_num = circle_num + 1 ;
39
- hText = text(dimentions (1 ) + dimentions (3 )/2 ,dimentions (2 )+dimentions (4 )/2 ,YourText ,' Color' ,[1 0 1 ],' FontSize' ,15 ); % put the pink string to image
40
- elseif dimentions (3 )~= dimentions (4 )
36
+ hText = text(dimensions (1 ) + dimensions (3 )/2 ,dimensions (2 )+dimensions (4 )/2 ,YourText ,' Color' ,[1 0 1 ],' FontSize' ,15 ); % put the pink string to image
37
+ elseif dimensions (3 )~= dimensions (4 )
41
38
rec_num = rec_num + 1 ;
42
- hText = text(dimentions (1 ) + dimentions (3 )/2 ,dimentions (2 )+dimentions (4 )/2 ,YourText ,' Color' ,[0.1 0 0.5 ],' FontSize' ,15 ); % put the blue string to image
39
+ hText = text(dimensions (1 ) + dimensions (3 )/2 ,dimensions (2 )+dimensions (4 )/2 ,YourText ,' Color' ,[0.1 0 0.5 ],' FontSize' ,15 ); % put the blue string to image
43
40
end
44
41
45
- rectangle(' Position' , stats(i ).BoundingBox, ' EdgeColor' , ' g' , ' LineWidth' , 3 ); % draw a rectangle also we used this with Gabor
42
+ rectangle(' Position' , stats(i ).BoundingBox, ' EdgeColor' , ' g' , ' LineWidth' , 3 ); % draw a rectangle
46
43
47
44
end
48
45
54
51
elseif circle_num < rec_num
55
52
final = ' Rectangle numbers are greater than circle numbers.'
56
53
elseif circle_num > rec_num
57
- final = ' Circle numbers are greater than rectangler numbers.'
54
+ final = ' Circle numbers are greater than rectangle numbers.'
58
55
end
59
56
0 commit comments