形態学的骨格からオブジェクトの画像を作成したいと考えています。MATLAB または C、C++ コードに関数はありますか? 前もって感謝します。
元の画像とその骨格 ( を使用して取得bwmorph(image,'skel',Inf)
):
形態学的骨格からオブジェクトの画像を作成したいと考えています。MATLAB または C、C++ コードに関数はありますか? 前もって感謝します。
元の画像とその骨格 ( を使用して取得bwmorph(image,'skel',Inf)
):
上記のコメントで述べたようにbwmorph(..,'skel',Inf)
、スケルトンのバイナリイメージが得られますが、それだけでは元のイメージを復元するのに十分ではありません。
一方、スケルトンピクセルごとに、距離変換によって返される値がある場合は、逆距離変換を正常に適用できます(@belisariusで提案されています)。
InverseDistanceTransformのこの実装はかなり遅いことに注意してください(私は以前の回答に基づいています)。POLY2MASKを繰り返し使用して、指定された円の内側のピクセルを取得するため、改善の余地があります。
%# get binary image
BW = ~imread('http://img546.imageshack.us/img546/3154/hand2.png');
%# SkeletonTransform[]
skel = bwmorph(BW,'skel',Inf);
DD = double(bwdist(~BW));
D = zeros(size(DD));
D(skel) = DD(skel);
%# zero-centered unit circle
t = linspace(0,2*pi,50);
ct = cos(t);
st = sin(t);
%# InverseDistanceTransform[] : union of all disks centered around each
%# pixel of the distance transform, taking pixel values as radius
[r c] = size(D);
BW2 = false(r,c);
for j=1:c
for i=1:r
if D(i,j)==0, continue; end
mask = poly2mask(D(i,j).*st + j, D(i,j).*ct + i, r, c);
BW2(mask) = true;
end
end
%# plot
figure
subplot(131), imshow(BW), title('original')
subplot(132), imshow(D,[]), title('Skeleton+DistanceTransform')
subplot(133), imshow(BW2), title('InverseDistanceTransform')
結果:
オブジェクトによっては、膨張 (Matlab ではIMDILATE )を使用して意味のある結果を得ることができる場合があります。