albumentations
albumentations copied to clipboard
ambiguity of albumentations.ToGray()
🐛 Bug
albumentations.augmentations.transforms.ToGray return a 3 channels image from
# albumentations/albumentations/augmentations/funtional.py
def to_gray(img):
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
return cv2.cvtColor(gray, cv2.COLOR_GRAY2RGB)
which means this funtion repeat the gray scale channel for 3 times. i thinl it would be suitable to return 'gray' directly or add some annotation to disambiguation
To Reproduce
Steps to reproduce the behavior:
- call the albumentations.ToGray() for any 3 channnel image
Expected behavior
Maybe an argument to specify 1/3 channels to return would be enough?
def to_gray(img, gray2rgb=False):
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
if gray2rgb:
return cv2.cvtColor(gray, cv2.COLOR_GRAY2RGB)
else:
return gray
May be it can refer to the
torchvision.transforms.Grayscale(num_output_channels=1)
def to_gray(img, num_output_channels=3):
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
if num_output_channels==3:
return cv2.cvtColor(gray, cv2.COLOR_GRAY2RGB)
elif num_output_channel==1:
return gray
else:
raise ImplementError# rasie an error
By setting the default argument 'num_output_channels' to 3, we can maintain the same visualization as before.