2014-04-06 52 views
0
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; 
     } 
    } 

回答

0
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]; 
+0

但是,新的矩陣應該有transposeImage [J] [我以前的值],不是嗎? – Sooner

相關問題