图像的高斯混合

发布于 2024-10-15 16:56:57 字数 194 浏览 6 评论 0原文

我正在编写一个 iPhone 应用程序,需要帮助来弄清楚如何拍摄图像并将其混合成单一颜色。我认为我需要进行高斯混合,但不确定这是否正确或如何进行。

您有任何建议,指向示例高斯混合代码片段的指针,还是我从图像到混合颜色图像的方向错误?

我似乎无法使用现有的 iPhone 框架来做到这一点,或者公共框架中是否有私有方法可以使这项工作变得更容易?

I'm writing an iPhone app and need help in figuring out how to take an image and blend it into a single color. I assume I need to do a gaussian blend but am not sure if this is correct or how to do it if it is.

Do you have any suggestions, pointers to sample gaussian blend code snippets, or am I heading in the wrong directions to get from image to blended color image?

It doesn't appear I can do this with existing iPhone frameworks or are there private methods in public frameworks that will make this job easier?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

原谅我要高飞 2024-10-22 16:56:58

所以你想要拍摄一张图像并将其“混合成单一颜色”。您是否想获得图像的“平均颜色”?

如果是这样,使用高斯滤波器可能会使其过于复杂,因为您需要的输出只是单个 RGB 值。最简单的方法是计算每个颜色通道(红色、绿色和蓝色)的平均值:

int r,g,b;
r=g=b=0;

for (y=0 ; y<image_height ; y++)
    for (x=0 ; x<image_width ; x++)
    {
        r = r + image[y,x,0];
        g = g + image[y,x,1];
        b = b + image[y,x,2];
    }

num_pixels = image_height * image_width;
average_r = r / num_pixels;
average_g = g / num_pixels;
average_b = b / num_pixels;

高斯滤波器是中心加权滤波器,这意味着过滤中心的像素窗口的权重比其他窗口重。如果您想要模糊图像,那么这是合适的,但对于混合整个图像,对所有像素进行同等加权(如上面的伪代码所示)同​​样有效。

So you want to take an image and "blend it into a single color". Are you trying to get the 'average color' for the image?

If so, using a Gaussian filter is perhaps overcomplicating it, since the output you require is simply a single RGB value. The easiest way to do this is to compute the average for each color channel (red, green and blue):

int r,g,b;
r=g=b=0;

for (y=0 ; y<image_height ; y++)
    for (x=0 ; x<image_width ; x++)
    {
        r = r + image[y,x,0];
        g = g + image[y,x,1];
        b = b + image[y,x,2];
    }

num_pixels = image_height * image_width;
average_r = r / num_pixels;
average_g = g / num_pixels;
average_b = b / num_pixels;

A Gaussian filter is a center-weighted filter, meaning that the pixel in the center of the filtering window is weighted more heavily than the others. If you want to blur an image, then this is appropriate, but for blending an entire image, equally weighting all pixels, as in the pseudo-code above, is just as effective.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文