DIAGNijmegen / pathology-whole-slide-data

A package for working with whole-slide data including a fast batch iterator that can be used to train deep learning models.
https://diagnijmegen.github.io/pathology-whole-slide-data/
Apache License 2.0
86 stars 24 forks source link

Add class for indexed masks #36

Closed daangeijs closed 1 year ago

daangeijs commented 1 year ago

Added: Added new class WholeSlideIndexedMaskWriter which extends the existing WholeSlideImageWriterBase class. This new class writes indexed binary masks for whole slide images.

To support indexed masks, the _set_indexed_channels() method has been added to determine the number of channels based on the dimensions of the binary mask. If the dimensions are 2D, then a single channel is used, while for 3D dimensions, the number of channels equals the number of dimensions.

The write() method is modified to set the color type as indexed and the number of indexed colors to the channels determined earlier by the _set_monochrome_channels() method. The method also sets other necessary parameters for writing the indexed mask such as the tile size, compression, and interpolation.

A print statement is added to display the number of indexed channels in the mask along with other details.

Note: To make the functionality more clear between the monochrome and indexed writer this could be a rename, I would even drop the name WholeSlide maybe. :

WholeSlideMonochromeMaskWriter: This name emphasizes that the class is responsible for writing monochrome (single-channel) masks for whole slide images.

WholeSlideIndexedColorMaskWriter: This name emphasizes that the class is responsible for writing indexed-color masks (which can have multiple channels) for whole slide images.

martvanrijthoven commented 1 year ago

Dear Daan,

Thank you for this pull request! It looks great. I will merge it. I agree with the renaming and will make a depreciation warning about using WholeSlideMaskWriter instead of WholeSlideMonochromeMaskWriter or WholeSlideIndexedColorMaskWriter. The "WholeSlide" naming is used in the whole package, it is indeed a bit verbose and I see your point. However, for lets keep it for now and we can discuss to change it in the whole package,

Thanks again for this contribution.

daangeijs commented 7 months ago

I kind see this code anymore in the main? Did this dissapear?

martvanrijthoven commented 7 months ago

Hi @daangeijs , Sorry about this, not sure what happened, I just committed it back in