Skip to content

Commit ed1c0ca

Browse files
author
omegion
committedJan 6, 2019
Update README.md
1 parent 396d793 commit ed1c0ca

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed
 

‎README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
# MatLab - Primitive Object Detection
2+
3+
This small project detects the circular and rectangular objects in the given image.
4+
5+
## Example
6+
7+
![example](https://i.imgur.com/YIDd9P2.png)

‎main.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
clear all; close all; clc; % clear console and close all windows
1+
clear all; close all; clc; % clear everything
22

33
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
55

6-
[h, w, ~] = size(im); % get height and width of the image
6+
[h, w, ~] = size(im); % get height and width of image
77

88
distR = double(im(:, :, 1)) - 0; % since we have only one dimension, first dimension of image will be enough
99

@@ -17,24 +17,24 @@
1717
results = bwmorph(results, 'open', 2);
1818
results = bwmorph(results, 'close', 2);
1919

20-
2120
stats = regionprops(results, 'BoundingBox'); % this gets the stats of each object
2221

2322
figure, imshow(results);
2423
hold on
2524

2625
circle_num = 0;
2726
rec_num = 0;
27+
2828
for i = 1 : length(stats)
2929
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
3131

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
3333
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)
3636
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
3838
end
3939

4040
rectangle('Position', stats(i).BoundingBox, 'EdgeColor', 'g', 'LineWidth', 3); % draw a rectangle

0 commit comments

Comments
 (0)