question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Question/Request : augment image according to mask

See original GitHub issue

🔥 Feature Question/Request

Hello,

I would like to know if 📚 Albumentation 📚 is capable of augment only a certain part of the image, especially according to the mask. I did not find it in the documentation and I don’t know if it is something usual when doing data augmentation but what I would like to do is, for my binary segmentation problem, augment only where the mask is. For example, if I want to segment a clothing someone is wearing, I was thinking that it would be useful to have different color version. I know that there might be some artefact generated compared to the original version but still I think it could be a cool thing to have …

Does someone know if it exists already or if it is possible to integrate it ?

I actually know how to do it my self with python, but I am not sure on how to interface with albumentation … Here, I change randomly the color where the mask is :

image[mask==1,:] = image[mask==1,:] + np.random.randint(low=-50,high=50,size=3)

image

Thank you !

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
Dipetcommented, Nov 4, 2020

Interesting idea. But at this time I do not know how to do so that it would work with any transforms. For now you can use this wrapper:

import numpy as np
import albumentations as A
import matplotlib.pyplot as plt


class MaskWrapper(A.Sequential):
    def __call__(self, **data):
        image = data['image'].copy()

        data = super(MaskWrapper, self).__call__(**data)

        mask = data['mask'].astype(np.bool)
        image[mask] = data['image'][mask]
        data['image'] = image

        return data

transforms = A.Compose([
    MaskWrapper([A.GaussianBlur(p=1), A.RGBShift([50, 50], p=1)]),
    A.LongestMaxSize(512),
    MaskWrapper([A.HueSaturationValue(p=1)])
])

img = A.read_rgb_image("true.png")
mask = np.zeros_like(img)
mask[:500, :500] = 1

res = transforms(image=img, mask=mask)

plt.subplot(211, title="original")
plt.imshow(img, vmin=0, vmax=255)
plt.subplot(212, title="result")
plt.imshow(res['image'], vmin=0, vmax=255)
plt.show()

image

0reactions
Dipetcommented, Nov 4, 2020

I think it is good feature. So let it be open.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data Augmentation with Masks - Apache MXNet
Our Dataset will return base images with their corresponsing masks. ... default None A function that takes data and label and transforms them:...
Read more >
Mask augmentation for segmentation - Albumentations
For instance and semantic segmentation tasks, you need to augment both the input image and one or more output masks. Albumentations ensures that...
Read more >
Can I augment images and masks in Keras just using flow ...
You need a custom generator that applies the same augmentation to image and mask. Keras ImageDataGenerator takes 2 arguments (image,label or ...
Read more >
[Tutorial] Augmentation with mask & Visualizati n | Kaggle
Applying augmentation with mask​​ Focus on that image and compare second one. We can see also CoarseDropout results between image and mask.
Read more >
A Model-Based Augmentation Method for 2D Pose Estimation ...
knowledge is considered in the design of image augmentation for pose estimation. A masked autoencoder was shown to have a non-negligible ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found