使用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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


原文地址:https://blog.csdn.net/MerryYoung/article/details/84071091
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.chinasem.cn/article/560221

相关文章

Java Thread中join方法使用举例详解

《JavaThread中join方法使用举例详解》JavaThread中join()方法主要是让调用改方法的thread完成run方法里面的东西后,在执行join()方法后面的代码,这篇文章主要介绍... 目录前言1.join()方法的定义和作用2.join()方法的三个重载版本3.join()方法的工作原

Spring AI使用tool Calling和MCP的示例详解

《SpringAI使用toolCalling和MCP的示例详解》SpringAI1.0.0.M6引入ToolCalling与MCP协议,提升AI与工具交互的扩展性与标准化,支持信息检索、行动执行等... 目录深入探索 Spring AI聊天接口示例Function CallingMCPSTDIOSSE结束语

Linux系统之lvcreate命令使用解读

《Linux系统之lvcreate命令使用解读》lvcreate是LVM中创建逻辑卷的核心命令,支持线性、条带化、RAID、镜像、快照、瘦池和缓存池等多种类型,实现灵活存储资源管理,需注意空间分配、R... 目录lvcreate命令详解一、命令概述二、语法格式三、核心功能四、选项详解五、使用示例1. 创建逻

Python实现批量提取BLF文件时间戳

《Python实现批量提取BLF文件时间戳》BLF(BinaryLoggingFormat)作为Vector公司推出的CAN总线数据记录格式,被广泛用于存储车辆通信数据,本文将使用Python轻松提取... 目录一、为什么需要批量处理 BLF 文件二、核心代码解析:从文件遍历到数据导出1. 环境准备与依赖库

在Java中使用OpenCV实践

《在Java中使用OpenCV实践》用户分享了在Java项目中集成OpenCV4.10.0的实践经验,涵盖库简介、Windows安装、依赖配置及灰度图测试,强调其在图像处理领域的多功能性,并计划后续探... 目录前言一 、OpenCV1.简介2.下载与安装3.目录说明二、在Java项目中使用三 、测试1.测

Python Web框架Flask、Streamlit、FastAPI示例详解

《PythonWeb框架Flask、Streamlit、FastAPI示例详解》本文对比分析了Flask、Streamlit和FastAPI三大PythonWeb框架:Flask轻量灵活适合传统应用... 目录概述Flask详解Flask简介安装和基础配置核心概念路由和视图模板系统数据库集成实际示例Stre

Python实现PDF按页分割的技术指南

《Python实现PDF按页分割的技术指南》PDF文件处理是日常工作中的常见需求,特别是当我们需要将大型PDF文档拆分为多个部分时,下面我们就来看看如何使用Python创建一个灵活的PDF分割工具吧... 目录需求分析技术方案工具选择安装依赖完整代码实现使用说明基本用法示例命令输出示例技术亮点实际应用场景扩

C++中detach的作用、使用场景及注意事项

《C++中detach的作用、使用场景及注意事项》关于C++中的detach,它主要涉及多线程编程中的线程管理,理解detach的作用、使用场景以及注意事项,对于写出高效、安全的多线程程序至关重要,下... 目录一、什么是join()?它的作用是什么?类比一下:二、join()的作用总结三、join()怎么

mybatis中resultMap的association及collectio的使用详解

《mybatis中resultMap的association及collectio的使用详解》MyBatis的resultMap定义数据库结果到Java对象的映射规则,包含id、type等属性,子元素需... 目录1.reusltmap的说明2.association的使用3.collection的使用4.总

Spring Boot配置和使用两个数据源的实现步骤

《SpringBoot配置和使用两个数据源的实现步骤》本文详解SpringBoot配置双数据源方法,包含配置文件设置、Bean创建、事务管理器配置及@Qualifier注解使用,强调主数据源标记、代... 目录Spring Boot配置和使用两个数据源技术背景实现步骤1. 配置数据源信息2. 创建数据源Be