public CompressImage(){
}
// compress image method
public static short[] compress(short image[][]){
// get image dimensions
int imageLength = image.length; // row length
int imageWidth = image[0].length; // column length
// convert vertical to horizontal
// store transposed Image
short[][] transposeImage = new short[imageWidth][imageLength];
// rotate by +90
for (int i = 0; i < imageWidth; i++)
{
for (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;
你为什么要在这里交换? 这没有意义 - transposeImage
是一个新矩阵,因此您不必进行就地编辑。 如果imageWidth != imageLength
,这肯定会中断 - 看看你是否能找出原因。
而且,实际上,你甚至没有交换。 以上三行相当于:
transposeImage[i][j] = image[j][i];
transposeImage[j][i] = image[i][j];
嵌套的 for 循环的主体实际上应该只是:
transposeImage[i][j] = image[j][i];