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

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

## Answers

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