|
1 |
| -clear all; close all; clc; % clear console and close all windows |
| 1 | +clear all; close all; clc; % clear everything |
2 | 2 |
|
3 | 3 | im = imread('objects.jpg'); % circles are greater than rectangles
|
4 |
| -% im = imread('objects_1.jpg'); % circles and rectangles are equal |
| 4 | +%im = imread('objects_1.jpg'); % circles and rectangles are equal |
5 | 5 |
|
6 |
| -[h, w, ~] = size(im); % get height and width of the image |
| 6 | +[h, w, ~] = size(im); % get height and width of image |
7 | 7 |
|
8 | 8 | distR = double(im(:, :, 1)) - 0; % since we have only one dimension, first dimension of image will be enough
|
9 | 9 |
|
|
17 | 17 | results = bwmorph(results, 'open', 2);
|
18 | 18 | results = bwmorph(results, 'close', 2);
|
19 | 19 |
|
20 |
| - |
21 | 20 | stats = regionprops(results, 'BoundingBox'); % this gets the stats of each object
|
22 | 21 |
|
23 | 22 | figure, imshow(results);
|
24 | 23 | hold on
|
25 | 24 |
|
26 | 25 | circle_num = 0;
|
27 | 26 | rec_num = 0;
|
| 27 | + |
28 | 28 | for i = 1 : length(stats)
|
29 | 29 | dimensions = stats(i).BoundingBox;
|
30 |
| - text = sprintf(int2str(i)); % put the iteration number to variable to print as string |
| 30 | + inserted_text = sprintf(int2str(i)); % put the iteration number to variable to print as string |
31 | 31 |
|
32 |
| - 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 |
| 32 | + 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 |
33 | 33 | circle_num = circle_num+1;
|
34 |
| - hText = text(dimensions(1) + dimensions(3)/2,dimensions(2)+dimensions(4)/2,text,'Color',[1 0 1],'FontSize',15); % put the pink string to image |
35 |
| - elseif dimensions(3) ~= dimensions(4) |
| 34 | + hText = text(dimensions(1) + dimensions(3)/2,dimensions(2)+dimensions(4)/2,inserted_text,'Color',[1 0 1],'FontSize',15); %put the pink string to image |
| 35 | + elseif dimensions(3)~= dimensions(4) |
36 | 36 | rec_num = rec_num+1;
|
37 |
| - hText = text(dimensions(1) + dimensions(3)/2,dimensions(2)+dimensions(4)/2,text,'Color',[0.1 0 0.5],'FontSize',15); % put the blue string to image |
| 37 | + hText = text(dimensions(1) + dimensions(3)/2,dimensions(2)+dimensions(4)/2,inserted_text,'Color',[0.1 0 0.5],'FontSize',15); %put the blue string to image |
38 | 38 | end
|
39 | 39 |
|
40 | 40 | rectangle('Position', stats(i).BoundingBox, 'EdgeColor', 'g', 'LineWidth', 3); % draw a rectangle
|
|
0 commit comments