use*_*127 2 c c++ matlab image-processing morphological-analysis
我想从它的形态骨架中创建一个物体的图像.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')
Run Code Online (Sandbox Code Playgroud)
结果: