DigitalSlideArchive / HistomicsTK

A Python toolkit for pathology image analysis algorithms.
https://digitalslidearchive.github.io/HistomicsTK/
Apache License 2.0
394 stars 117 forks source link

Single band nuclei detection should use consistent scaling across image #1002

Closed manthey closed 9 months ago

manthey commented 1 year ago

One of the reasons we want to calculate a whole-image scaling parameter is to avoid processing differences on different tiles.

manthey commented 1 year ago

I think if src mu and sigma are None just before we call detect_nuclei_with_dask, we could fetch the entire region we are working on at low res (e.g., ts.getRegion(**it_kwargs, output=dict(maxWidth=2048, maxHeight=2048)), make sure it is in the format expected (e.g., make it three channel and cast it if necessary like we did in segment_wsi_foreground_at_low_res), then compute mu, sigma = color_conversion.lab_mean_std(image_pixels).

subinkitware commented 1 year ago

If we go inside the detect_nuclei_with_dask -->detect_tile_nuclei there is already a checkpoint that stacks a single-channel image to RGB. I have added casting to that code. Now the input for Reinhard normalization will be of the desired dtype and in 3 channel format.

manthey commented 1 year ago

If we go inside the detect_nuclei_with_dask -->detect_tile_nuclei there is already a checkpoint that stacks a single-channel image to RGB. I have added casting to that code. Now the input for Reinhard normalization will be of the desired dtype and in 3 channel format.

I don't think we have to do this cast unless the code is going to use skimage.rgb2lab; I think the other code handles the floating point values that aren't scaled [0,1], so the cast just uses more time and memory.

subinkitware commented 1 year ago

After the casting process, the input goes into htk_cnorm.reinhard that has an inbuild rgb_to_lab coming from the preprocessing module. Inside that function, there is a dot product between the log of the image and the array. I believe that the casting could be helpful there.

manthey commented 1 year ago

@subinkitware When we run this on an image where we fail to compute mu and sigma, you can see that the tiles get inconsistent normalization. When I am on master and run this on tcgaextract_rgb.tiff, I can see denser nuclei on the left. I haven't checked if #1005 has any affect.

subinkitware commented 1 year ago

@subinkitware When we run this on an image where we fail to compute mu and sigma, you can see that the tiles get inconsistent normalization. When I am on master and run this on tcgaextract_rgb.tiff, I can see denser nuclei on the left. I haven't checked if #1005 has any affect.

Let me investigate this issue. I believe the #1005 has some effect since it is casting the images from float to uint16