【问题标题】:Saving a pytoch tensor as a 32-bit grayscale Image将 pytorch 张量保存为 32 位灰度图像
【发布时间】:2021-06-29 21:34:21
【问题描述】:

我处理了一个 32 位灰度 .tif 图像,我使用 PIL 将其转换为张量。在此之后,我将其保存为:

torchvision.utils.save_image(train_img_poac,fp=str(j)+".tif")

此方法自动将张量转换为 RGB 格式的图像。我希望我的输出图像是 32 位灰度图像。

我尝试使用 save_image 函数中的参数,但找不到任何东西。是否将其转换为 numpy ndarray,然后将其转换为 32 位图像?

【问题讨论】:

标签: python python-3.x image-processing pytorch save-image


【解决方案1】:

很遗憾,save_image 没有保留单通道图像的选项。你可以像 OpenCV 一样使用different library

import cv2

image = train_img_poac.numpy()
cv2.imwrite('image_name', image)

【讨论】:

    猜你喜欢
    • 2021-02-19
    • 2021-04-05
    • 1970-01-01
    • 1970-01-01
    • 2011-03-04
    • 2015-08-04
    • 1970-01-01
    • 2020-10-31
    • 2015-06-24
    相关资源
    最近更新 更多