-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtry2.m
More file actions
41 lines (32 loc) · 655 Bytes
/
try2.m
File metadata and controls
41 lines (32 loc) · 655 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
clear;
close all;
clc;
%Read the image
img = imread('objects1.png');
%View the image
figure,
imshow(img);
%Convert into Grayscale Image
img_gray = rgb2gray(img);
figure,
imshow(img_gray);
% Conver to a binary version of image
BW = imbinarize(img_gray, 0.7);
figure,
imshow(BW);
% Complement the image
BW1 = imcomplement(BW);
figure,
imshow(BW1);
% Fill the holes to make a solid object
BW2 = imfill(BW1,'holes');
figure,
imshow(BW2);
% Filter the image
BW3 = bwareaopen(BW2, 1);
% Remove objects that touch the border of the image
BW4 = imclearborder(BW3);
% Count the number of objects
objects = bwconncomp(BW4);
disp('Count: ');
disp(objects);