Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Augment RGB and Grayscale image #845

Open
RGring opened this issue Feb 19, 2021 · 2 comments
Open

Augment RGB and Grayscale image #845

RGring opened this issue Feb 19, 2021 · 2 comments

Comments

@RGring
Copy link

RGring commented Feb 19, 2021

Hi,
Thanks for this nice library.

I couldn't find any information about how to augment a collection of different image types. In my case I would like to augment a RGB and grayscale image.
E.g. how can I apply Normalize() on those different types. Can I somehow set valid target identifier?

Thanks in advance!

@creafz
Copy link
Collaborator

creafz commented Feb 22, 2021

Hey, @RGring

You need to apply different normalization values (e.g., different mean or std) to RGB and Grayscale images. Do I understand the case correctly?

In such a situation, I think the simplest way is to define two separate augmentation pipelines and use the appropriate pipeline for an input image. For example:

transform_rgb = A.Compose([
    ...,
    A.Normalize(mean=..., std=...)
])

transform_grayscale = A.Compose([
    ...,
    A.Normalize(mean=..., std=...)
])

if is_rgb(image):
    transformed = transform_rgb(image=image)
else:
    transformed = transform_grayscale(image=image)

@RGring
Copy link
Author

RGring commented Mar 2, 2021

Thanks for the reply. I want to compose both images in the same way, except channel relevant augmentations like e.g. normalization. But your answer inspired me, splitting it in another way. Haven't thought about it. Thanks!

transform_both = A.Compose([
    ...,
    A.ShiftScaleRotate()
])

transform_grayscale = A.Compose([
    A.Normalize(mean=..., std=...)
])

transform_rgb = A.Compose([
    A.Normalize(mean=..., std=...)
])

transformed = transform_both(image=rgb_image, gray_image=gray_image)
normalized_grey = transform_grayscale(transformed["gray_image"])
normalized_rgb = transform_rgb(transformed["image"])

Have not yet tried it though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants