java - I am getting an array out of bound exception for this piece of code -
public compressimage(){ } // compress image method public static short[] compress(short image[][]){ // image dimensions int imagelength = image.length; // row length int imagewidth = image[0].length; // column length // convert vertical horizontal // store transposed image short[][] transposeimage = new short[imagewidth][imagelength]; // rotate +90 (int = 0; < imagewidth; i++) { (int j = 0; j < imagelength; j++) { short temp = image[i][j]; transposeimage[i][j] = image[j][i]; transposeimage[j][i] = temp; } }
short temp = image[i][j]; transposeimage[i][j] = image[j][i]; transposeimage[j][i] = temp;
why swapping here? doesn't make sense - transposeimage
new matrix, don't have inplace editing. guaranteed break if imagewidth != imagelength
- see if can figure out why.
and, actually, you're not swapping. 3 lines above equivalent to:
transposeimage[i][j] = image[j][i]; transposeimage[j][i] = image[i][j];
the body of nested loop should be:
transposeimage[i][j] = image[j][i];
Comments
Post a Comment