0

我正在处理 .svs 格式的大于 8 GB 的图像。使用 openslide,我将它们读取为 1D numpy 数组。现在,为了将它们输入算法,我需要将它们重塑为图像形式,以处理像素位置相关信息。由于图像非常大,使用 PIL 将 numpy 数组转换为

image=np.load('test.npy') 
im=Image.fromarray(image)

给我一个错误size does not fit in int。我试图通过将dtypefrom更改为uint8来解决此错误,uint64但是,尽管64GB RAM and 3 TB memory我的工作站上有,但我的 python 一直在崩溃。

然后我尝试使用以下方法加载 numpy 数组memmap

    im = np.load(curr_path)
    shapeIm=im[:].shape  ##shape of the image
    name_no_ext = os.path.splitext(f[i])[0]
    filename=path.join(dir,name_no_ext+'.tif') ##filename to save the image file
    #Create a memmap with dtype and shape that matches our data:
    fp = np.memmap(filename, dtype='uint8', mode='w+',shape=shapeIm)  #memmap to read/write very large image files in chunks directly from disk
    #Write data to memmap array:
    fp[:] = im[:]
    fp.filename == path.abspath(filename)
    #Deletion flushes memory changes to disk before removing the object:
    del fp
    #Load the memmap and verify data was stored:
    newfp = np.memmap(filename, dtype='uint8', mode='r+', shape=shapeIm)

现在上面的代码给了我一个.tif格式的图像。但是,我无法处理它。我分析不出来为什么?我发现当我尝试读取该图像并打印其形状时。

AttributeError:“NoneType”对象没有属性“形状”

所以,这种方式对我来说也失败了。然后我尝试以图像的形状(44331、64625、3)重塑numpy数组,但出现以下错误

ValueError:序列太大;不能大于 32

谁能帮我处理这样的图像。我在 x、y、z 像素位置对这些图像进行了注释,并将这些注释作为基本事实处理,我需要将我的 numpy 数组转换为图像的形式。

任何帮助都会很棒。

编辑:我现在正在重塑 numpy 数组。但是,仍然不知道如何使用 numpy 文件作为我的数据集输入而不是图像。

4

0 回答 0