Python 如何使用matplotlib显示CZI格式的图像?

Python 如何使用matplotlib显示CZI格式的图像?,python,matplotlib,image-processing,Python,Matplotlib,Image Processing,我用czifile库读取了一个图像 import czifile img = czifile.imread("static/Osteosarcoma_01.czi") print(img.shape) 输出: (1, 1, 3, 1104, 1376, 1) 现在,我想使用Matplotlib库显示此图像。我如何才能做到这一点?您必须将光栅重塑为(1104、1376、3)才能显示图像。下面是一个代码: import czifile import numpy as

我用
czifile
库读取了一个图像

import czifile    
img = czifile.imread("static/Osteosarcoma_01.czi")
print(img.shape)
输出:

(1, 1, 3, 1104, 1376, 1)

现在,我想使用Matplotlib库显示此图像。我如何才能做到这一点?

您必须将光栅重塑为(1104、1376、3)才能显示图像。下面是一个代码:

import czifile
import numpy as np
import matplotlib.pyplot as plt

img = czifile.imread(file_path)
channels = []
for channel in range(3):
    channel_raster = img[0,0,channel,:,:,0]
    channels.append(channel_raster)
arr = np.stack(channels, axis=2)
plt.imshow(arr)
或者,您可以使用slideio软件包(),它可以为您做到:

import slideio
import matplotlib.pyplot as plt

slide = slideio.open_slide(file_path, "CZI")
scene = slide.get_scene(0)
plt.imshow(scene.read_block())


你能分享你的czi文件链接吗?@Karthik是图像。它看起来像一个2D彩色图像。重新排列尺寸就足够了。