For an augmentation that simulates infrared, I'd like to change the R,G AND B components, increase or decrease their intensity. I noticed that ops.ColorTwist operator can do something like this in HSV space. Is there a way to tune R,G,B in RGB space in DALI?
(What I am trying to achieve is infrared augmentation smth like the one used in Photoshop: https://www.photoshopessentials.com/photo-effects/infrared-photo/)
Thank you!
Hello @bamfpga !
If you only need to _linear_ transformation of your RGB space pixels, you can treat pixels as 3D points and apply arbitrary affine transform to them:
import nvidia.dali.fn as fn
matrix = [a, b, c, d,
e, f, g, h,
i, j, k, l]
out_images=fn.coord_transform(my_images, MT=matrix, dtype=dali.types.UINT8) # you need to specify type, otherwise it will convert your data to float
Moreover, the matrix may be a datanode and you can use spatial transforms such as scaling and translation to achieve brightness/contrast adjustment:
contrast = fn.transforms.scale(scale=[1.4, 1.2, 2.0])
matrix = fn.transforms.translation(contrast, offset=[64,32,10])
out_images=fn.coord_transform(my_images, MT=matrix, dtype=dali.types.UINT8)
The mentioned transforms are available in the nightly/weekly build and will be part of the 0.28 release.
Thank you @mzient and @JanuszL.
I only managed to find the CoordTransform operator: https://docs.nvidia.com/deeplearning/dali/user-guide/docs/supported_ops.html?highlight=translation#nvidia.dali.ops.CoordTransform
The scale and translation operator will be soon added, right? They are not available in the 0.21 release I am using, am I correct?
@mzient , the code you provided me will scale and shift the pixels of each channel of the image accordingly, right? exactly what I need to scale or offset R,G or B components.
"contrast = fn.transforms.scale(scale=[1.4, 1.2, 2.0])
matrix = fn.transforms.translation(contrast, offset=[64,32,10])
out_images=fn.coord_transform(my_images, MT=matrix, dtype=dali.types.UINT8)"
Thanks again for the clarifications!
That is correct. 0.21 doesn't have it.
@bamfpga
Yes, scale/translation will scale and shift channels independently.
0.21 is positively ancient. All the operators mentioned will be available in 0.28. You can use latest nightly build - see https://docs.nvidia.com/deeplearning/dali/user-guide/docs/installation.html#nightly-and-weekly-release-channels for instructions on installing nightly builds.
DALI 0.28 has been released. It should address your request.