jit.normalize equivalent for textures

Jonas Magnussen's icon

Hello! Is there any object or solution out for a version of jit.normalize that operates on the GPU? I often find myself confused once I'm trying my hand at GPU tasks that requires analysing an entire texture. In this case, I would need to find the minimum and maximum pixel value in an entire texture (or the min/max pixel values of the texture's luminosity, in the case of an image).

Matteo Marson's icon

Hey Jonas,

normalizing the values of a texture isn't as trivial as making the same on the CPU. You can, of course, read back the texture on the CPU and use jit.normalize, but depending on the size of the texture, it could be an important bottleneck performance-wise.
This could be a way to go:

Max Patch
Copy patch and select New From Clipboard in Max.

I keep narrowing down the dimension of the texture, comparing neighboring pixels and keeping the relative minimum and maximum values. I repeat the same operation both horizontally and vertically to finally get two 1x1 textures containing the "winners" of the playoffs: the lowest and highest values.
The normalization is then very simple:
normVal = (val - min) / (max - min)

Just remember to adapt the number of iterations depending on the size of the initial texture.

Hope this helps, cheers!

C Hausch's icon

@ matteo marson

i was just searching for a answer to this very same problem – your solution works brilliantly, thanks for posting it!