-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindCentre.m
More file actions
94 lines (76 loc) · 2.09 KB
/
Copy pathfindCentre.m
File metadata and controls
94 lines (76 loc) · 2.09 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function centres=findcentre(snap1)
min_area=1100;
location1=[];
location2=[];
rr=snap1(:,:,1);
gg=snap1(:,:,2);
bb=snap1(:,:,3);
redz=((rr>=80) & (rr<=255) & (gg>=0) & (gg<=50) & (bb>=0) & (bb<=50));
% figure,imshow(redz);
%title('before filter');
%redz=medfilt2(redz);
%figure,imshow(redz);
%title('after filter');
% redz = bwareaopen(redz,10); %% 10 se kam pixels ko hatao
% figure,imshow(redz);
% title('area open');
se=strel('disk',5);
redz=imclose(redz,se);
%figure,imshow(redz);
redz=imfill(redz,'holes'); %closed component ke ander vali noise ka removal
%figure,imshow(redz);
L1 = bwlabel(redz);%connected componenets label
a1 = regionprops(L1, 'Area');
area=[a1.Area]
f1=find(area>min_area);
im1=ismember(L1,f1);% agar l1 ,f1 ka member hai
L1=im1.*L1;
c1= regionprops(L1, 'Centroid');
g1=[c1.Centroid];
g1(isnan(g1))=[]; %remove nan error
counter=1;
for i=1:length(g1)
if mod(i,2)~=0
location1(counter,2)=g1(i);
else
location1(counter,1)=g1(i);
counter=counter+1;
end
end
bluez=((rr>=0) & (rr<=55) & (gg>=0) & (gg<=55) & (bb>=65) & (bb<=200));
%figure,imshow(bluez);
%title('before filter');
bluez=medfilt2(bluez);
%figure,imshow(bluez);
title('after filter');
% redz = bwareaopen(redz,10); %% 10 se kam pixels ko hatao
% figure,imshow(redz);
% title('area open');
se=strel('disk',5);
bluez=imclose(bluez,se);
%figure,imshow(bluez);
title('image closing');
bluez=imfill(bluez,'holes'); %connected component ke ander vali noise ka removal
%figure,imshow(bluez);
title('image after filling holes ')
L1 = bwlabel(bluez);
a1 = regionprops(L1, 'Area');
area=[a1.Area]
f1=find(area>min_area);
im1=ismember(L1,f1);%% returns 1 jaha pe area required limit mein hai
L1=im1.*L1;
c1= regionprops(L1, 'Centroid');
g1=[c1.Centroid];
g1(isnan(g1))=[]; %remove nan eroor
counter=1;
for i=1:length(g1)
if mod(i,2)~=0
location2(counter,2)=g1(i);
else
location2(counter,1)=g1(i);
counter=counter+1;
end
end
location1
location2
centres=vertcat(location1,location2);