We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm making this function for converting images to duotone. I'm close but I can't get the gradient (from color1 to color2 right). Also I would like to do this from color1 to transparent/alpha 0, if somebody has any idea. Thanks a LOT for any help!
A related script: http://codepen.io/72lions/pen/jPzLJX
// duotone script
color c1, c2;
void setup() {
size(800, 800, P2D);
colorMode(HSB, 255);
c1 = color(240, 14, 46);
c2 = color(25, 37, 80);
PImage pic=loadImage("<a href="http://jquery-custom-scrollbar.rocketmind.pl/images/lena.png" target="_blank" rel="nofollow">http://jquery-custom-scrollbar.rocketmind.pl/images/lena.png</a>");
image(duotone(pic, c1, c2), 0, 0);
}
PImage duotone(PImage img, color color1, color color2) {
img.resize(width, 0);
img.filter(GRAY);
color gradient[] = new color[256];
// Creates a gradient of 255 colors between color1 and color2
for (int d=0; d < 255; d++) {
float ratio= float(d)*0.00392156862745;
gradient[d]=lerpColor(color1,color2,ratio);
}
loadPixels();
for (int y = 0; y < img.height; y++) {
for (int x = 0; x < img.width; x++) {
int loc = x + y*img.width;
// get the brightness
float br = brightness(img.pixels[loc]);
// The luminosity from 0 to 255 --this is necessary?
float luminosity = max(0, min(254, round((br * 254))));
// Set the pixel to a gradient with the level of brightness
img.pixels[loc] = gradient[int(br)];
//img.pixels[loc] = gradient[int(luminosity)]; // this won't work
}
}
updatePixels();
return(img);
}
Answers
Reposted from https://forum.processing.org/two/discussion/19476/monotone-duotone-image-filter
Please don't make duplicate posts for the same issue. If you have more up-to-date code, add it to the bottom of that thread.
Can we close this and continue there?