Hi,
I'm new to processing and still trying to wrap my head around the language. I'll have to admit, with only some experience using PHP, processing and OOP are a little intimidating.
I'm trying to develop a program that does as follows:
- Reads a directory of .jpegs from a local disk ( 0001.jpeg, 0002.jpeg etc.)
- Averages the color within each image
- Creates a "duplicate" for each image, using only the averaged color from the source image. (a one color jpeg)
- Writes each new image to a different directory or sub-directory with incremental naming.
I've been plowing through the forums and handbook, finding several examples that seem to work for each stage, but I'm having trouble understanding how to patch everything together into one program.
For the averaging process I've been using Huskee's code from http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1203885612;start=10#10
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("wgreen.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 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 average = color(avgRed,avgGreen,avgBlue,100); // simple average calculation
c_red = brgtnss*avgRed;
c_green = brgtnss*avgGreen;
c_blue = brgtnss*avgBlue;
float m = millis(); // performance
println(brgtnss + " " + lerp_r + " : " + lerp_g + " : " + lerp_b + " | " + m + " msecs since start");
fill(average);
stroke(0);
rect (10,10,100,60);
}
Can anyone point me in the right direction?
Any help would be wonderful.
Rob