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.
color_contour_07.02.2020.zip (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.