1

I have manipulated a 32-bit grayscale .tif image which I converted to tensor using PIL. After this I saved it with:

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

This method automatically converts the tensor to an RGB format image. I want my output image to be a 32-bit grayscale image.

I tried to use the arguments in the save_image function but could not find anything. Is converting it to numpy ndarray and then converting it to a 32-bit Image an option?

iacob
  • 20,084
  • 6
  • 92
  • 119

1 Answers1

1

Unfortunately save_image doesn't have an option for preserving one-channel images. You can use a different library like OpenCV:

import cv2

image = train_img_poac.numpy()
cv2.imwrite('image_name', image)
iacob
  • 20,084
  • 6
  • 92
  • 119