我正在尝试根据我正在遵循的教程来模糊图像。这是说明。
\n\n\n模糊 有多种方法可以创建模糊或软化图像的效果。对于这个问题,我们\xe2\x80\x99将使用\xe2\x80\x9cbox模糊,\xe2\x80\x9d的工作原理是获取每个像素,并针对每个颜色值,通过平均给它一个新的值。相邻像素的颜色值。
\n考虑以下像素网格,其中我们\xe2\x80\x99\n对每个像素进行了编号。
\n像素网格
\n每个像素的新值将是原始像素 1 行和列内的所有像素值的平均值(形成一个 3x3 框)。例如,像素 6\n的每个颜色值将通过对像素 1、\n2、3、5、6、7、9、10 和 11 的原始颜色值进行平均来获得(请注意,像素 6 本身也包括在内)平均)。同样,像素 11 的颜色值可以通过对像素 6、7、8、10、11、12、14、15 和 16 的颜色值进行平均来获得。
\n
\n\n\n
\n\n对于沿着边缘或角落的像素,例如像素 15,我们仍然\n查找 1 行和列内的所有像素:在本例中,为像素 10、\n11、12、14、15 和 16。```
\n
因此,为了解决这个问题,我想出了这个解决方案。
\nfor each row\n for each column\n add the pixel if upper left exists\n add the pixel if directly above exists\n add the pixel if upper right exists\n add the pixel if right exists\n add the …Run Code Online (Sandbox Code Playgroud) 我试图反射(水平翻转)图像,但我似乎不太明白为什么图像不反射并保持原始状态。我尝试了许多不同的方法(添加-1或[width - j]分配tempArrayasRGBTRIPLE tempArray;并width除以/2as 循环条件。
没有抛出任何错误,我已经遵循了 Stackoverflow 的解决方案,但似乎我还没有完全达到目标,有什么建议吗?
// Reflect image horizontally
void reflect(int height, int width, RGBTRIPLE image[height][width])
{
RGBTRIPLE tempArray[height][width];
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
tempArray[i][j] = image[i][j];
image[i][j] = image[i][width - j];
image[i][width - j] = tempArray[i][j];
}
}
return;
}
Run Code Online (Sandbox Code Playgroud)