Bug 1275 : ArrayIndexOutOfBoundsException when trying to adapt histogram example
Last modified: 2009-06-12 04:32




Status:
RESOLVED
Resolution:
INVALID -
Priority:
P2
Severity:
normal

 

Reporter:
sbrower
Assigned To:
fry

Attachment Type Created Size Actions

Description:   Opened: 2009-06-12 04:27
In attempting to adapt the Histogram basic tutorial, I keep getting this
error code, no matter what size or what image I replace the originals with.
I searched for bugs and found several in this database that sound similar
but they have all been 'resolved'. But I'm not sure how to resolve this
for myself. Below is the code as I've changed it, which is only different
in image size and the image itself. I've tried to make the size the same,
larger and smaller in turn, and have also tried different images but always
get the same error. The error refers always to whatever size I have
entered, and always the larger of the two if they are different.
mac os 10.4.11, powerpc g4, processing 1.0.5


size(200, 200);
colorMode(RGB, width);

int[] hist = new int[width];

// Load an image from the data directory
// Load a different image by modifying the comments
PImage a;
a = loadImage("moranTest.jpg");
image(a, 0, 0);

// Calculate the histogram
for (int i=0; i<width; i++) {
for (int j=0; j<height; j++) {
hist[int(red(get(i, j)))]++;
}
}

// Find the largest value in the histogram
float maxval = 0;
for (int i=0; i<width; i++) {
if(hist[i] > maxval) {
maxval = hist[i];
}
}

// Normalize the histogram to values between 0 and "height"
for (int i=0; i<width; i++) {
hist[i] = int(hist[i]/maxval * height);
}

// Draw half of the histogram (skip every second value)
stroke(width);
for (int i=0; i<width; i+=2) {
line(i, height, i, height-hist[i]);
}
ArrayIndexOutOfBoundsException: 200
Additional Comment #1 From fry 2009-06-12 04:32
that's a programming error, not a processing bug. you can get help on the
discourse board.