relabeling pixels based on distance between object's centerline and boundary

怎甘沉沦 提交于 2019-12-08 02:53:56

问题


I've a binary image containing an object as illustrated in the figure below. The centerline of the object is depicted in red. For each pixel belonging to the object, I would like to relabel it with a color. For instance, pixels whose orthogonal distance to the centerline are half of the distance to the object boundary from the centerline, should be labeled blue, otherwise green. An illustration is given below. Any ideas? Also, how could I fit a 1D gaussian centered in the object centerline and orthogonal to it?

The image in full resolution can be found under: http://imgur.com/AUK9Hs9


回答1:


Here is what comes to mind (providing you have the Image Processing Toolbox):

Create two binary images, one BWin with 1 (true) pixels at the location of your red line, and one BWout that is the opposite of your white region (1 outisde the region and 0 (false) inside).

Like this:

BWin:

BWout:

Then apply the euclidean transform to both using bwdist:

Din = bwdist(BWin);
Dout = bwdist(BWout);

You now have two images with pixel intensities that represent the euclidean distance to the closest non-0 pixel.

Now subtract both, the values of the difference will be positive on one side of the equidistance and negative on the other side:

blueMask=Din-Dout>0;
greenMask=~BWout & blueMask;

You can then populate the RGB layer using the masks:

Result=zeros(size(II));
Result(:,:,1)=BWin;
Result(:,:,2)=greenMask;
Result(:,:,3)=~blueMask & ~BWin;
imshow(Result);



来源:https://stackoverflow.com/questions/22116123/relabeling-pixels-based-on-distance-between-objects-centerline-and-boundary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!