0

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).

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
the_bonze
  • 325
  • 1
  • 4
  • 11
  • I'm not really sure what you're asking. You can store them in whatever data structure you want. Maybe a 2D array? – Kevin Workman Jan 04 '18 at 17:23
  • @KevinWorkman - what I need to do is compare the amount of green in each pixel of a given image with the amount of green in the corresponding pixel of the target image - Processing (and coding generally) is new to me, so apologies if I'm not explaining the technicalities very well. – the_bonze Jan 04 '18 at 17:59

1 Answers1

0

The best thing I can tell you to do is to break your problem down into smaller pieces and take those pieces on one at a time.

For example, instead of working with 20 images, focus on getting something working for a single image. Write down a list of steps you want to follow, in English, before you think about implementing those steps in code.

There are ton of different ways you could approach this, but how I might approach it is as follows:

  • For an image, loop over its pixels.
  • For each pixel, get its green value.
  • Add that green value to a 2D array.
  • Maybe then take the total of that 2D array, or maybe the average?

From there, then you can start thinking about code. To loop over pixels, I would use the get() function, which takes an X and Y parameter. Or you could use the pixels array.

Write a function that takes a PImage argument and returns a data structure of green values: a 2D array, or a 1D array, or an ArrayList, whatever. This part really depends on you want what you want to do with the data afterwards.

Get it working perfectly with a single image before you think about multiple images. Good luck.

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107