ローカル ヒストグラムの均等化を行うために、ゼロが埋め込まれた 2D 配列からいくつかの行と列を読み取り、それらに対して何らかの処理を実行しようとしています。最初のステップで、元の配列 ( arr[][]
) をゼロで埋めて、正常に動作する場所に保存しますtemp_arr[][]
。temp_arr[][]
次に、毎回これから 3*3 配列を読み取り、それらを 3*3 配列に保存して処理を実行しようとします。ただし、部分的に結果が得られ、エラーが発生します。それが私のコードを実行した後に得られるものです:
000 012 045
000 123 456
000 230 560
00Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5 at lhe_test.main(lhe_test.java:28)
誰でも助けてもらえますか?
ここに私のコードがあります:
public class lhe_test {
public static int x=0 ;
public static double sum = 0;
public static double mn =0;
public static int [][] savedImage;
public static int row , col;
public static int [][] temp_tb= new int[ImagePro.pad][ImagePro.pad];
public static void main(String[] args) {
// TODO Auto-generated method stub
int [][] arr = {{1,2,3},
{4,5,6},{7,8,9},{10,11,12}};
ImagePro.pad = 3 ;
int temp_arr[][] = zero_pad(arr , ImagePro.pad);
int p = ImagePro.pad/2;
for (int i = 0 ; i < temp_arr[0].length -p ; i ++){
for (int j = 0 ; j< temp_arr.length - p ; j++){
for (int ii=0 ; ii< ImagePro.pad ; ii++){
for (int jj =0 ; jj<ImagePro.pad ; jj++){
int temp=temp_arr[ii+i][jj+j];
temp_tb[ii][jj]= temp;
System.out.print(temp_tb[ii][jj]);
}
System.out.println();
}
System.out.println();
}
}
}
public static int[][] zero_pad (int [][] imageData , int ratio){
int w = imageData[0].length +((ratio-1));
int h = imageData.length +((ratio-1));
int [][]temp = new int[h][w];
for (int i = 0 ; i<h ; i++){
for (int j =0 ; j<w ; j++){
temp[i][j]=0;
}
}
for (int k=0 ; k<imageData.length ; k++){
for (int l=0 ; l <imageData[0].length ; l++){
temp[k+(ratio-1)/2][l+(ratio-1)/2]= imageData[k][l];
}
}
return temp;
}
}