0

I am having a 3 channel image, in which each channel has some information encoded in the form of colors. I want to convert it to a single channel image with all the information retained. When I convert it into 1 channel (using grayscale) I loose all that color information and get a tensor with zero values and visualizing this image show a total black image.

So, is there any way to change the 3 channel image to 1 channel image but not grayscale ?

Irfan Umar
  • 196
  • 3
  • 18

1 Answers1

0

You probably have to keep the 3 channels. 1 channel images do not have colors, since you need an additional dimension to represent them. Why would you want to drop the channels and keep the color information at the same time? In typical image processing with deep learning, the tensors have dimensions such as [Batch x Channel x Height x Width] (more frequent in pytorch) or [Batch x Height x Width x Channel] (more frequent in tensorflow). What is the real problem with 3 channels?

87VN0
  • 775
  • 3
  • 10
  • Actually I have masked images in 3 channels, and I want to use its converted information into 1 channel. That I will further use as a ground truth to UNet with data images. Usually I have seen people using 1 channel as ground truth for UNet. – Irfan Umar Jun 30 '20 at 15:21
  • @IrfanUmar the ground truth of a segmentation network is not a color image, but a per-pixel segmentation label, which can be represented as a one channel image. – Dr. Snoopy Jun 30 '20 at 18:11
  • @Dr.Snoopy exactly, that is why I want to convert 3 channel image into one channel. – Irfan Umar Jun 30 '20 at 18:16
  • 1
    @IrfanUmar With U-nets what you would like to have is called "1 hot encoding". If you have 10 different classes, you have to transform the image into a 10 channel image. This answer will probably help https://stackoverflow.com/questions/43884463/how-to-convert-rgb-image-to-one-hot-encoded-3d-array-based-on-color-using-numpy – 87VN0 Jun 30 '20 at 20:14
  • @ Irfan Umar I have a same question as yours. Have you found the solution to your question? – rayan Sep 05 '22 at 06:42