如何将dicom图像分割成块?

2024-05-15 02:50:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用image_slicer函数将DICOM图像分割成平铺,但它无法识别DICOM。在

我已经阅读了DICOM并将其转换为np数组:

dcm_文件[0]

array([[-1024, -1024, -1024, ..., -1024, -1024, -1024],
       [-1024, -1024, -1024, ..., -1024, -1024, -1024],
       [-1024, -1024, -1024, ..., -1024, -1024, -1024],
       ...,
       [-1024, -1024, -1024, ..., -1024, -1024, -1024],
       [-1024, -1024, -1024, ..., -1024, -1024, -1024],
       [-1024, -1024, -1024, ..., -1024, -1024, -1024]], dtype=int16)

并且能够通过以下方式查看图像:

^{pr2}$

然后试着把它切开:

import image_slicer
image_slicer.slice(img, 64)

错误:“Image”对象没有属性“read”

谢谢!在


Tags: 文件函数图像imagenp方式数组array
1条回答
网友
1楼 · 发布于 2024-05-15 02:50:18

模块image_slicer使用文件名,而不是文件实例。因此,必须将数组保存到某个局部。您可以为此使用^{} module。在

from PIL import Image
import numpy as np
import image_slicer
import tempfile

array = np.random.randint(0,200, size=(128,128), dtype='int32')

img = Image.fromarray(array)

temp = tempfile.NamedTemporaryFile()
img.save(temp.name, format="png")

image_slicer.slice(temp.name, 4)
#if you want to play with the slices:
tiles = image_slicer.slice(temp.name, 4, save=False)

相关问题 更多 >

    热门问题