Skip to content
Advertisement

Python open jp2 medical images – Scipy, glymur

I am trying to read and tile a jp2 image file. The image is RGB 98176 x 80656 pixels (it is medical image data).

When trying to read the image with glymur I get this error:

JavaScript

I understand the image is too big. What I need is to read the image data by tiles and save them elsewhere and in another format.

Glymur allows me to read the header using python, so for instance, the code stream is:

JavaScript

Tiling doesnt work, the read method doesn’t work.

Edit:

I tried also Scipy which is able to read the header but the same thing, errors that arise are:

JavaScript

Is there any way to stream the image data into a different type of container so that the number of indices is not an issue and enables me to process it?

Advertisement

Answer

The standard thing for reading huge medical images is openslide, I’d try that first. I’m not sure it will read jp2 directly, but assuming this is from a slide scanner, perhaps you could save in one of the formats that openslide supports?

ImageMagick will load sections of large jp2 images via OpenJPEG, though it’s not especially quick. I have a 10k x 10k jp2 image here, for example, and if I convert to JPG I see:

JavaScript

If I try to crop out a small piece, it’s hardly any quicker, suggesting that IM always decodes the entire image:

JavaScript

But if I do the crop during load, it does speed up:

JavaScript

Not great, but it might work if you’re patient.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement