albumentations icon indicating copy to clipboard operation
albumentations copied to clipboard

[FR] Grayscale to RGB

Open hoangtnm opened this issue 3 years ago • 7 comments

Hi, I'm using albumentations for my project, but my image is GrayScale with shape [H, W] but I need to use RGB image (3 channels or [H, W, 3]) for training neural networks. Does the library provides any transformation to convert grayscale to RGB, which is similar to tf.image.grayscale_to_rgb? thank you

hoangtnm avatar Oct 08 '21 14:10 hoangtnm

You can use cv2.cvtColor function from OpenCV to do this conversion. We have support for grayscale image augmentation for vast majority of transforms as well. You can also change the network to take the single channel input instead of taking three channels. So there are many options.

Пт, 8 окт. 2021 г. в 17:49, Tran N.M. Hoang @.***>:

Hi, I'm using albumentations for my project, but my image is GrayScale with shape [H, W] but I need to use RGB image (3 channels or [H, W, 3]) for training neural networks. Does the library provides any transformation to convert grayscale to RGB, which is similar to tf.image.grayscale_to_rgb? thank you

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/albumentations-team/albumentations/issues/1032, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEB6YG4FCVXRKXGP7ROCE3UF4AHXANCNFSM5FTZIUVA .

BloodAxe avatar Oct 08 '21 14:10 BloodAxe

@BloodAxe I understand your idea, but I think having a transformation like A.RepeatChannels(3) or A.ToRGB will be more easy-to-use rather than use cv2.cvtColor outside A.Compose[...]. Another question is how to scale image in range [0, 255] to [0, 1] like torchvision's ToTensor, but when I try albumentations.pytorch.transforms.ToTensorV2, it just swaps channels from [H, W, C] to [C, H, W]. Does albumentations have any equivalent transform?

hoangtnm avatar Oct 08 '21 16:10 hoangtnm

A combination of [A.Normalize(), A.ToTensorV2()] should do the job. Please refer to this notebook for an example.

BloodAxe avatar Oct 08 '21 16:10 BloodAxe

Hi @BloodAxe, as I understand RGBShift is used for RGB image with shape [H, W, 3], does albumentations has the equivalent transform for Grayscale image with shape [H, W]?

hoangtnm avatar Oct 10 '21 15:10 hoangtnm

+1 for a ToRGB transformation in the same vein as ToGray

amin-nejad avatar Dec 06 '21 17:12 amin-nejad

Is this Issue still ongoing? Can I take it?

Beluuuuuuga avatar Jan 15 '22 14:01 Beluuuuuuga

A transformation A.ToRGB would be very usefull.

domef avatar May 12 '22 09:05 domef

ToRGB added in #1323

Dipet avatar Oct 25 '22 19:10 Dipet