Pathology image color separation scaling artifacts

Please see the following discussion showing an issue with the scale of values in the output of separate_stains, where I get really high values corresponding to potential artifacts or just high density staining, rendering the other positive values (which are the ones I am interested in capturing) too low.

I used the following strategy but I am not sure if it’s reasonable and would scale well to other images, because I don’t want to determine thresholds per image separately and manually.

Here is the potential culprit rendering the high values. I don’t know if and how to remove these artifacts from the image, or otherwise, should I just set a lower upper threshold on the hema values?

And this is what it looks like in the original image for reference:


I’ll reply here rather than annoying everyone on the pull request.

You mentioned multiplying by 2.5 and clipping the values, meaning setting the values above an arbitrary threshold I choose to that threshold if I understand correctly, as I did above. You didn’t mention scaling like I did. It’s not clear to me how does the 2.5 or 5 multiplication would help rather than scaling instead.

Multiplying is scaling. rescale_intensity applies a multiplication and an addition. That is, it scales and it moves the zero point. Simply multiplying is cheaper and also safer, you don’t want to move the zero point.

Instead of your hema[hema<0]=0 etc. I would do this:

scale = 5  # or whatever you think is a good value. 5 corresponds to
           # your 0.2. You could try 6 or 8 or whatever if your image
           # is still too dark
hema = np.clip(hema * scale, a_min=0, a_max=1)

One thing that is important: use the same scale on all images, if you want to be able to compare staining across those images. Only use a per-image setting if the relative amount of stain is not important to you.

I see, thanks.
So how do you handle cases where the actual staining procedure and quantities of materials used may have created incomparable images? If it’s all relative then any artifact saturated with the antibody or any specific tissue that was subjected to more substance or time before scanning could have created a situation where after the transformation above I would call only half of the true positive as positive.