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

旧街凉风 提交于 2019-12-06 11:51:23

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);

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