import imageadjuster.*;
/**
Illustrates using the very low-level LUT routines to accomplish a "sigmoid" adjustment.
A Sigmoid function is an "S" -shaped curve with a number of specific properties. However,
for the purposes here it is sufficient to think of it as a double-sided "gamma" adjustment.
It can be used to simultaneously decrease the "gamma" of darker pixels, while increasing the
"gamma" of lighter pixels.
*/
size(200,200);
background(loadImage("milan_rubbish.jpg"));
ImageAdjuster adjust = new ImageAdjuster(this);
// create a custom lookup table
float [] mylut = new float[256];
// populate the lookup table with sigmoid values
float k = 6f; // a "squeeze" factor to compress the log scale into desired range
for (int i=0; i<256; i++) {
float t = (float)(i) / 127.5f - 1f;
mylut[i] = (1f / (1f + exp(-t*k))) * 255f;
}
// tell the adjuster to use custom lookup table
adjust.setLUT(mylut);
// perform the adjustment
adjust.apply(g);
// and plot the curve also
// input values are shown along the x-axis, output values along the y-axis
stroke(255);
for (int x=0; x<200; x++) {
int y = (int)(mylut[x*255/200] * 200f / 255f); // would be simpler with a 256x256 image! :-D
point(x, height-1-y);
}