注:これまでに試したこと、または試みたことを示すことをお勧めします。通常、事前の試みのない一般的な未解決の質問は反対票を投じられます。あなたは初心者であり、画像処理が大好きなので、このコードを書き、このソリューションを投稿して、あなたが始めるのを助けることができませんでした.
Paulpro がコメントしたように、問題はローパス フィルターの実装です。与えられたデータ マトリックスでは、3 x 3 ウィンドウで平均化できるポイントを見つける必要があります。そのため、まずこれらのポイントを特定する方法について説明します。これらのポイントの識別を説明する以下のコメント付きのサンプル コードを見つけてください。
// Input Data
int input_array[4][4] = { {10, 11, 1, 4}, {5, 1, 6, 9}, {9, 0, 2, 7}, {7, 4, 9, 8}};
// To calculate the average
float sum ;
// Row counter, column counter, dimension of the square matrix
int row_ctr, col_ctr, array_dimension;
int row, col;
array_dimension = 4; // Initialization
// Run the loop for the entire array
for(row_ctr = 0; row_ctr < array_dimension; row_ctr++)
{
// If the current row's top neighbor is outside the boundary or
// the bottom neighbor is outside the boundary, PASS and continue with
// next row
if(((row_ctr - 1) < 0) || ((row_ctr + 1) >= array_dimension))
{
continue;
}
// Run the loop for array dimension
for(col_ctr = 0; col_ctr < array_dimension; col_ctr++)
{
// If the current column's left neighbor is outside the boundary or
// right neighbor is outside the boundary, PASS and continue with
// next column
if(((col_ctr - 1) < 0) || ((col_ctr + 1) >= array_dimension))
{
continue;
}
// Initialize sum to 0.0
sum = 0.0;
// Reset to Top Left corner by going (-1, -1) from current position
row = row_ctr - 1;
col = col_ctr - 1;
sum = input_array[(row+0)][col] +
input_array[(row+0)][(col+1)]+ input_array[(row+0)][(col+2)];
sum += input_array[(row+1)][col] +
input_array[(row+1)][(col+1)]+ input_array[(row+1)][(col+2)];
sum += input_array[(row+2)][col] +
input_array[(row+2)][(col+1)]+ input_array[(row+2)][(col+2)];
// Find the average
sum = sum / 9.0;
printf("Average being found for (%d, %d) is %6.2f\n", row_ctr, col_ctr, sum);
}
}
このコードを実行すると、出力は次のように表示されます。
Average being found for (1, 1) is 5.00
Average being found for (1, 2) is 4.56
Average being found for (2, 1) is 4.78
Average being found for (2, 2) is 5.11