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

Chromatic Abberation #1386

Closed
KulikDM opened this issue Jan 25, 2023 · 5 comments
Closed

Chromatic Abberation #1386

KulikDM opened this issue Jan 25, 2023 · 5 comments

Comments

@KulikDM
Copy link

KulikDM commented Jan 25, 2023

Hi, I'm not sure if any augmentation like this exists in Albumentations. But if not, chromatic abberation would be a great addition. Chromatic abberation occurs when a camera lens fails to focus all the colors at the focal point of the lens due to dispersion. This effect can easily be replicated in python. Below is an example code of the implementation:

import numpy as np

image[:, :, 0] = np.roll(image[:, : ,0], -px_shift * 2)
image[:, :, 1] = np.roll(image[:, :, 1], -px_shift)

where px_shift is the number of pixels the color is shifted by and the direction is set by the sign in front of the pixel shift. Both the direction and the pixel shift can be randomized with the pixel shift also being able to be assigned a random range.

@mrsmrynk
Copy link
Contributor

Simply shifting the 2 channels (blue and red) would apply the chromatic aberration effect to the whole image.
This might not be the desired effect since the color fringing typically occurs only at the edges of the image.

To simulate lateral chromatic aberration, the shift should be applied to the individual channels separately with respect to the radial distance from the center of the image.

This can be done by splitting the image into its RGB channels, applying a slight amount of distortion to the blue and red channels, and then merging the channels back together.
The border mode should be set to cv2.BORDER_REFLECT to avoid black borders in the channels, if the distortion gets quite large.

If this transform seems useful, I would like to implement it as an ImageOnlyTransform.

@KulikDM
Copy link
Author

KulikDM commented Mar 14, 2024

Great to hear back on this!
You are totally right, my implementation was an overly simplistic one and lateral chromatic aberration as you described would be much more realistic. If it looks something like (https://smallpond.ca/jim/photomicrography/ca/index.html) then you have me super excited. Please implement it, by all means, looking forward trying it out.

@mrsmrynk
Copy link
Contributor

Already implemented this for our augmentation pipeline. The results look like this:

Left: Original, Middle: Subtle chromatic aberration, Right: Strong chromatic aberration
(Image is from our internal mobile mapping dataset)

Waiting for feedback from @albumentations-team, then I'll make a PR :)

@ternaus ternaus added the enhancement New feature or request label Mar 14, 2024
@ternaus
Copy link
Collaborator

ternaus commented Mar 14, 2024

@mrsmrynk Looks great.

Waiting for a PR :)

@ternaus ternaus added feature request and removed enhancement New feature or request labels Mar 14, 2024
@ternaus
Copy link
Collaborator

ternaus commented Mar 18, 2024

Added by @mrsmrynk in #1589

@ternaus ternaus closed this as completed Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants