使用openslide-python对whole slide image(WSI)进行读取、显示和金字塔构建、生成tiles

本文主要是介绍使用openslide-python对whole slide image(WSI)进行读取、显示和金字塔构建、生成tiles,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

H&E染色的病理切片怎么读取

特点是:太大,每张600Mb~10Gb,一般软件打不开。
基于python开发,暂时想到3种打开方式:


#coding:utf-8
import openslide
import matplotlib.pyplot as plt
#image file
img_path = 'path/to/img/1.tif'#method 1
slide1 = openslide.OpenSlide(img_path)
#method 2
slide2 = openslide.open_slide(img_path)
#method 3
slide3 = openslide.ImageSlide(img_path)#size of the image
print(slide.level_dimensions[0])

输出:

(68046, 80933)

这张图的像素是(68046, 80933),用OpenSlideopen_slide打开没问题,但是用ImageSlide就内存溢出了。
打开之后,就可以看看openslide能够解析的图像信息了,以及实现图像切分等操作,具体可参见官网:https://openslide.org/api/python/
下面是部分我认为可能需要用到的操作(python3.6):

from openslide.deepzoom import DeepZoomGenerator#图像扫描仪制造商
print(slide.detect_format(img_path))#幻灯片的各种属性
print(slide.properties)#下采样因子
downsamples = slide.level_downsamples#图像大小(宽,高)
[w, h] = slide.level_dimensions[0]
print(w,h)#得到原图的缩略图(206X400)
simg = slide.get_thumbnail((206,400))
#显示缩略图
plt.imshow(simg)
plt.show()#实现DeepZoomGenerator的功能
data_gen = DeepZoomGenerator(slide2, tile_size=1023, overlap=1, limit_bounds=False)#The number of Deep Zoom levels in the image
print(data_gen.level_count)#The total number of Deep Zoom tiles in the image
print(data_gen.tile_count)#A list of (tiles_x, tiles_y) tuples for each Deep Zoom level. level_tiles[k] are the tile counts of level k
print(data_gen.level_tiles)#A list of (pixels_x, pixels_y) tuples for each Deep Zoom level. level_dimensions[k] are the dimensions of level k
print(data_gen.level_dimensions)#Return a string containing the XML metadata for the Deep Zoom .dzi file
#Parameters:format (str)  the delivery format of the individual tiles (png or jpeg)
print(data_gen.get_dzi('png'))

输出是:

18
7199
((1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (2, 2), (3, 3), (5, 5), (9, 10), (17, 20), (34, 40), (67, 80))
((1, 1), (2, 2), (3, 3), (5, 5), (9, 10), (17, 20), (34, 40), (67, 80), (133, 159), (266, 317), (532, 633), (1064, 1265), (2127, 2530), (4253, 5059), (8506, 10117), (17012, 20234), (34023, 40467), (68046, 80933))
<Image Format="png" Overlap="1" TileSize="1022" xmlns="http://schemas.microsoft.com/deepzoom/2008"><Size Height="80933" Width="68046" /></Image>

显示tiles:

#Return an RGB Image for a tile.
#level (int):the Deep Zoom level
#address (tuple):  the address of the tile within the level as a (column, row) tupletile_img1 = data_gen.get_tile(11,(0,0))
tile_img2 = data_gen.get_tile(11,(0,1))
plt.imshow(tile_img1)
plt.show()
plt.imshow(tile_img2)
plt.show()

tile_img1
tile_img2

其实这张图来自level11,它的大小是(1064,1265),切分大小是1024,所以该图片被切分成了4个子图,而我们显示的是第一行第一列和第二行第一列的两张子图。

注意:tile_size的设置原则是:tile_size + overlap = 2^n

此处,1023+1=1024(2^10)

# Return the OpenSlide.read_region() arguments corresponding to the specified tile.
# Most applications should use get_tile() instead.
# level (int)  the Deep Zoom level
# address (tuple)  the address of the tile within the level as a (column, row) tuple
read_region = data_gen.get_tile_coordinates(11, (0,0))
print(read_region)#Return a (pixels_x, pixels_y) tuple for the specified tile.
print(data_gen.get_tile_dimensions(12, (0,0)))

输出:

((0, 0), 2, (4092, 4092))
(1024, 1024)
Authors
Merry Young

这篇关于使用openslide-python对whole slide image(WSI)进行读取、显示和金字塔构建、生成tiles的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/560221

相关文章

Java使用Curator进行ZooKeeper操作的详细教程

《Java使用Curator进行ZooKeeper操作的详细教程》ApacheCurator是一个基于ZooKeeper的Java客户端库,它极大地简化了使用ZooKeeper的开发工作,在分布式系统... 目录1、简述2、核心功能2.1 CuratorFramework2.2 Recipes3、示例实践3

springboot security使用jwt认证方式

《springbootsecurity使用jwt认证方式》:本文主要介绍springbootsecurity使用jwt认证方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录前言代码示例依赖定义mapper定义用户信息的实体beansecurity相关的类提供登录接口测试提供一

go中空接口的具体使用

《go中空接口的具体使用》空接口是一种特殊的接口类型,它不包含任何方法,本文主要介绍了go中空接口的具体使用,具有一定的参考价值,感兴趣的可以了解一下... 目录接口-空接口1. 什么是空接口?2. 如何使用空接口?第一,第二,第三,3. 空接口几个要注意的坑坑1:坑2:坑3:接口-空接口1. 什么是空接

springboot security快速使用示例详解

《springbootsecurity快速使用示例详解》:本文主要介绍springbootsecurity快速使用示例,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝... 目录创www.chinasem.cn建spring boot项目生成脚手架配置依赖接口示例代码项目结构启用s

Python如何使用__slots__实现节省内存和性能优化

《Python如何使用__slots__实现节省内存和性能优化》你有想过,一个小小的__slots__能让你的Python类内存消耗直接减半吗,没错,今天咱们要聊的就是这个让人眼前一亮的技巧,感兴趣的... 目录背景:内存吃得满满的类__slots__:你的内存管理小助手举个大概的例子:看看效果如何?1.

Python+PyQt5实现多屏幕协同播放功能

《Python+PyQt5实现多屏幕协同播放功能》在现代会议展示、数字广告、展览展示等场景中,多屏幕协同播放已成为刚需,下面我们就来看看如何利用Python和PyQt5开发一套功能强大的跨屏播控系统吧... 目录一、项目概述:突破传统播放限制二、核心技术解析2.1 多屏管理机制2.2 播放引擎设计2.3 专

Python中随机休眠技术原理与应用详解

《Python中随机休眠技术原理与应用详解》在编程中,让程序暂停执行特定时间是常见需求,当需要引入不确定性时,随机休眠就成为关键技巧,下面我们就来看看Python中随机休眠技术的具体实现与应用吧... 目录引言一、实现原理与基础方法1.1 核心函数解析1.2 基础实现模板1.3 整数版实现二、典型应用场景2

Python实现无痛修改第三方库源码的方法详解

《Python实现无痛修改第三方库源码的方法详解》很多时候,我们下载的第三方库是不会有需求不满足的情况,但也有极少的情况,第三方库没有兼顾到需求,本文将介绍几个修改源码的操作,大家可以根据需求进行选择... 目录需求不符合模拟示例 1. 修改源文件2. 继承修改3. 猴子补丁4. 追踪局部变量需求不符合很

java中使用POI生成Excel并导出过程

《java中使用POI生成Excel并导出过程》:本文主要介绍java中使用POI生成Excel并导出过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录需求说明及实现方式需求完成通用代码版本1版本2结果展示type参数为atype参数为b总结注:本文章中代码均为

在java中如何将inputStream对象转换为File对象(不生成本地文件)

《在java中如何将inputStream对象转换为File对象(不生成本地文件)》:本文主要介绍在java中如何将inputStream对象转换为File对象(不生成本地文件),具有很好的参考价... 目录需求说明问题解决总结需求说明在后端中通过POI生成Excel文件流,将输出流(outputStre