Python打开jp2医学图像-Scipy,glymur [英] Python open jp2 medical images - Scipy, glymur

查看:747
本文介绍了Python打开jp2医学图像-Scipy,glymur的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试读取和平铺jp2图像文件.图像为RGB 98176 x 80656像素(它是医学图像数据).

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

当尝试使用glymur读取图像时,出现此错误:

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

glymur.lib.openjp2.OpenJPEGLibraryError: OpenJPEG library error:  Prevent buffer overflow (x1: 80656, y1: 98176)

我了解图片太大.我需要的是按图块读取图像数据并将其保存在其他位置并以另一种格式保存.

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允许我使用python读取标头,例如,代码流为:

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

>>> print(codestream.segment[1])
SIZ marker segment @ (87, 47)
    Profile:  no profile
    Reference Grid Height, Width:  (98176 x 80656)
    Vertical, Horizontal Reference Grid Offset:  (0 x 0)
    Reference Tile Height, Width:  (832 x 1136)
    Vertical, Horizontal Reference Tile Offset:  (0 x 0)
    Bitdepth:  (8, 8, 8)
    Signed:  (False, False, False)
    Vertical, Horizontal Subsampling:  ((1, 1), (1, 1), (1, 1))

平铺不起作用,read方法不起作用.

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

我也尝试了Scipy,它能够读取标头,但同一件事,出现的错误是:

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

>>> import scipy.misc
>>> image=scipy.misc.imread('Sl0.jp2')
/home/user/anaconda2/lib/python2.7/site-packages/PIL/Image.py:2274: DecompressionBombWarning: Image size (7717166080 pixels) exceeds limit of 89478485 pixels, could be decompression bomb DOS attack.
  DecompressionBombWarning)
>>> scipy.misc.imwrite('/home/user/Documents/imageCfromjp2.tif',image)
/home/user/
AttributeError: 'module' object has no attribute 'imwrite'
>>> scipy.misc.imsave('/home/user/Documents/imageCfromjp2.tif',image)
/home/user/
  File "/home/user/anaconda2/lib/python2.7/site-packages/scipy/misc/pilutil.py", line 195, in imsave
    im = toimage(arr, channel_axis=2)
  File "/home/user/anaconda2/lib/python2.7/site-packages/scipy/misc/pilutil.py", line 287, in toimage
    raise ValueError("'arr' does not have a suitable array shape for "
ValueError: 'arr' does not have a suitable array shape for any mode.
>>> image2=image[0:500,0:500]
/home/user/
IndexError: too many indices for array
>>> image2=image[0:500]
/home/user/
ValueError: cannot slice a 0-d array

有什么方法可以将图像数据流式传输到另一种类型的容器中,从而索引的数量不是问题,而是可以处理的吗?

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?

推荐答案

读取巨大的医学图像的标准方法是 openslide ,我会先尝试一下.我不确定它会直接读取jp2,但是假设这是从幻灯片扫描仪读取的,也许您可​​以保存openlide支持的一种格式?

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将通过OpenJPEG加载大的jp2图像的部分,尽管它不是特别快.例如,我在这里有一个10k x 10k jp2图像,如果转换为JPG,我会看到:

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:

$ time convert sekscir25.jp2 x.jpg
real    0m25.378s
user    0m24.832s
sys 0m0.544s

如果我尝试裁剪一小块,几乎不会更快,这表明IM总是对整个图像进行解码:

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

$ time convert sekscir25.jp2 -crop 100x100+0+0 x.png
real    0m19.887s
user    0m19.380s
sys 0m0.504s

但是,如果我在加载过程中进行裁剪,它的确会加快速度:

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

$ time convert sekscir25.jp2[100x100+0+0] x.png
real    0m7.026s
user    0m6.748s
sys 0m0.276s

不太好,但是如果您有耐心的话,它可能会起作用.

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

这篇关于Python打开jp2医学图像-Scipy,glymur的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆