这是我的代码生成的输出和输入图像:https://imgur.com/a/mT7YqCD
以下代码用于模糊功能,pset4中未涉及所有支持代码。
void blur(int height, int width, RGBTRIPLE image[height] [width])
{
RGBTRIPLE newImage[height][width];
for (int h = 0; h < height; h++)
{
for (int w = 0; w < width; w++)
{
BYTE redAvg = 0;
BYTE greenAvg = 0;
BYTE blueAvg = 0;
BYTE count = 0;
for (int y = -1; y <= 1; y++)
{
for (int x = -1; x <= 1; x++)
{
int h_1 = h + y;
int w_1 = w + x;
if (h_1 >= 0 && h_1 < height && w_1 >= 0 && w_1 < width)
{
count++;
redAvg += image[h_1][w_1].rgbtRed;
greenAvg += image[h_1][w_1].rgbtGreen;
blueAvg += image[h_1][w_1].rgbtBlue;
}
}
}
newImage[h][w].rgbtRed = redAvg/count;
newImage[h][w].rgbtGreen = greenAvg/count;
newImage[h][w].rgbtBlue = blueAvg/count;
}
}
for (int x = 0; x < height; x++)
{
for (int y = 0; y <width; y++)
{
image[x][y] = newImage[x][y];
}
}
return;
}