平均模糊蒙版会产生不同的结果
将每个像素乘以平均模糊掩模 *(1/9) 但结果完全不同。
PImage toAverageBlur(PImage a)
{
PImage aBlur = new PImage(a.width, a.height);
aBlur.loadPixels();
for(int i = 0; i < a.width; i++)
{
for(int j = 0; j < a.height; j++)
{
int pixelPosition = i*a.width + j;
int aPixel = ((a.pixels[pixelPosition] /9));
aBlur.pixels[pixelPosition] = color(aPixel);
}
}
aBlur.updatePixels();
return aBlur;
}
multiplying each pixel by the average blurring mask *(1/9) but the result is totally different.
PImage toAverageBlur(PImage a)
{
PImage aBlur = new PImage(a.width, a.height);
aBlur.loadPixels();
for(int i = 0; i < a.width; i++)
{
for(int j = 0; j < a.height; j++)
{
int pixelPosition = i*a.width + j;
int aPixel = ((a.pixels[pixelPosition] /9));
aBlur.pixels[pixelPosition] = color(aPixel);
}
}
aBlur.updatePixels();
return aBlur;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前,您没有应用平均滤镜,仅将图像缩放 1/9,这会使其更暗。您的术语很好,您正在尝试应用 3x3 移动平均值(或邻域平均值),也称为棚车过滤器。
对于每个像素 i,j,您需要取 (i-1,j-1)、(i-1,j)、(i-1,j+1)、(i,j-1)、 (i,j),(i,j+1),(i+1,j-1),(i+1,j),(i+1,j+1),然后除以 9(对于 3x3平均的)。为此,您不需要考虑图像边缘上的像素,这些像素没有 9 个邻居(例如,您从像素 (1,1) 开始)。输出图像每边都会小一个像素。或者,您可以镜像值以向输入图像添加一条额外的线,这将使输出图像与原始图像的大小相同。
有更有效的方法可以做到这一点,例如使用基于 FFT 的卷积;这些方法速度更快,因为它们不需要循环。
Currently, you are not applying an average filter, you are only scaling the image by a factor of 1/9, which would make it darker. Your terminology is good, you are trying to apply a 3x3 moving average (or neighbourhood average), also known as a boxcar filter.
For each pixel i,j, you need to take the sum of (i-1,j-1), (i-1,j), (i-1,j+1), (i,j-1), (i,j),(i,j+1),(i+1,j-1),(i+1,j),(i+1,j+1), then divide by 9 (for a 3x3 average). For this to work, you need to not consider the pixels on the image edge, which do not have 9 neighbours (so you start at pixel (1,1), for example). The output image will be a pixel smaller on each side. Alternatively, you can mirror values out to add an extra line to your input image which will make the output image the same size as the original.
There are more efficient ways of doing this, for example using FFT based convolution; these methods are faster because they don't require looping.