使用openslide

阅读: 评论:0

使用openslide

使用openslide

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能够解析的图像信息了,以及实现图像切分等操作,具体可参见官网:/
下面是部分我认为可能需要用到的操作(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 = _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(_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=""><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 = _tile(11,(0,0))
tile_img2 = _tile(11,(0,1))
plt.imshow(tile_img1)
plt.show()
plt.imshow(tile_img2)
plt.show()


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

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

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

# Return ad_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 = _tile_coordinates(11, (0,0))
print(read_region)#Return a (pixels_x, pixels_y) tuple for the specified tile.
print(_tile_dimensions(12, (0,0)))

输出:

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

本文发布于:2024-01-31 13:37:30,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170667945328913.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:openslide
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23