thanks, completely makes sense what you're saying. I changed the code to the following which did make it faster:
if you do execute the code please give me some feedback on it!
much appreciated
Robin
Quote:
PImage img;
int cellSize = 4;
int cols, rows;
int numPix;
int avgRed, avgGreen, avgBlue;
int brgtnss;
int factor = 40;
int f_red,f_green,f_blue;
float r,g,b,c_red,c_green,c_blue,c_r,c_g,c_b;
float d_red,d_green,d_blue,lerp_r,lerp_g,lerp_b;
void setup(){
img = loadImage("24.jpg"); // loads the Image
size(img.width, img.height);
colorMode(RGB, 255,255,255,100); // setting colormode
cols = width / cellSize;
rows = height / cellSize;
numPix = rows * cols;
}
void mousePressed(){
loop();
}
void draw (){
image(img,0,0);
for (int i = 0; i < cols ; i++) {
for (int j = 0; j < rows ; j++) {
int x = i*cellSize;
int y = j*cellSize;
int loc = x + y*width;
r = red(img.pixels[loc]);
g = green(img.pixels[loc]);
b = blue(img.pixels[loc]);
float PixelBrightness = brightness(img.pixels[loc]);
brgtnss += PixelBrightness;
avgRed += r;
avgGreen += g;
avgBlue += b;
if(i == cols);
noLoop();
}
}
avgRed = avgRed/numPix;
avgGreen = avgGreen/numPix;
avgBlue = avgBlue/numPix;
brgtnss = brgtnss/(factor*numPix);
// calculates the dominant color and returns a factor between 0.? and 1
if ((avgRed >= avgGreen)&&(avgRed >= avgBlue)) {
f_red = 1;
f_green = avgGreen/avgRed;
f_blue = avgBlue/avgRed;
} else if ((avgGreen >= avgRed)&&(avgGreen >= avgBlue)) {
f_red = avgRed/avgGreen;
f_green = 1;
f_blue = avgBlue/avgGreen;
} else if ((avgBlue >= avgRed)&&(avgBlue >= avgGreen)) {
f_red = avgRed/avgBlue;
f_green = avgGreen/avgBlue;
f_blue = 1;
}
color a = color(avgRed,avgGreen,avgBlue,100); // simple average calculation
c_red = brgtnss*avgRed;
c_green = brgtnss*avgGreen;
c_blue = brgtnss*avgBlue;
color b = color(c_red,c_green,c_blue,100); // brightness augmented color
c_r = f_red*255;
c_g = f_green*255;
c_b = f_blue*255;
// dominant color is boosted to 100 percent
d_red = brgtnss*c_r;
d_green = brgtnss*c_g;
d_blue = brgtnss*c_b;
color c = color(d_red,d_green,d_blue,100);
// dominant color (66%) and
// brightness augmented color (33%) calcualtions are put together.
color d = lerpColor(b,c,0.33);
lerp_r = red(d);
lerp_g = green(d);
lerp_b = blue(d);
float m = millis();
println(brgtnss + " " + lerp_r + " : " + lerp_g + " : " + lerp_b + " | " + m + " msecs since start");
fill(a);
stroke(0);
rect (10,10,100,60);
fill(b);
rect (10,80,50,20);
fill(c);
rect (60,80,50,20);
fill(d);
rect (10,110,100,100);
}