Info

此问题已关闭。 请重新打开它进行编辑或回答。

What is this filtering algorithm called?

1 次查看(过去 30 天)
John Snow
John Snow 2014-1-7
关闭: MATLAB Answer Bot 2021-8-20
Hello, can somebody explain to me how the following code works or tell me the name of the method used to filter the left binary image to the right one?
Image:
Code:
[rows, cols] = size(e);
L1 = 20;
L2 = 80;
seed = [];
for alpha = 40:120
dx = cos( alpha * pi / 180);
dy = sin( alpha * pi / 180);
for d = L1:L2
r = round(cy - d * dy );
c = round(cx + d * dx );
found = 0;
for i = -2:2
for j=-2:2
ri = r + i;
cj = c + j;
if( ri < 1 || ri > rows || cj < 1 || cj > cols || found )
continue;
end;
if( e(ri, cj) )
found = 1;
seed = [ seed, sub2ind( [rows, cols], ri, cj ) ];
end;
end;
end;
if( found>0 )
break;
end;
end;
end;
newe = ones( rows, cols ) > 2;
for k=1:length(seed)
[r,c] = ind2sub( [rows, cols], seed(k) );
if( e(r,c) )
e(r,c) = 0;
q = seed(k);
newe(r,c) = 1;
while( ~isempty(q) )
id = q(1); q = q(2:end);
[r,c] = ind2sub( [rows, cols],id);
for i=-1:1
for j=-1:1
ri = r+i;
cj = c+j;
if( ri < 1 || ri > rows || cj < 1 || cj > cols )
continue;
end;
if( e(ri, cj) )
e(ri, cj) = 0;
newe( ri, cj ) = 1;
q = [q, sub2ind( [rows, cols], ri, cj ) ];
end;
end;
end;
end;
end;
end;
newe = bwmorph( newe, 'dilate', 2 );
newe = bwmorph( newe, 'thin', inf );

回答(0 个)

此问题已关闭。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by