so you want change the colors of the picture?
if you want quantify the color there must be a rule like
color name x = color(hx,sx,bx) range:
- hue from a to hx to b,
- saturation from c to sx to d,
- brightness from e to bx to f,
do you have that rule or math?
and that calc you need to do on each pix color?
import processing.video.*;
Capture video;
void setup() {
size(320, 240);
colorMode(HSB);
video = new Capture(this, width, height);
video.start();
}
void draw() {
if (video.available()) {
video.read();
//video.filter(POSTERIZE, 4);
//image(video, 0, 0); // show org or filtered picture
video.loadPixels();
int count = video.width * video.height;
for (int i = 0; i < count; i++) {
color c = video.pixels[i];
float h = hue(c);
float s = saturation(c);
float b = brightness(c);
if ( hprint ) println("i "+i+" h "+nf(h, 0, 1)+" s "+nf(s, 0, 1)+" b "+nf(b, 0, 1) );
// what is the RULE for a correct color?
video.pixels[i] = color(h, s, b);
}
updatePixels();
hprint = false;
image(video, 0, 0); // show mod picture
}
}
boolean hprint = false;
void keyPressed() {
if ( key == 'h' ) hprint = true;
}
a example for ranging math here with WEB SAFE COLORS
// https://processing.org/reference/filter_.html
// https://discourse.processing.org/t/changing-webcam-pixels-to-nearest-color-from-color-palette-array/14811
import processing.video.*;
Capture video;
void setup() {
size(160, 120);
//colorMode(HSB,100); // as we later change float to int this here is already POSTERIZE ( reduced color resolution )
video = new Capture(this, width, height);
video.start();
}
void draw() {
if (video.available()) {
video.read();
//video.filter(POSTERIZE, 4);
//image(video, 0, 0); // show org or filtered picture
video.loadPixels();
int count = video.width * video.height;
for (int i = 0; i < count; i++) {
color c = video.pixels[i];
int h = (int)hue(c);
int s = (int)saturation(c);
int br = (int)brightness(c);
int r = (int)red(c);
int g = (int)green(c);
int bl = (int)blue(c);
// what is the RULE for a correct color?
//h = h;
//s = s;
//br = br;
// test web safe quantification
int wr = websafe(r);
int wg = websafe(g);
int wbl = websafe(bl);
if ( hsbprint ) println("i "+i+" h "+h+" s "+s+" b "+br+" / r "+r+" g "+g+" b "+bl+" // websafe wr "+wr+" wg "+wg+" wbl "+wbl);
video.pixels[i] = color(wr, wg, wbl); //color(h, s, b);
}
updatePixels();
hsbprint = false;
image(video, 0, 0); // show mod picture
}
}
int websafe(int c) {
//https://www.rapidtables.com/web/color/Web_Safe.html
// c from 0 ..255 for r g bl / w in 6 steps for 255 step color space
int w = 0;
if ( c < 25 ) w = 0;
else if ( c < 75 ) w = 51;
else if ( c <125 ) w = 102;
else if ( c <175 ) w = 153;
else if ( c <225 ) w = 204;
else w = 255;
return w;
}
boolean hsbprint = false;
void keyPressed() {
if ( key == 'h' ) hsbprint = true;
}