2

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: https://i.stack.imgur.com/DqNkC.jpg

chappjc
  • 30,359
  • 6
  • 75
  • 132
Tin
  • 1,006
  • 1
  • 15
  • 27
  • First of all, is your centerline defined for you, how are you creating that centerline? You have some areas of it that are vertical, which seems odd. You also show 2 different lines moving away from the centerline. They are at differing angles from horizontal, so my next question is, when you want coloring, are you looking for perpendicular to the centerline, regardless of the angle for which it touches the edge of the blob? – trumpetlicks Mar 01 '14 at 19:34
  • The perpendicular lines are merely for demonstrating how the colors are to be distributed, I think. – Jonas Mar 01 '14 at 19:50
  • @trumpetlicks, the 2 different lines moving from the `centerline` are just for illustration purposes ;-) They show, as @Jonas, mentioned, for the pixels on the lines, how they should be colored after the `relabeling`. Concerning the perpendicular distance, I think, it might be better from the edge of the blob towards the `centerline`, but if you could illustrate also the other way round (`the way you mentioned`), it would be really helpful :-) – Tin Mar 01 '14 at 20:34

1 Answers1

3

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: BWin

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

Result

Cape Code
  • 3,584
  • 3
  • 24
  • 45
  • thank you. But to make the things clear, the 2 `colored` lines from my original image, are for illustration purposes only (they don't actually belong to the object). They were only used to show how the pixels on those lines, should be `relabeled`. – Tin Mar 01 '14 at 21:11
  • Thanks for the code @Jigg! I was wondering, can we make the solution more general? For instance, if we need to divide the pixels into `3` regions, instead of 2, based again on their distances, e.g. pixels between the first 1/3 of the distance one colour, then the ones in the second third another color, and the ones in the last third another color. – Tin Mar 01 '14 at 21:44