-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcanny_edge.m
More file actions
76 lines (51 loc) · 1.18 KB
/
canny_edge.m
File metadata and controls
76 lines (51 loc) · 1.18 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
clear all;
close all;
I = imread('0a747cb3-c720-4572-a661-ab5670a5c42e.png');
imshow(I);
I_gray = rgb2gray(I);
I_hc = imadjust(I_gray);
[~,threshold] = edge(I_hc,'sobel');
fudgeFactor = 0.5;
BWs = edge(I_hc,'sobel',threshold * fudgeFactor);
imshow(BWs);
se90 = strel('line',3,75);
se0 = strel('line',3,0);
BWsdil = imdilate(BWs,[se90 se0]);
imshow(BWsdil)
BWdfill = imfill(BWsdil, 'holes');
imshow(BWdfill)
BWnobord = imclearborder(BWdfill,1);
imshow(BWnobord)
seD = strel('diamond',1);
BWfinal = imerode(BWnobord,seD);
BWfinal = imerode(BWfinal,seD);
f=figure;
imshow(BWfinal)
%% Second pass
[~,threshold] = edge(I_hc,'sobel');
fudgeFactor = 0.5;
BWsv2 = edge(BWfinal,'sobel',threshold * fudgeFactor);
f=figure;
imshow(BWsv2)
BWsdil2 = imdilate(BWsv2,[se90 se0]);
imshow(BWsdil2)
BWdfill2 = imfill(BWsdil2, 'holes');
imshow(BWdfill2)
BWnobord2 = imclearborder(BWdfill2,1);
imshow(BWnobord2)
%
% seD = strel('diamond',1);
% BWfinal2 = imerode(BWnobord2,seD);
% BWfinal2 = imerode(BWfinal2,seD);
% f=figure;
% imshow(BWfinal2)
s = size(I);
for i = 1:s(1)
for j = 2:s(2)
if BWfinal(i,j) == 0
I_gray(i,j) = 0;
end
end
end
f = figure;
imshow(I_gray)