为了平滑图像,我需要总结给定中心像素周围的所有像素,然后建立平均值,这基本上就是我的新像素。现在有两个问题:
1)总结它们的好方法是什么?和
2)我怎样才能最好地避免角落像素?
这是我到目前为止所做的,但我认为这没有什么好处。
for(i = 0; i < image1->nx; i++)
{
for(j = 0; j < image1->ny; j++)
{
if(i == 0 || j == 0 || i == image1->nx - 1 || j == image1->ny - 1)
{
image2->image[i][j] = image1->image[i][j];
}
else
{
int average = 0;
average += image1->image[i][j];
average += image1->image[i+1][j];
average += image1->image[i][j+1];
average += image1->image[i+1][j+1];
average += image1->image[i-1][j];
average += image1->image[i-1][j+1];
average += image1->image[i-1][j-1];
average += image1->image[i][j-1];
average += image1->image[i+1][j-1];
average /= 9;
image2->image[i][j] = average;
}
}
}
我在 C 中的结构是这样的:
struct pgm_image
{
int nx; // row number
int ny; // cell number
unsigned char image[N1][N2]; // image information
};