Problem with Retrieving red(), green(), or blue() on an Array of PImages

I am trying to create an image texture analyzer by progressively blurring an image and finding the difference between the pixels at different stages of blurring. I had this working when I was using individual PImages but when I tried using an array of PImages, my code broke. The error I am receiving is, "the function "red()" expects parameters like: red(int)". Here is my code.

PImage[] pic, difference;
int levels = 3;

void setup(){

  size(displayWidth, displayHeight);
  background(0);

  //setup image arrays

  pic = new PImage[levels + 1];
  difference = new PImage[levels];

  //load image to be analyzed
  pic[0] = loadImage("swamptrees.jpg");
  pic[0].loadPixels();

  //setup individual color variables
  float r, g, b;

  //blur each image and find the diffence from previous level of blur
  for (int i = 0 ; i < levels ; i ++){

    //create and blur this level
    pic[i + 1] = createImage(pic[0].width, pic[0].height, RGB);
    pic[i + 1] = pic[0].get();
    pic[i + 1].filter(BLUR, pow(2, i));
    pic[i + 1].loadPixels();

    //create and calculate the difference
    difference[i] = createImage(pic[0].width, pic[0].height, RGB);
    difference[i].loadPixels();

    for (int j = 0 ; j < pic[0].pixels.length ; j++){

      r = abs(red(pic[i].pixels[j] - red(pic[i + 1].pixels[j])));
      g = abs(green(pic[i].pixels[j] - green(pic[i + 1].pixels[j])));
      b = abs(blue(pic[i].pixels[j] - blue(pic[i + 1].pixels[j])));

      difference[i].pixels[j] = color(r, g, b);

    }

  }

  pic[0].updatePixels();

  for (int i = 0 ; i < levels ; i++){

    pic[i + 1].updatePixels();
    difference[i].updatePixels();

  }

}

void draw(){

  image(pic[0], 0, 0, width/4, height/4);

  for (int i = 0 ; i < levels ; i ++){

    image(pic[i + 1], 0, (height / 4) * (i + 1), width / 4, (height / 4) * (i + 2));
    image(difference[i + 1], width / 4, (height / 4) * (i + 1), width / 2, (height / 4) * (i + 2));

  }

}
Tagged:

Answers

  • edited August 2016 Answer ✓

    Check your closing brackets on lines 36, 37, 38

  • Yep, that worked. Thanks a bunch.

  • cool. to be a bit more explicit now i'm not typing on my phone:

    r = abs(red(pic[i].pixels[j] - red(pic[i + 1].pixels[j])));
    

    should be

    r = abs(red(pic[i].pixels[j]) - red(pic[i + 1].pixels[j]));
    

    etc

Sign In or Register to comment.