0

我有一个包含 853 个图像的大型图像堆栈,每个图像都有尺寸(11779、15394)像素和 3 个通道。图像具有 8 位深度,并以 BigTiff 格式保存。我的数据存储在连接到计算机的外部 SSD 上。我想要做的是根据初始值改变一些像素的值。由于我无法将整个堆栈加载到内存中,因此我使用 tifffile.memmap 来内存映射我想要调查和更改的像素。

这是我的代码外观的一个最小示例:

import numpy as np
from tifffile import memmap

memmap_img_HSV = memmap('img_HSV.tif', mode='r')    #original image stack I want to investigate
memmap_img_result = memmap('img_result.tif', mode='r+')    #another image which I want to overwrite with the results

img_hue = memmap_img_HSV[:,:,:,0]    #first channels of original image

memmap_img_result[:,:,:] = 0    #set all pixels = 0, before I save the results into it

fill_value = 11    #define the variable "fill_value" which will be used later
sigma_list = []    #create a list where I later save coordinates in

array_label = memmap_img_result[z1:z2, y1:y2, x1:x2]    #only memmap indicated pixels
array_hue = img_hue[z1:z2, y1:y2, x1:x2]

count = array_label == fill_value                       #these are the pixels which have already been investigated and replaced by the "fill_value"

orig_value_hue = np.median(array_hue[count])    #determine the median value of the pixel values from "count"

org = memmap_img_result[zv1:zv2, yv1:yv2, xv1:xv2]    #original values of the investigated pixels

if (orig_value_hue+1) < 10:    #condition, which pixels should be replaced with "fill_value": the rest stays how it was before
    res = np.where((memmap_img_HSV[zv1:zv2, yv1:yv2, xv1:xv2] == 0), fill_value, org)

if (orig_value_hue+1) < 10:    #another condition; if this is True, write the coordinates into list 
    res_sigma = np.argwhere(memmap_img_HSV[zv1:zv2, yv1:yv2, xv1:xv2] == 1)
    if len(res_sigma)>0:
        sigma_list.append([zv1,yv1,xv1])
        sigma_list = np.asarray(sigma_list[1])

        if len(sigma_list[sigma+1])>0:
            np.savetxt('list.txt', np.column_stack([sigma_list[1]]))

memmap_img_result.flush()
del memmap_img_HSV
del memmap_img_result

如果代码看起来有点混乱,我深表歉意;它只是对更复杂的代码的简化。但我希望,目标明确。

现在我的问题如下:当我运行代码时,有时会发生代码崩溃。将文件“list.txt”写入磁盘时,我会收到错误消息“设备上没有剩余空间”,尽管磁盘上有很多可用空间(足以保存列表)。或者我收到错误消息“无效参数:'list.txt'”。此外,SSD 在错误消息后显示 0 kB 大小。我首先必须修复磁盘并重新启动,然后才能再次使用该磁盘。我认为这不是 memmap 的问题,而是以某种方式将列表保存为文本文件。

我已经可以使用其他(较小的)数据运行代码而没有任何错误消息,但它会因这些数据而崩溃。有人知道什么可能导致崩溃或我可以尝试什么吗?

4

0 回答 0