Segmenting images with different colours

Hi, I’m super new to ImageJ/Fiji and image analysis in general. Only got into it a week or so ago. I’ve trying to measure the areas that each coloured line encloses in the following image:

These are traces of wounds on a patient made by hand and scanned in. The different colours represent different points in time. I've been trying to follow the segmentation tutorial on the *ImageJ* site.

Measuring the area manually seems pretty easy after some preprocessing. I’m able to do this in a few ways - repeatedly Color Thresholding and fiddling around with the sliders there, using the versatile wand tool, or just using the selection tools. However, since I have quite a few of these images I’d ideally like to have a method to do this automatically.

I’ve been trying in vain over the last week or so to come up with a way to do this. To my inexperienced eye, this seems like it ought to be quite easy as it is a simple image, especially compared to some of the stuff I’ve seen here.

I’d appreciate any pointers in the right direction.

If you only have 3 colors you can use Color Deconvolution.

This will give you perfect results … but only with 3 colors.

Unfortunately not. I have a maximum of 5 colors (5 time points). Many of my images have 3 or less colors so I suspect colour deconvolution would be useful.

Do you know if there is a way to iteratively use colour deconvolution? Like a scenario where I can split up the 5 colors into images with 1 | 1 | 3 colours and then split the 3 color image into the individual colours?

Anyway this seems like a good starting point for further investigation. Thank you very much @phaub

No, color deconvolution can not be applied iteratively.

3 channels (RGB) can be unmixed into 3 stains.

If you have more stains you need more color channels.
This could be achieved e.g. by capturing multiple images of the sceen with different illuminations.

I played a bit with your image and had an idea how to separate the 4 colors.
I got distinct contours for each marker color.
See the colored contour lines overlayed in your original image.

Currently not all contours are closed. But this can be solved.

Whether it make sense to proceed depends on your answers to the following questions:
Are you using always the same colors / the same marker pens?
What is the 5th color?
How strong can the marks overlap?

Wow, first of all thank you very much for taking the time to help me out.

Yeah, all images use the same colours.

It is black but this does not really matter. I have only have 3 images with 5 colours while there are about ~100 of 4 colour ones. If you have a way of doing this for 4 colours that itself would be sufficient.

More or less like this one. Typically wounds heal over time :slight_smile: so a lot of the images have the marks completely inside one another with no overlap.

Hey Shrinath,
here is my solution …

My approach is a kind of marker class assignment based on absorbance values.
So, in the first step the RGB values are converted to absorbance values.

Based on the absorbance values of your color image I have estimated absorbance (stain) vectors for each of the 4 marker colors. The vectors are selected to maximize the angle between each other.
Here is a visualization of the absorbance distribution and the estimated stain vectors.


Based on this stain vectors I calculated the angle between each pixel absorbance in the image and each stain vector. This angle can be thought as a probability for each pixel belonging to each of the 4 marker stains.
The result is a 4 channel image with the angle measurements for each stain class.

These channels typically show 4 maxima in their histogram. The threshold between the first and second maximum separates the relevant stain.


The threshold between the first and second maximum are found for each channel by means of a custom Plugin.

The result of this thresholding is a fragmented contour line for each of the markers.

This fragmented contours are finally closed based on Watershed.

This solution depends on your marker stains. Your current marker colors are ideally distributed.
If you change your marker colors the stain vectors have to be adapted.
I hope that your marking and imaging is consistent and that my approach will give you a meaningful result and support - not only in your test image.

As I already explained on private channel,
Save the following 3 java files included in the zip file into the \plugins directory in ImageJ. (2.6 KB)

Use the function <Plugins/Install…> to install this plugins in ImageJ and make them available for usage in the macro code.
Then open the following macro code in ImageJ in a macro script window (just Drag&Drop the file onto the IJ GUI).

CreateContourLines_4Markers_07.02.2020.ijm (2.2 KB)

Study the lines of the macro.

How to use on a single image:

  • Close all images.
  • Open one of your images (start with the test image you have originally posted because my development is based on this image even it is jpeg).
  • Run the macro.
  • See what happens.

The next steps would be to include the measurement into the macro and to apply the macro to a list of images / to all images in a folder.


Try some k-means clustering. It’s pretty much a textbook application.

You can use colorseg

Or pain old k-means

1 Like