下载
首先进入官网下载Win10平台的Binaries文件,需要根据自己的系统下载32位或64位Binaries文件

配置与安装
然后解压,放置在你想要放置的目录,添加bin以及lib环境变量

然后输入
pip install openslide-python
安装完成后就可以使用了

SVS转PNG
我们以文件夹第一张图为例,由于这里我们的SVS存储的格式为RGBA四个通道,所以转成jpeg会报错(别问我怎么知道它存的RGBA,因为我存JPG报错了的φ(゜▽゜*)♪),报错如下:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
e:\anaconda3\envs\paddle\lib\site-packages\PIL\JpegImagePlugin.py in _save(im, fp, filename)
613 try:
--> 614 rawmode = RAWMODE[im.mode]
615 except KeyError as e:
KeyError: 'RGBA'
The above exception was the direct cause of the following exception:
OSError Traceback (most recent call last)
<ipython-input-12-38951423c55b> in <module>
----> 1 im.save("your_file.jpg")
e:\anaconda3\envs\paddle\lib\site-packages\PIL\Image.py in save(self, fp, format, **params)
2156
2157 try:
-> 2158 save_handler(self, fp, filename)
2159 finally:
2160 # do what we can to clean up
e:\anaconda3\envs\paddle\lib\site-packages\PIL\JpegImagePlugin.py in _save(im, fp, filename)
614 rawmode = RAWMODE[im.mode]
615 except KeyError as e:
--> 616 raise OSError("cannot write mode %s as JPEG" % im.mode) from e
617
618 info = im.encoderinfo
OSError: cannot write mode RGBA as JPEG

使用如下代码进行处理,我们可以使用matplotlib库进行显示,利用PIL库将图片存为PNG或TIFF格式都是可以滴
import openslide
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
test = openslide.open_slide('DATASET_A_DIB/SAS_21883_001.svs')
img = np.array(test.read_region((0, 0), 0, test.dimensions))
print(img.shape)
im = Image.fromarray(img)
im.save("your_file.png")
plt.imshow(img)
plt.show()

我建议最好存成TIFF格式,因为TIFF格式在医学图像更为通用,当然TIFF格式比PNG格式大得多,如下所示

PNG格式

TIFF格式

我们将两者图片放大,TIFF加载更快,但两种格式在这次的SVS数据集上并无差别
支持
由于网站位于国外,下载比较困难,我这里上传至CSDN一份,也可以评论留言获取

854

被折叠的 条评论
为什么被折叠?



