帮助了解像素化算法背后的理论吗?

发布于 2024-09-29 19:41:05 字数 265 浏览 0 评论 0原文

假设我有一张想要“像素化”的图像。我想要这个由 100 x 100 方格网格表示的清晰图像。因此,如果原始照片为 500 px X 500 px,则每个正方形为 5 px X 5 px。因此,每个方块都有一个与它所交换的 5 px X 5 px 像素组相对应的颜色...

我如何找出最能代表它所覆盖的内容的这种颜色是什么?我是否只取 25 个像素中每个像素的 RG 和 B 数字并对其进行平均?或者还有一些我应该知道的晦涩的其他方式吗? “像素化”功能中通常使用什么,比如在 Photoshop 中?

So say I have an image that I want to "pixelate". I want this sharp image represented by a grid of, say, 100 x 100 squares. So if the original photo is 500 px X 500 px, each square is 5 px X 5 px. So each square would have a color corresponding to the 5 px X 5 px group of pixels it swaps in for...

How do I figure out what this one color, which is best representative of the stuff it covers, is? Do I just take the R G and B numbers for each of the 25 pixels and average them? Or is there some obscure other way I should know about? What is conventionally used in "pixelation" functions, say like in photoshop?

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

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

发布评论

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

评论(2

离鸿 2024-10-06 19:41:05

如果您想了解像素化的“理论”,请阅读重采样(特别是下采样)。像素化算法只是简单地对图像进行下采样(使用某种下采样方法),然后使用最近邻插值< /a>.请注意,在代码中,这两个步骤可以合并为一个。

对于一般的下采样,要按 n 因子下采样,首先使用适当的低通滤波器对图像进行滤波,然后从每个 n 中获取一个样本。使用的“理想”过滤器是 sinc 过滤器,但由于实现它的问题, Lanczos 过滤器 通常用作紧密的替代方案。

然而,对于进行像素化时的几乎所有目的,使用简单的 框模糊 应该可以正常工作,并且实施起来非常简单。这只是附近像素的平均值。

如果您不需要更改图像的输出大小,则这意味着您将图像划分为 k×k 像素的块(大的结果像素) ,然后将每个块中的所有像素替换为该块中像素的平均值。

If you want to know about the 'theory' of pixelation, read up on resampling (and downsampling in particular). Pixelation algorithms are simply downsampling an image (using some downsampling method) and then upsampling it using nearest-neighbour interpolation. Note that in code these two steps may be fused into one.

For downsampling in general, to downsample by a factor of n the image is first filtered by an appropriate low-pass filter, and then one sample out of every n is taken. An "ideal" filter to use is the sinc filter, but because of issues with implementing it, the Lanczos filter is often used as a close alternative.

However, for almost all purposes when doing pixelization, using a simple box blur should work fine, and is very simple to implement. This is just an average of nearby pixels.

If you don't need to change the output size of the image, then this means you divide the image into blocks (the big resulting pixels) which are k×k pixels, and then replace all the pixels in each block with the average value of the pixels in that block.

浮光之海 2024-10-06 19:41:05

当源网格和目标网格如此均匀地可分和对齐时,大多数算法都会给出相似的结果。如果网格是固定的,则采用简单平均值。

在其他情况下,特别是当大小调整很小的百分比时,质量差异非常明显。与简单平均值相比,最简单的增强是考虑目标像素区域中包含的像素值,对每个像素值进行加权。

有关更多算法,请查看多元插值

when the source and target grids are so evenly divisible and aligned, most algorigthms give similar results. if the grids are fixed, go for simple averages.

in other cases, especially when resizing by a small percentage, the quality difference is quite evident. the simplest enhancement over simple average is weighting each pixel value considering how much of it's contained in the target pixel's area.

for more algorithms, check multivariate interpolation

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