I am creating a synthetic dataset to train a model that needs to find documents in an image. the documents will be far from perfect, i.e they were folded, creased and wrinkled crinkled.
I could find a few ways of doing it in photoshop but I was wondering if someone has a better idea of doing this augmentation in opencv without trying to reverse engineer the photoshop process.
for example (from https://www.photoshopessentials.com/photo-effects/folds-creases/):
to:
or crinkles (from https://www.myjanee.com/tuts/crumple/crumple.htm):
5
Answers
Without too much work I came up with this result. It’s far from perfect but I think it is in the right direction.
From this:
And this:
We get this (blend 0.5):
Or this (blend 0.333):
Here is also one with folds:
This is not an answer to your question. It’s more about using a blending mode suitable for your application. See more details about blending modes in the wiki page. This might help you address the quality loss. Following code implements the first few blend modes under Multiply and Screen from the wiki page. This does not address the Plastic Wrap filter and the effects added using the Brushes given in the Photoshop tutorial you refer.
You’ll still have to generate the overlays (image b in the code), and I agree with Nelly’s comment regarding augmentation.
Photoshop Soft Light:
The proper way to apply the wrinkles to the image is to use hardlight blending in Python/OpenCV.
Cat image:
Wrinkle image:
Wrinkled Cat image:
I have tried to put all your distortions together in one script in Python/Opencv.
Input:
Wrinkles:
Wrinkles adjusted:
Wrinkles with folds:
Wrinkles with folds and creases:
Result:
As you are creating a static synthetic data set, a more realistic and possibly the simplest solution seems to be using DocCreator to randomly generate the data set for you.
With the given sample:
One can generate the following data set
Via Image > Degradation > Color Degradation > 3D distortion
Then you choose the Mesh (Load mesh…) and finally hit the save random images… button and select the constraints.
Generating a data set with more subtle distortions is possible by changing the Phy and the Theta upper and lower bounds.
The project offers a demo that allows one to better assess whether it is applicable to your purposes.