Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
omegion committed Jan 6, 2019
1 parent 396d793 commit ed1c0ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# MatLab - Primitive Object Detection

This small project detects the circular and rectangular objects in the given image.

## Example

![example](https://i.imgur.com/YIDd9P2.png)
18 changes: 9 additions & 9 deletions main.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
clear all; close all; clc; % clear console and close all windows
clear all; close all; clc; % clear everything

im = imread('objects.jpg'); % circles are greater than rectangles
% im = imread('objects_1.jpg'); % circles and rectangles are equal
%im = imread('objects_1.jpg'); % circles and rectangles are equal

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

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

Expand All @@ -17,24 +17,24 @@
results = bwmorph(results, 'open', 2);
results = bwmorph(results, 'close', 2);


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

figure, imshow(results);
hold on

circle_num = 0;
rec_num = 0;

for i = 1 : length(stats)
dimensions = stats(i).BoundingBox;
text = sprintf(int2str(i)); % put the iteration number to variable to print as string
inserted_text = sprintf(int2str(i)); % put the iteration number to variable to print as string

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
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
circle_num = circle_num+1;
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
elseif dimensions(3) ~= dimensions(4)
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
elseif dimensions(3)~= dimensions(4)
rec_num = rec_num+1;
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
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
end

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

0 comments on commit ed1c0ca

Please sign in to comment.