필터 지우기
필터 지우기

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
Muhammad Sohail
Muhammad Sohail 2015년 11월 3일
as in Distance transform you just increase the intensities of pixels with any value as told by our teacher,but still i dont understand what would is the correct way to do that.

댓글을 달려면 로그인하십시오.

답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by