-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskelBasic.m
91 lines (79 loc) · 2.03 KB
/
skelBasic.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
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
function skel = skelBasic(im,gaussOrder,branch,thresh,neighborhood)
%Naive approach to skeletonization of a heatmap by local thresholding and
%then performing a skeletonization
%
% INPUT:
% im - the input image, will attempt to convert color images
% gaussOrder - the order of the gaussian filter
% thresh - the threshold from 0-256 of data to examine
% branch - the minimum size of a branch when pruning
% neighborhood -
%
% OUTPUT:
% skel - the skeletonization
if 2 < size(size(im),2)
warning('Attempting to convert multidimensional image to grayscale')
img = rgb2gray(im);
elseif size(size(im),2) < 2
error('Not an image?')
else
img = im;
end
if 0 < gaussOrder
imblur = imgaussfilt(img,gaussOrder);
elseif gaussOrder < 0
error('Negative Gauss order specified');
else
imblur = img;
end
%{
%if thres1 <
if thres < 0
error('Negative threshold entered');
elseif 256 < thres
error('Threshold must be <=256');
else
imbw = imbinarize(imblur,thres/256);
end
%}
T = adaptthresh(imblur,0.5,'ForegroundPolarity','bright','NeighborhoodSize',neighborhood);
imbw = imbinarize(imblur,T);
for i=1:size(im,2)
for j=1:size(im,1)
% imbw(j,i)=0;
if imbw(j,i) == 1 && im(j,i) < thresh
imbw(j,i) = 0;
end
end
end
if 0 < branch
skel = bwskel(imbw,'MinBranchLength',branch);
elseif branch < 0
error('Negative minimum branch specified');
else
skel = bwskel(imbw);
end
flag = false;
for i=1:size(skel,2)
if flag
break
end
for j=1:size(skel,1)
if(skel(j,i) == 1)
flag = true;
break
end
end
end
if ~flag
figure
subplot(2,2,1), imshow(img);
subplot(2,2,2), imshow(imblur);
subplot(2,2,3), imshow(single(imbw));
else
figure
subplot(2,2,1), imshow(labeloverlay(img,skel,'Transparency',0));
subplot(2,2,2), imshow(labeloverlay(imblur,skel,'Transparency',0));
subplot(2,2,3), imshow(labeloverlay(single(imbw),skel,'Transparency',0));
end
end