# Pixelshader Min, Max and Mean

I am doing a very basic GreyScale shader, and wanted to add some Contrast and Brightness.

I would like to know the Syntaxes I have to use to figure out this:

The formulas I found/use some great dutch tutorial about photoshop filters. Here they use the Maxium value (per color) and Minimum value (per Color) to calculate the middle off the color spectrum. (for red: R_Max + R_min / 2 )

Also another tutorial I found uses the Mean value (avarage) off the colors.

I am using this Microsoft Page as a guideline for the syntaxes (or is it called functions?), if any one knows a better one, please share!

Thnx for helping me, realy want to understand this.

West is digging into shaders! fine!

## as a start for you i took the constant.fx provided with vvvv after line 17 i inserted

float center <String uiname=“Brightness Center”;> = {0.5f};
float width <String uiname=“Brightness Width”;> = {0.5f};

## which adds two inlets with guesswhat names and default values after line 67:

float4 PS (vs2ps In): COLOR
{
float4 col = tex2D(Samp, In.TexCd) * cAmb;

col.rgb *= width;
col.rgb += center;

## return col; }

this might be a too easy start?!?
but thats similar to how i began with that.

in the patch.

0.5 is not the middle off every color spectrum, that is why I would like to calculate it.

I attached my Grey Shader, it has 2 ways off calculating grey, and a Brightness thingy.

For now I just copied/pasted the brightness, but is there any clever way not to do this? Realy hope so, because I want to add color balance and (if ever) contrast.

Grey.zip (13.3 kB)

Okay, reading this post I see:

``````float minVal = min(col.r, min(col.g, col.b));    //Min. value of RGB
float maxVal = max(col.r, max(col.g, col.b));    //Max. value of RGB
float delta = maxVal - minVal;
``````

Where could I have figured/read this (out) myself???

(still leaves me with the MEAN btw!)

Dunno if this will help but i’ve found this short formula to get grays : {CODE(ln=>1)}return(dot(col.rgb,0.33333).xxx).xxx));^

Grey.zip (14.4 kB)

Hehe, that looks like a cheap scanner, add that too. thnx :)

What does ((0.33333).xxx) mean???

I just can’t stand it I have no way to figure out some basic color info off my picture, because most filters are picture dependent for best result.

haha, perhaps xxx is the path to desaxismundis favourite picturefolder