帮助一个像素算法背后的理论? [英] Help with the theory behind a pixelate algorithm?

查看:168
本文介绍了帮助一个像素算法背后的理论?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以说,我有一个图像,我想像素化。我想要这个清晰的图像表示的网格,例如,100×100正方形。因此,如果原始照片是500像素X 500像素,每个正方形是5像素X 5像素。所以每个正方形都会有一个颜色对应于它交换的像素的5像素X 5像素组...



我如何弄清楚这一种颜色,这是最好的代表的东西,它覆盖,是?我只是把R G和B数字的25个像素的每一个,并平均他们?或者有一些不清楚的其他方式我应该知道吗?

解决方案

如果你想知道理论的像素化,在重采样(特别是下采样)上读。像素化算法只是简单地对图像进行下采样(使用一些下采样方法),然后使用最近邻居插值法对其进行上采样。注意,在代码中,这两个步骤可以融合成一个。



对于下采样,一般来说,通过 n 首先由适当的低通滤波器滤波,然后取出每个 n 中的一个采样。要使用的理想过滤器是 sinc筛选器,但由于实施它的问题, Lanczos过滤器通常用作紧密的选择。



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



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

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?

解决方案

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.

这篇关于帮助一个像素算法背后的理论?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆