Archive: Color mod code snippets


11th June 2006 12:24 UTC

Color mod code snippets
this thread should provide examples of code for the color mod.ape.


Per channel color reduction
init:
colred=[any value between 1 and 256]
colgreen=[any value between 1 and 256]
colblue=[any value between 1 and 256]

channel:
red=floor(red*colred)/(colred-1);
green=floor(green*colgreen)/(colgreen-1);
blue=floor(blue*colblue)/(colblue-1);


11th June 2006 23:18 UTC

tip for many simple conversions in the CMF:
define red channel, and then assign 'red' to the other two channels.

a multiplier x3 can be just:

red = red*3;
blue = red;
green = red;

and it will be the same like
red = red*3;
blue = blue*3;
green = green*3;

since the r,b and g values are equal each time [256 times that is] the level box is evaluated.

color edge [a greyscale image needed for a 1-bit/b&w color result]:
red = above(red,.5);
blue = red;
green = red;


brighten image without clipping colors [middle tones brightness]:
red = pow(red,x); // 0<x<1, the smaller the brighter
blue = red;
green = red;

12th June 2006 07:33 UTC

Intensify colors by multiplying a channel with 1+value and then subtract that same value.

ie.
value=0.5 ;
red=red*(1+value)-value ;

And so on for the rest of the channels. You can also use it in reverse (make the value a - one to get less intense colors all the way up where everything is just white)


12th June 2006 13:24 UTC

I'm going to be pedantic and point out some of the correct terminology because people are using the wrong words:

Brightness is an additive equation
e.g. red = red + 0.1
blue = blue + (-0.5)

Contrast is a multiplicative equation
e.g. red = red * 1.1
blue = blue * 0.9


Gamma is an exponential equation
e.g. red = pow(red,3)
blue = pow(blue,0.9)

Intensity is an energy measurement (energy flux/time) but it doesnt mean very much on computers. The closest actual image processing term is 'luminence' (as in Hue, Saturation and) Tuggs example is a contrast adjustment followed by a brightness reduction


12th June 2006 13:39 UTC

And it makes the colors more intense.


12th June 2006 17:34 UTC

I think it makes them more rubbery


12th June 2006 17:49 UTC

gradiation curve
this allows you to increase the contrast in middle tone or dark and bright areas.
linear curve:
http://img150.imageshack.us/img150/9...near5ai.th.jpg
curve with increased midtone contrast:
http://img297.imageshack.us/img297/8...rves8bn.th.jpg
init or frame: midcon=[-1,1] //0=>no changes
//below 0=> low contrast in midtones
//above 0=> high contrast in midtones
someval=pow(8,-midcon);

channel: red=0.5*pow(abs(2*red-1),someval)*sign(2*red-1)+0.5;


12th June 2006 18:34 UTC

Time independent fadeout effect. The line on frame, "f=pow(.8,30*dt);" sets the speed and curve of the fadeout, tweak the values of .8 between 0..1 and the 30 between 0..+inf to see how to use it...

init:
lasttime=gettime(0);

frame:
t=gettime(0);dt=t-lasttime;lasttime=t;
f=pow(.8,30*dt);

level:
red=red*f;
blue=red;
green=red;


12th June 2006 18:57 UTC

here is a example of my midtone contrast color mod


12th June 2006 21:20 UTC

custom chrome effect triangle wave like
init: nc=[1-256 number of cycles]

level: someval=floor(red*nc);
red=if(someval%2,1-(red*nc-someval),(red*nc-someval));

custom chrome effect sine wave like
init: nc=[1-256 number of cycles]
channel: red=0.5-0.5*cos(red*$pi*nc);