pyvips icon indicating copy to clipboard operation
pyvips copied to clipboard

How to read mrxs format image and choose certain dimension level. Then cut them into desire tiles?

Open HanYanxi opened this issue 2 years ago • 7 comments

import pyvips svs_file = 'file.mrxs'

img = pyvips.Image.new_from_file(svs_file, level=0)

img2 = img.crop(x1, y1, h, w) img2 = np.asarray(img2, dtype=np.uint8)

I got an attribute error from "level=0"

HanYanxi avatar Oct 05 '23 18:10 HanYanxi

Hello @HanYanxi ,

I would guess your libvips has been built without openslide support. You should see:

$ vipsheader Mirax2.2-1.mrxs
Mirax2.2-1.mrxs: 101832x219976 uchar, 4 bands, srgb, openslideload

ie. vips has detected an openslide format.

jcupitt avatar Oct 05 '23 22:10 jcupitt

Hello @jcupitt, Thank you for your reply. I checked it. I don't have openslide support. This is what I get. May I ask how can I get the openslide support? image

HanYanxi avatar Oct 05 '23 22:10 HanYanxi

On Windows you need the all binary:

https://github.com/libvips/build-win64-mxe/releases/download/v8.14.5/vips-dev-w64-all-8.14.5.zip

jcupitt avatar Oct 06 '23 00:10 jcupitt

Thank you. It works. But how can I check how many dimension levels the mrxs image has? And how can I know the shape of each level? I cannot find the document for it.

HanYanxi avatar Oct 06 '23 14:10 HanYanxi

It's in the image properties. Try:

$ vipsheader -a Mirax2.2-1.mrxs 
Mirax2.2-1.mrxs: 101832x219976 uchar, 4 bands, srgb, openslideload
width: 101832
height: 219976
bands: 4
format: uchar
coding: none
interpretation: srgb
xoffset: 0
yoffset: 0
xres: 4275.77
yres: 4267.47
filename: Mirax2.2-1.mrxs
...
openslide.level-count: 10
openslide.level[0].downsample: 1
openslide.level[0].height: 219976
openslide.level[0].width: 101832
openslide.level[1].downsample: 2
openslide.level[1].height: 109988
openslide.level[1].width: 50916
openslide.level[2].downsample: 4
openslide.level[2].height: 54994
openslide.level[2].width: 25458
...

So from Python (for example) you can use:

n_levels = image.get("openslide.level-count")

jcupitt avatar Oct 06 '23 15:10 jcupitt

Thank you! I used "n_levels = image.get("openslide.level-count")" in Python only got a number, like 10. Is that right?

HanYanxi avatar Oct 09 '23 16:10 HanYanxi

It could be, mrxs files have a lot of levels.

jcupitt avatar Oct 09 '23 16:10 jcupitt