Nib.load()错误-尝试加载要为FCNN调整大小的PNG和DICOM图像

问题描述 投票:0回答:1

具有一个完整CNN的40个DICOM和40个PNG图像(数据及其遮罩),这些图像已加载到我的Google云端硬盘中,并且已通过笔记本计算机通过print(os.listdir(...))找到,如下所示在第一段代码中,列出了上述集合中80个数据的所有名称。

还在下面的第二个代码块中,将所有DICOM和PNG都分为长度均为40的img_path和mask_path。

现在尝试将所有图像调整为256 x 256的大小,然后再将它们输入到类似架构的U-net中进行分割。但是,无法通过nib.load()调用加载它们,因为它无法计算出DCM和PNG文件的文件类型,即使对于后者也不会出错,但仍会生成一组空数据,如最后一个块代码产量。

假设纠正了第三段代码中for循环内的前几行,应完成预处理,然后我就可以进行U-net实现。

使当前的pydicom在Colab笔记本中运行并尝试代替nib.load()调用,该调用产生的错误与当前的错误相同。


import data as data -> this line is a comment
import pydicom
import numpy as np
import glob
print(os.listdir("/content/drive/My Drive/Images"))
print(os.listdir("/content/drive/My Drive/Masks"))
pixel_data = []
images = glob.glob("/content/drive/My Drive/Images/IMG*.dcm");
for image in images:
    dataset = pydicom.dcmread(image)
    pixel_data.append(dataset.pixel_array)
masks= cv2.imread("/content/drive/My Drive/Masks/IMG*.png");

** ['IMG-0004-00040.dcm','IMG-0002-00018.dcm','IMG-0046-00034.dcm','IMG-0043-00014.dcm','IMG-0064- 00016.dcm',....]

['IMG-0004-00040.png','IMG-0002-00018.png','IMG-0046-00034.png','IMG-0043-00014.png','IMG-0064-00016。 png',....] **

import glob
img_path = glob.glob("/content/drive/My Drive/Images/IMG*.dcm")
mask_path = glob.glob("/content/drive/My Drive/Masks/IMG*.png")
print(len(img_path))
print(len(mask_path))

40

40

import pydicom
for name in img_path:
    a=nib.load(name)
    a=a.get_data()
    print("image (%d) loaded"%(i))
    a=resize(a,(a.shape[0],256,256))
    a=a[:,:,:]
    for j in range(a.shape[0]):
        images.append((a[j,:,:]))

[ImageFileError:无法计算“ / content / drive /我的驱动器/Images/IMG-0004-00040.dcm”的文件类型

images=np.asarray(images)
print(images)

[]

import cv2
masks=[]
b=[]
for mask in masks:
    b=nib.load(mask)
    b=b.get_data()
    print("mask (%d) loaded"%(i))
    b=resize(b,(b.shape[0],256,256))
    b=b[:,:,:]
    for j in range(b.shape[0]):
        masks.append((b[j,:,:]))

输出为空白

masks=np.asarray(masks)
print(masks)

[]

png image-resizing dicom nib pydicom
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.