Zlo*_*niy 10 python image-processing scipy jpeg2000
我正在尝试阅读并平铺jp2图像文件.图像是RGB 98176 x 80656像素(它是医学图像数据).
当试图用glymur读取图像时,我收到此错误:
glymur.lib.openjp2.OpenJPEGLibraryError: OpenJPEG library error: Prevent buffer overflow (x1: 80656, y1: 98176)
Run Code Online (Sandbox Code Playgroud)
我明白图像太大了.我需要的是通过图块读取图像数据并将其保存在其他地方并以其他格式保存.
Glymur允许我使用python读取头,例如,代码流是:
>>> 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))
Run Code Online (Sandbox Code Playgroud)
平铺不起作用,read方法不起作用.
编辑:
我也试过Scipy能够读取标题,但同样的事情,出现的错误是:
>>> 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
Run Code Online (Sandbox Code Playgroud)
有没有办法将图像数据流式传输到不同类型的容器中,以便索引的数量不是问题,并使我能够处理它?
我使用幻灯片扫描仪中的文件时遇到了同样的问题.我发现有用的是使用vips和openslide使用以下命令平铺图像:
vips dzsave image.mrxs targetdirectoryname --depth one --tile-size 2048 --overlap 0
Run Code Online (Sandbox Code Playgroud)
这将输出源图像的级别0(全分辨率)的图块,其中您选择的图块大小和0的像素重叠到tartget目录.
希望这有任何帮助.马里奥
阅读大型医学图像的标准方法是openslide,我会先尝试一下。我不确定它会直接读取 jp2,但假设这是来自幻灯片扫描仪,也许您可以保存为 openslide 支持的格式之一?
ImageMagick 将通过 OpenJPEG 加载大型 jp2 图像的部分,尽管速度不是特别快。例如,我这里有一个 10k x 10k jp2 图像,如果我转换为 JPG,我会看到:
$ time convert sekscir25.jp2 x.jpg
real 0m25.378s
user 0m24.832s
sys 0m0.544s
Run Code Online (Sandbox Code Playgroud)
如果我尝试裁剪掉一小部分,速度也不会更快,这表明 IM 总是解码整个图像:
$ time convert sekscir25.jp2 -crop 100x100+0+0 x.png
real 0m19.887s
user 0m19.380s
sys 0m0.504s
Run Code Online (Sandbox Code Playgroud)
但如果我在加载期间进行裁剪,它确实会加速:
$ time convert sekscir25.jp2[100x100+0+0] x.png
real 0m7.026s
user 0m6.748s
sys 0m0.276s
Run Code Online (Sandbox Code Playgroud)
不太好,但如果你有耐心,它可能会起作用。