# Pixel Bender

Currently Being Moderated

## How to create gamma (midtone) changes with help Pixel Bender?

### Feb 19, 2012 10:12 AM

Tags:

I'd like to create Level correction with help Pixel Bender. I made correction for each channel (r, g, b), it works. But I don't know how to make correction for midtone for each one.

Is there some formula or example?

I use the next code for each channel, for instance, the red channel will be look like

dst.r = ((dst.r-red[0])/(red[1]-red[0])-rgb[1]-rgb[0]), where red[n], rgb[n] are the values which can be changed by user

Replies
• Currently Being Moderated
Feb 24, 2012 4:34 PM   in reply to IlyaMordasov

I'm not sure I'm understanding exactly what you're wanting.  There is a gamma tutorial with some glsl shaders at:

http://www.geeks3d.com/20101001/tutorial-gamma-correction-a-story-of-l inearity/

A PixelBender shader for the channel by channel gamma is:

<languageVersion : 1.0;>

kernel channelByChannelGamma

<   namespace : "cfr";

vendor : "AIF";

version : 1;

>

{

input image4 src;

output pixel4 dst;

parameter float3 gammaRGB <defaultValue:float3(1.0, 1.0, 1.0);>;

void

evaluatePixel()

{

dst = sampleNearest(src,outCoord());

dst.rgb = pow(dst.rgb, 1.0 / gammaRGB);

}

}

|
Mark as:
• Currently Being Moderated
Feb 24, 2012 4:34 PM   in reply to AIF Chuck

Please let me know if I'm misunderstanding what you're trying to do here.

|
Mark as:
• Currently Being Moderated
Feb 27, 2012 9:00 AM   in reply to IlyaMordasov

gammaRGB is a float3.  If you wanted to alter the gamma for G and leave the others unchanged, you can set that parameter to (1.0, greenGamma, 1.0).  The pow function and the 1.0 divide in the kernel are componentwise.  This line instead would have been equivalent, but does make the intention clearer:

dst.rgb = pow(dst.rgb, float3(1.0, 1.0, 1.0) / gammaRGB);

Most of the intrinsic functions will return vectors if their operands are vectors.  Intrinsitcs like dot, any, and all, which specifically reduce a vector input to a scalar output, are the exceptions.

|
Mark as:
• Currently Being Moderated
Feb 28, 2012 11:03 AM   in reply to IlyaMordasov

I'm glad I was able to help.  I'm not certain what the exact formula the Photoshop team is using, so I was going on one in the gamma tutorial website I was pointed out earlier in this thread.  That seemed to follow the standard gamma formulation I've seen on wiki and in the CG texts I have in my office.

I did have a look at the panel you suggested.  I don't think I've used that one before, so thanks for the pointer.

Best,

Chuck.

|
Mark as:
Actions

#### More Like This

• Retrieving data ...

#### Answers + Points = Status

• 10 points awarded for Correct Answers