joheras / CLoDSA

123 stars 33 forks source link

How to apply two augmentation techniques sequentially to a single image [feature] #19

Closed rivered closed 3 years ago

rivered commented 3 years ago

First off, thank you for this great library. Got it up and running in no time, output is great.

It is nice to have some augmented data which has different brightness or is rotated, but imo it would be even better to have, as an example, a rotated image which has its brightness altered. A workaround would be to generate the augmented images, and use them as input for the second augmentation round. It would be more preferred to do this directly.

I am not sure how the augmentor.addTransformer works but it seems to append to self.transformers. applyAugmentation(self) and readImagesAndAnnotations(self) seem to do all the work based on the input provided to the augmentor. Is there an easy way to implement this feature?

Currently I am using the following setup:

from clodsa.transformers.transformerFactory import transformerGenerator
from clodsa.techniques.techniqueFactory import createTechnique
import cv2
%matplotlib inline

#Creating the augmenter object
PROBLEM = "detection"
ANNOTATION_MODE = "coco"
GENERATION_MODE = "linear"
OUTPUT_MODE = "coco"
augmentor = createAugmentor(PROBLEM,ANNOTATION_MODE,OUTPUT_MODE,GENERATION_MODE,INPUT_PATH,{"outputPath":OUTPUT_PATH})

#Adding the augmentation techniques
#Example for rotation and flip
#As a general rule of thumb, an image should not be augmented more than 2 times
transformer = transformerGenerator(PROBLEM)

#Gamma correction (brightening)
gamma_correction = createTechnique("gamma",{"gamma":2.5})
augmentor.addTransformer(transformer(gamma_correction))

#Rotations
for angle in [45, 90,180, 225]:
    rotate = createTechnique("rotate", {"angle" : angle})
    augmentor.addTransformer(transformer(rotate))

#Perform the augmentations
augmentor.applyAugmentation()

Thanks

joheras commented 3 years ago

First of all, thanks for your comments.

I think that the feature that you mean is the "power" mode. Currently, this mode is only supported when working with hdf5 files: https://github.com/joheras/CLoDSA/blob/master/docs/configuration.md#folders-hdf5-power

It would be possible to add this mode to the other augmentation procedures, but the problem is the explosion of images that are generated.

Let me know if that is what you are looking for.

Best, Jónathan

El mié., 14 oct. 2020 a las 0:21, rivered (notifications@github.com) escribió:

First off, thank you for this great library. Got it up and running in no time, output is great.

It is nice to have some augmented data which has different brightness or is rotated, but imo it would be even better to have, as an example, a rotated image which has its brightness altered. A workaround would be to generate the augmented images, and use them as input for the second augmentation round. It would be more preferred to do this directly.

I am not sure how the augmentor.addTransformer works but it seems to append to self.transformers. applyAugmentation(self) and readImagesAndAnnotations(self) seem to do all the work based on the input provided to the augmentor. Is there an easy way to implement this feature?

Currently I am using the following setup:

from clodsa.transformers.transformerFactory import transformerGenerator from clodsa.techniques.techniqueFactory import createTechnique import cv2 %matplotlib inline

Creating the augmenter object

PROBLEM = "detection" ANNOTATION_MODE = "coco" GENERATION_MODE = "linear" OUTPUT_MODE = "coco" augmentor = createAugmentor(PROBLEM,ANNOTATION_MODE,OUTPUT_MODE,GENERATION_MODE,INPUT_PATH,{"outputPath":OUTPUT_PATH})

Adding the augmentation techniques

Example for rotation and flip

As a general rule of thumb, an image should not be augmented more than 2 times

transformer = transformerGenerator(PROBLEM)

Gamma correction (brightening)

gamma_correction = createTechnique("gamma",{"gamma":2.5}) augmentor.addTransformer(transformer(gamma_correction))

Rotations

for angle in [45, 90,180, 225]: rotate = createTechnique("rotate", {"angle" : angle}) augmentor.addTransformer(transformer(rotate))

Perform the augmentations

augmentor.applyAugmentation()

Thanks

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/joheras/CLoDSA/issues/19, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJRAG6RTKYDJAT6VADRHNDSKTHGPANCNFSM4SPY3RVA .

rivered commented 3 years ago

Dear Jónathan,

This would indeed lead to an explosion of the images that are being generated. My use case would be more simple: Have a single input image and a single output image which has undergone two techniques. Basically it would entail the possibility to chain two techniques for a single image or a group of images.

gamma_correction = createTechnique("gamma",{"gamma":2.5}) -> rotate = createTechnique("rotate", {"angle" : angle}) -> augmentor.addTransformer(transformer(gamma_correction&rotate))

img_001.jpg --> gamma_correction&rotate --> img_001_gammacorrected&rotated.jpg

joheras commented 3 years ago

I see. Currently that feature is not implemented, I will try to include it in a new version of the library. Best

El mié., 14 oct. 2020 a las 11:08, rivered (notifications@github.com) escribió:

Dear Jónathan,

This would indeed lead to an explosion of the images that are being generated. My use case would be more simple: Have a single input image and a single output image which has undergone two techniques. Basically it would entail the possibility to chain two techniques for a single image or a group of images.

gamma_correction = createTechnique("gamma",{"gamma":2.5}) -> rotate = createTechnique("rotate", {"angle" : angle}) -> augmentor.addTransformer(transformer(gamma_correction&rotate))

img_001.jpg --> gamma_correction&rotate --> img_001_gammacorrected&rotated.jpg

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/joheras/CLoDSA/issues/19#issuecomment-708268920, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJRAG2ECC2FKKFZNPR6PRDSKVTBZANCNFSM4SPY3RVA .

rivered commented 3 years ago

Thank you!

joheras commented 3 years ago

This feature has been recently included by @juanmed