-
Notifications
You must be signed in to change notification settings - Fork 2
/
vitreous.m
54 lines (48 loc) · 1.01 KB
/
vitreous.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
clear;
I0 = imread('5.tif');
%Vitreous提取
[m,n] = size(I0);
I1 = medfilt2(I0,[5, 5]); %中值滤波
thresh = graythresh(I1); %大津法全局阈值调整
I2 = imbinarize(I1, thresh); %二值化
I3 = edge(I2,'canny'); %边缘提取
%边界特征提取
for j = 1:n
ymin(j) = m;
end
for i = 1:m
for j = 1:n
if(I3(i, j) == 1)
if(i < ymin(j))
ymin(j) = i;
elseif(i < ymin(j) + 10 && j ~= 2)
if(I3(i, j+1) == 1 && I3(i, j-1) == 1)
I3(i,j) = 0;
end
else
I3(i,j)=0;
end
end
end
end
k = 1;
for i = 1:m
for j = 1:n
if(I3(i,j) == 1)
if(i == ymin(j))
yV(k) = i;
xV(k) = j;
k = k + 1;
end
end
end
end
imshow(I0);
hold on;
%绘制边界
pV = polyfit(xV, yV, 10);
y1V = polyval(pV, xV);
xxV = linspace(1, n, 300);
yyV = spline(xV, y1V, xxV);
plot(xxV, yyV, '-', 'LineWidth', 1, 'color', 'b');
legend('Vitreous');