Booritas / slideio

BSD 3-Clause "New" or "Revised" License
49 stars 2 forks source link

Question: How to set the magnification of an image. #26

Closed dgkoenigsberg closed 7 months ago

dgkoenigsberg commented 7 months ago

I have images that are 40x and images that are 20x zoom. I want to open them both at 20x zoom. How can I open the 40x images at 20x zoom? Is there any supported way other than opening the image and calling read_block with a manual size of width/2 and height/2? Is calling read block with a halved resolution the same as reading the image at a different magnification?

Thank you for your help!

Booritas commented 7 months ago

Yes, it is correct. To get 20x from 40x image, you need to divide block sizes by 2. Unfortunately, there is no direct way to specify desired magnification. Do you think, it would be helpful to introduce the possibility to specify magnificatoin instead of the size?

dgkoenigsberg commented 7 months ago

The reason I asked is because I know with open slide there are "levels" at different magnifications. However, I realized that the levels do not correspond to every magnification anyway (i'm not sure if this is a scanner issue, a code issue, or an SVS issue).

For instance my 40x images have magnifications of 40x, 10x, etc. I was hoping to avoid a simple resizing function because I was worried that resizing an image is potentially meaningfully different from viewing it at a different magnification (a difference that I'm sure would be minor). I did not want to introduce bias into my dataset for deep learning to bias towards.

I've been having a memory issue with openslide where slideio is able to easily read these large files into memory but openslide is not (and slideio is about 50% faster too). For that reason I wanted to use slideio where possible, so I'm replacing openslide with slideio in my code and resizing as above.

To answer your question: I don't think a magnification feature is necessary (maybe a level feature, but only if there is a functional difference between resizing and reading at a different level - I'm afraid I wouldn't know).

Does that make sense?

Booritas commented 7 months ago

Yes, it makes sense. SlideIO also uses "levels," although it conceals their usage. When read_block is invoked with the 'size' parameter, the library searches for the most appropriate level for resizing. If your image has levels such as 40x, 10x, and 5x, and you call read_block with a downscaling factor of 2 (resulting in a magnification of 20x), the library will use the 40x level for resizing. If your image contains a 20x level, this level will be directly read without resizing. In cases where the requested magnification falls between two levels, the library will select the larger of the two and use it for downsampling to achieve the requested magnification.

I'm glad that you find the library useful. Do not hesitate to contact me should you have any questions or a feature request. I would appreciate if you add a star to the repository.

dgkoenigsberg commented 7 months ago

Done! That's what I figured you were doing.

I will say it would be nice to be able to get the dimensions of the various levels so that if I want to display at a specific level I can set the size to those dimensions. That would be my only feature request.

Thank you for everything you have done to make this and support it!