I have fifty aerial images stored in an array, in a Processing script (.pde).
I want to calculate the amount of 'green' in each pixel of each image, based on RGB colour space, to compare against a separate, target image. The aim is to find which of the fifty images in the array are most similar to the target image (they are aerial images of urban and rural environments). I am basing this comparison on the green RGB value of each pixel.
The code I have written so far loads the target and comparison images - using PImage
- and calculates the amount of 'green' in each pixel for each image, using a green
method. The outputs in draw
are just for me to visualise the process as I'm working through it:
//declare variables for outputting images
PImage p,p1;
//declare test image array
PImage [] q;
//declare naming convention for images
String pre = "Image_";
void setup(){
size(850,800);
p = loadImage("LDN.jpg");
p.resize(width/2, height/2);
p1 = green(p);
//load array of comparison images
q = new PImage[51];
for(int i = 1; i<q.length; i++)
{
q[i]=loadImage(pre+(i) + ".jpg");
}
//calculate green value of every pixel in every comparison image in the the array
for(int j=1; j<q.length; j++)
{
q[j].resize(width/2, height/2);
q[j] = green(q[j]);
}
}
void draw(){
image(p,0,0);
image(p1,0,height/2);
image(q[13],width/2,0);
image(q[37],width/2,height/2);
}
PImage green(PImage pin)
{
pin.loadPixels();
PImage pout = createImage(pin.width, pin.height, RGB);
pout.loadPixels();
for(int i = 0; i<pout.pixels.length; i++)
{
pout.pixels[i] = color(0, green(pin.pixels[i]),0);
}
pout.updatePixels();
return pout;
}
I've not found anything on the Processing help pages or wider discourse that suggests approaches for storing these values for comparison. Ideally I would like to compare them later using the Manhattan
or chamfer
distance comparators (if I use edge detection).