1- % Hakan Kurtulus
2- % HXMKGP
3-
41clear all ; close all ; clc ; % clear defined variable from previous run
52
63im = imread(' objects.jpg' ); % circles are greater than rectangles
74% im = imread('objects_1.jpg'); %circles and rectangles are equal
85
96[h , w , ~ ] = size(im ); % get height and width of image
107
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
129
1310% 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
1512
1613thres = 13000 ;
1714results = d2 <= thres ; % we set the boundary for image not to detect image itself but objects
2118results = bwmorph(results , ' close' , 2 );
2219
2320
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
2522
2623figure , imshow(results );
2724hold on
3027rec_num = 0 ;
3128for i = 1 : length(stats )
3229
33- dimentions = stats(i ).BoundingBox;
30+ dimensions = stats(i ).BoundingBox;
3431
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
3633
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
3835 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 )
4138 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
4340 end
4441
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
4643
4744end
4845
5451elseif circle_num < rec_num
5552 final = ' Rectangle numbers are greater than circle numbers.'
5653elseif circle_num > rec_num
57- final = ' Circle numbers are greater than rectangler numbers.'
54+ final = ' Circle numbers are greater than rectangle numbers.'
5855end
5956
0 commit comments