Gimp-Forum.net
replicating grain extract in blender using nodes - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+--- Thread: replicating grain extract in blender using nodes (/Thread-replicating-grain-extract-in-blender-using-nodes)



replicating grain extract in blender using nodes - mindvox - 08-16-2022

I tried to use the Formula in the manual but the results are similar to when I use Subtract and Addition Modes in Gimp when using MixRGB Nodes in Blender.
 I tried separating the RGB channels and did a straight up calculation on each channel and the results look to washed out. 

I looked in the code at github and is says:

[blendModeKeys.GRAIN_EXTRACT]: (i, m) => (
i - m + 0.5

I attached a pic of the Node Setup and the results and what it should look like.
Anybody know what the problem is?


RE: replicating grain extract in blender using nodes - Ofnuts - 08-16-2022

Are you working in "Linear space" or in "Perceptual"?

Originally, Gimp worked in a gamma-corrected perceptual space: The 255 available values per channel do not represent the level directly, but are  a function of it (about a square root: but 1/2.24instead of 2). This gives more level points to distinguish the darks (the middle gray, is around 180 instead of 128). And all computations were done directly on these values.

When you use a [0.0 ... 1.0] scale, you are using floating point and are not limited  by the number of distinct value points, so your values can represent the level directly.

The I-M+0.5 formula was applied directly on the gamma corrected values

gamma( R ) = gamma( I ) - gamma( M ) + 0.5

But in linear space you do:
 
gamma( R ) = gamma( I - M + 0.5 )

(in the second case the gamma isn't applied on the stored values, but applied when passing the data to the display (or exporting to JPEG/PNG)

 There is a way to tell if this is your problem: in Gimp 2.10 the "legacy" blend modes(*) are applied on the linear values as if they were gamma corrected, so if the legacy Grain Extract produces the same result as your Blender computation, you are doing the computation on lianear values.


(*) this is the small selector at the end of the blend mode selector in the Layers list, Wilber's head switching the modes to "legacy". You also get a (l)  in the mode name: [Image: ecca5fV.png]


RE: replicating grain extract in blender using nodes - mindvox - 08-20-2022

Yep Gamma was the issue!!  You need to set the Image Texture Nodes from sRGB to Linear, Raw, or Non-Color, and after the equation, stick a Gamma Node at the end of it and set it to 2.2 to 2.5. You don't even need Math Nodes it works for MixRGB as well.