このエラーが発生する理由を知っている人はいますか? 基本的に、このプログラムは画像を表示し、ヒストグラムまたは画像を表示します。次に、各ピクセルの明るさを調整し、調整された値で画像とヒストグラムをもう一度表示します。
エラーは次のとおりです。
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();
}