I tried to calculate Distance Transform using City Block filter but failed to get required result. please help
1 回表示 (過去 30 日間)
古いコメントを表示
I am calculating Distance Transform of binary image using City Block filter,but its not working for me. There must be something wrong i am doing. Please guide me. Here is the code, i am not using the built in functions.
clc;
clear all;
close all;
M =imread('Picture1.png');
cb = [2 1 2;1 0 1;2 1 2];
% M = rand(20,20)*100<1;
[W H D] = size(M);
C = zeros(12,12);
for i=2:W
for j=2:H
C(i,j) = M(i-1,j-1);
end
end
[r c] = size(C);
for i=1:r
for j=1:c
if(C(i,j) == 1)
C(i,j) = 0+50;
else
C(i,j) = C(i,j)+50;
end
end
end
for i=2:r - 1
for j=2:c - 1
lr_tl = C(i-1,j-1) + 2;
lr_l = C(i-1,j) + 1;
lr_bl = C(i-1,j+1) + 2;
lr_c = C(i,j) + 0;
lr_tc = C(i,j-1) + 1;
A = [lr_tl lr_l lr_bl lr_c lr_tc];
C(i,j) = min(A);
end
end
for i=r-1:-1:2
for j=c - 1:-1:2
rl_tr = C(i+1,j-1) + 2;
rl_r = C(i+1,j) + 1;
rl_br = C(i+1,j+1) + 2;
rl_c = C(i,j) + 0;
rl_bc = C(i,j+1) + 1;
A = [rl_tr rl_r rl_br rl_c rl_bc];
C(i,j) = min(A);
end
end
[k t] = size(C);
for i=1:k
for j=1:t
O(i,j) = abs(C(i,j)-50);
end
end
% figure();
% imshow(M);
figure();
imshow(C);
figure();
imshow(O);
I am using the following image as input
And this output is required , which i am fail to get it. The output image should be
Please correct me where i am doing wrong process.
thanks
2 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Lighting, Transparency, and Shading についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!