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:


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:



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:

greenMask=~BWout & blueMask;

You can then populate the RGB layer using the masks:

Result(:,:,3)=~blueMask & ~BWin;

Need Your Help

Does resizing jpeg images affect their compression?

c# .net image compression resize

I'm resizing jpegs by using the Graphics.DrawImage method (see code fragment below). Can anyone confirm that this will not affect the compression of the new image?