-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDBSCAN_Double.m
executable file
·64 lines (51 loc) · 1.48 KB
/
DBSCAN_Double.m
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
function [outputArg1,outputArg2] = DBSCAN_Double(img,pathsave_Detected,k)
im = im2double (img);
idm = im < 0.12; %% Theta value of the image- Can also be adjusted w.r.t. the Brightness/Contrast of the images.
im(idm) = NaN;
indices = find(isnan(im) == 1);
[I,J] = ind2sub(size(im),indices);
id (:,1) = I;
id (:,2)=J;
eps = 1 ;
minpt = 5;
idx = dbscan(id, eps,minpt);
%
vis = [id,idx];
indices_vis = find(vis(:,3) <0);
vis (indices_vis,:) = [];
% Logical
BW = zeros (size(im));
for i = 1:length (vis)
BW(vis(i,1),vis(i,2))=1;
end
BW_log = logical(BW);
% Centroids
stats = regionprops(BW_log,'centroid');
centroids = cat(1,stats.Centroid);
%% New- 2nd DBSCAN
BW_2 = BW;
[II,JJ] = ind2sub(size(BW_2),find(BW_2==1));
idd (:,1) = II; idd (:,2)=JJ;
db_2 = dbscan(idd,1,5);
viss = [idd,db_2];
indices_viss = find(viss(:,3) <0);
viss (indices_viss,:) = [];
BW_2_new = zeros (size(im));
for j = 1:length (viss)
BW_2_new(viss(j,1),viss(j,2))=1;
end
% Centroids
BW_2_log = logical(BW_2_new);
statss = regionprops(BW_2_log,'centroid');
centroidss = cat(1,statss.Centroid);
%% Bounding Boxes
xlen = 250 ; ylen = 250;
for f= 1: length (centroidss)
clearvars xmin ymin F
xmin = centroidss(f,1) - 125 ; ymin = centroidss(f,2) - 125;
F = imcrop(img, [xmin ymin xlen ylen]);
baseFileName = sprintf('%d%d.png',k,f);
fullFileName = fullfile(pathsave_Detected, baseFileName);
imwrite(F, fullFileName);
end
end