Anyone know why I get this error? Essentially this program displays an image, displays the histogram or the image. It then adjust each pixels brightness and once more displays the image and histogram with the adjusted values.
The error is:
The method drawHistogram(int[], int, int) is not applicable for arguments (PImage, int[]);
PImage rocks;
PImage rocksBrightened;
PImage rocks2;
int rockBytes[][];
int rockBrights[][];
void setup() {
rocks = loadImage("rocks.png");
size(rocks.width+256, rocks.height*2);
rocks2 = createGraphics(rocks.width, rocks.height, P2D);
rocks2.loadPixels();
int h = rocks.height;
size(rocks.width*2, rocks.height*2);
image(rocks, 0, 0);
rockBytes = new int[rocks.width][rocks.height];
rockBrights = new int[rocks.width][rocks.height];
for (int i = 0;i < rocks.width; i++) {
for (int j = 0; j < rocks.height; j++) {
rockBytes[i][j] = rocks.get(i, j);
}
}
for (int i = 0; i < rocks.width; i++) {
for (int j = 0; j < rocks.height; j++) {
rockBrights[i][j] = rocksBrightened.get(i, j);
}
}
drawHistogram(rocks, computeHistogram(rocks)); //THIS LINE CAUSES ERROR
brighten(rockBrights);
// makeImage(rocksBrightened, rockBrights);
image(rocksBrightened, 0, h);
}
void loadPixelArray(PImage anImage) {
anImage.loadPixels(); //load pixels into pixels[] array
}
int[] computeHistogram (PImage anImage) {
int histogram[] = new int[256];
for (int i = anImage.pixels.length-1; i >= 0; --i) {
int v = (int) brightness(anImage.pixels[i]);
histogram[v]++;
}
int maxV = 0;
for (int i = 0; i < 256; i++) {
maxV = max(maxV,histogram[i]);
}
for (int i = 0; i < 256; i++) {
histogram[i] = (int) (histogram[i]*100.0/maxV);
}
return histogram;
}
void brighten(int anyArray[][]) {
for (int i = rocks.pixels.length-1; i >= 0; --i) {
int v = rocks.pixels[i];
float br = brightness(v);
float r = constrain(br*-.004436+2.1308*red(v),0,255);
float g = constrain(br*-.004436+2.1308*green(v),0,255);
float b = constrain(br*-.004436+2.1308*blue(v),0,255);
rocks2.pixels[i] = color(r,g,b);
}
}
void drawHistogram(int histogram[], int x, int y) {
noStroke();
fill(0);
stroke(255);
rect(x, y, 256, 256);
for (int i = 0; i < 256; i++) {
line(x + i, y+256, x + i, y+256 - histogram[i]);
}
}
void makeImage(PImage anImage, int imgArray[][]) {
anImage.loadPixels();
for (int i = 0; i < imgArray.length; i++) {
for (int j = 0; j < imgArray[0].length; j++) {
int loc = i + j*imgArray.length;
set(i, j+100, color(imgArray[i][j]));
}
}
anImage.updatePixels();
}
Well, the error message says it all:
This means that you’re trying to call the method
drawHistogram(), which is declared asdrawHistogram(int[], int, int)(which means it takes an int array and two ints as arguments), but that you pass aPImageand an int array instead of the required arguments. That doesn’t make sense.It’s a bit like trying to stick a dollar bill into a machine accepting coins only: it doesn’t work.