Subtract pixel by pixel of two channels

Hello all, I would like to subtract one channel pixel by pixel of an other channel.
Is it possible in qupath?

Hi @TheSa, can you say why?

In general, QuPath doesn’t support modifying the image in any permanent way - but you can extract pieces of the image and do whatever you like with these, for example using ImageJ or OpenCV.

Hi,

The tissue sample showed high and inhomogenious autofluorescence resulting in inaccurate detection of positive events. Reduction of autofluorescence or enhancement of signal was not possible. I am on the level of autofluorescence of the untreated sample. I have changed several parameters in detection as well as in the assay (antibody concentration, incubation ime, temperature, washing conditions, completly different antibodies …).

Nonetheless autofluorescence and selective staining was inhomogenious and the selective signal was impossible to count.
An overlay of two channels (selective signal + autofluorescence and only autofluorescence) showed, that the signal is clearyl to differentiate. Thatswhy a subtraction of this channels would help me in automation of the analysis of selective signal.

Ah ok. This isn’t currently possible, but is something that may be supported in the future. Basically, it will remain the case that an image in QuPath can’t be changed… but an image does not need to be exactly what is stored in a file. Rather, the image can be calculated as it is being read: for example concatenating channels, applying spatial transforms, normalizing intensities and so on.

The general design supports this already in v0.2.0, but doesn’t provide an implementation that does exactly what you need.

Two questions:

  • Would a simple subtraction be enough? I can imagine there might need to be rescaling involved… and maybe smoothing?
  • What is the final output that you want from the analysis?

If you are able to show any screenshots of your images that would be helpful. There are many different ways to approach ‘detecting things’ in QuPath, supporting varying levels of complexity and customization.

1 Like

This!!

Does the variance in AF occur at a scale where you could get a useful result by subtracting the two measurements within the objects you are studying?

For example, Ch1 mean cytoplasmic intensity - Ch2 mean cytoplasmic intensity = Ch1 fixed cytoplasmic intensity

I had to do something like that for paraffin embedded samples of islets.

Another possibility is when the autofluorescent tissue is very strong in both channels, while the real signal is only strong in one channel. In that case I was able to classify my objects that were strongly positive in both channels as “Autofluorescent” and then only quantify the signal in other regions (remove the AF cell detections).

Hello Petebankhead,

First Question: A simple substraction would be enough for me. I would not need rescaling as long as negative intensities are OK for QuPath.

Second Question: It is the recognizition and characterization of elements (in location, number and size in total as well as different elements of the picture). But I think substraction would be enough, as the stained element will have a higher value than the autofluoreszent one after subtraction.

I am not allowed to post a picture in this forum right now, but perhaps I could send it to you?

Have you tested the subtraction to see how well it works in ImageJ? You can send a region to ImageJ from QuPath, do the subtraction and save your image as a TIFF. Then you can read the processed image back into QuPath.

This won’t work on a full whole slide image because of the size, but it is enough to do it in a small region to check if the process works.

If you mean not allowed by the forum trust level, it should be possible now.

Subtraction of two channels in ImageJ works pervectly fin (using SnapShot function).
Afterwards I would have to do an overlay with my nucleus staining.

I added an extreme subtraction of a more or less nice analog exmaple to visulize the enhancement of the events (before substraction, after substraction) . Normally, differences between the intensities (autofluorescence and signal) are much lower. I am not sure, if ImageJ allowed negative intensities. Of course I would do final analysis more carefully :wink:

Result of Screenshot - 105_N-Kid_CD45-2.tif (3.0 MB) before_Screenshot - 105_N-Kid_CD45-2.tif (2.2 MB)

Sending a snapshot will just be an RGB representation of the image - not actually the original pixel values (you’ll need Send region to ImageJ for that).

Since the RGB representation will also reflect the brightness/contrast settings and any lookup tables, this will implicitly do some extra work transforming the image. Subtracting the original image values is likely to give a (perhaps very) different result.

Negative intensities are fine in ImageJ if you convert the image to 32-bit.

I’m still not sure that the ability to subtract one channel from another is really necessary to solve the problem, and it would take some time and effort to do. Some further background info:

Thank you. Here is an actual example in pseudocolor.
In the signal channel you hardly see all signals (early stages of experiments) which apear in the overlay. You will notice some red elements in the overlay - which are only in the stained samples (excluding some blood spots). Unstained samples did not show this.

SignalChannel.tif (2.2 MB) Autofluorescence.tif (2.2 MB) Overlay.tif (2.2 MB)

Thanks, because these images are all RGB / pseudocolor - rather than original pixel values suitable for analysis - I’m really not sure what kind of processing steps would be helpful for any quantitative analysis. The links in my last post explain why this is so important.

Thank you. I think I am understanding the problem.
Is it possible to detect elements (starting from positive cell detection) which fullfil the following conditions.

possibility 1.: Nucleus is stained
Cells have a stronger signal in channel 1 than a threshold
Cells have a signal in channel 1 (threshold) which is stronger than a signal in channel 2 (threshold) otherwise the element is not positive.

possibility 2: Set a point/elemenat in a picture as origin and compare all other points to this one (to kind of “normalize” different channels without changing real information), where there is only autofluorescence. Every other detected element (mean/max or something) in this channel is devided by the intensity of this element at each channel. Differences would between channels would therefore be comparative and we could see, if channels are differing.

Best regards and many thanks for all your hints helping me to learn in this (for me) new field.

1 Like

Potentially yes, if I understand correctly. But regarding 1. I’d start by seeing if the detection classifier can do the job of figuring out the rules for you, e.g. see https://qupath.readthedocs.io/en/latest/docs/tutorials/cell_classification.html
That would require less work/scripting, and you can try it out by following the same process in the documentation or the youtube tutorials.

For 2., you can take existing measurements generated by QuPath for each cell and then ‘do something’ with them, including normalizing them to some other measurement you’ve got. The measurements are all stored in the ‘measurement list’ for the cell; by scripting, you can request any measurement and add a new one if you like. It doesn’t exactly match your use, but this post shows the idea: Detecting Purple chromogen - classifying cells based on green chromaticity

Often the easiest way to do something in QuPath is different from in other software. In ImageJ then you’d probably subtract the channels, but in QuPath it’s easier to keep the channels as they are, make measurements, and finally subtract (or do something else with) those measurements to get the result you need.

1 Like