Separate_stains output of one channel and conversion to grayscale

I am using color deconvolution to identify the red pixels in a histology image, but the output values from separate_stains appear to be in a format of both positive and negative values rather than a grayscale 0-255 value scale. What is the format of the output and how can I transform it to the common value scales of a grayscale image? I currently have to save the image to file and then load it in order to get this red channel in the format I want, which is very not ideal.


Hi @asmagen, I don’t know much about stain deconvolution but using this example from the docstring

>>> from skimage import data
>>> from skimage.color import separate_stains, hdx_from_rgb
>>> ihc = data.immunohistochemistry()
>>> ihc_hdx = separate_stains(ihc, hdx_from_rgb)

ihc_hdx is a float image. I’m guessing that it has values between -1 and 1. If you need to have an image of unsigned 0-255 integers you can do

from skimage import img_as_ubyte
ihc_ubyte = img_as_ubyte(0.5 * (ihc_hdx + 1))

and then save this image using for example.

Thank you, but I was advised to get rid of the negative values which in conventional stain unmixing/deconvolution correspond to noise in the fitting. The output format you describe, and the transformation applied on it, render it impossible to take care of this noise.

Can you advise on how to get an unmoving that allows finding the normal value range estimates?