You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何低内存旋转填充大numpy数组并生成OpenSlide兼容WSI?

大WSI图像低内存旋转与填充方案需求

我正在处理大尺寸全玻片图像(WSI),制作过程中用OpenCV完成计算,并将帧存入一个50kx50kx3的numpy数组,内存占用约7.5GB。

  • 最初用cv2.imwrite保存TIFF文件,但用OpenSlide打开时抛出「unsupported or missing image file」错误,排查发现OpenCV不支持保存金字塔图像,转而尝试用pyvips保存金字塔格式的TIFF。
  • 由于相机为快速扫描做了旋转,保存前需要对图像进行旋转操作,但使用OpenCV旋转时程序内存占用直接翻倍;处理图像边缘填充时,也会出现短暂内存翻倍的情况。

现寻求低内存占用的旋转与填充最优方法,以下是当前使用的填充和旋转代码:

当前填充代码

if np.shape(test_matrix)[1] - (cm2 + int(y_edge_on_wsi) + y_in) <= 2000:
    test_matrix = np.pad(test_matrix, ((0, 0), (0, 10000), (0, 0)), mode='constant', constant_values=255)

if np.shape(test_matrix)[0] - (cm1 + int(x_edge_on_wsi) + x_in) <= 2000:
        test_matrix = np.pad(test_matrix, ((0, 10000), (0, 0), (0, 0)), mode='constant', constant_values=255)

# 在test_matrix开头添加行或列
if cm2 + int(y_edge_on_wsi) <= 2000:
    test_matrix = np.pad(test_matrix, ((0, 0), (10000, 0), (0, 0)), mode='constant', constant_values=255)
    cm2 = cm2 + 10000
if cm1 + int(x_edge_on_wsi) <= 2000:
    test_matrix = np.pad(test_matrix, ((10000, 0), (0, 0), (0, 0)), mode='constant', constant_values=255)
    cm1 = cm1 + 10000

当前旋转代码

self.image = cv2.rotate(self.image, cv2.ROTATE_90_CLOCKWISE)
cv2.imwrite(self.fullSavePathTiff, self.image)

内存占用情况

  • 旋转前内存使用:内存占用(旋转前)
  • 旋转后内存使用:内存占用(旋转后)

内容的提问来源于stack exchange,提问作者sinamcr7

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 09:51:10