开发者

What algorithms to use for image downsizing?

开发者 https://www.devze.com 2023-01-04 10:04 出处:网络
What algorithms to use for image downsizing? What is faster? What algorithm is performed for image resizing ( specially downsizing from big 600x600 tosuper small 开发者_如何学JAVA6x6 for example) by

What algorithms to use for image downsizing?

What is faster?

What algorithm is performed for image resizing ( specially downsizing from big 600x600 to super small 开发者_如何学JAVA6x6 for example) by such giants as flash and silver player, and html5?


Bilinear is the most widely used method and can be made to run about as fast as the nearest neighbor down-sampling algorithm, which is the fastest but least accurate.

The trouble with a naive implementation of bilinear sampling is that if you use it to reduce an image by more than half, then you can run into aliasing artifacts similar to what you would encounter with nearest neighbor. The solution to this is to use an pyramid based approach. Basically if you want to reduce 600x600 to 30x30, you first reduce to 300x300, then 150x150, then 75x75, then 38x38, and only then use bilinear to reduce to 30x30.

When reducing an image by half, the bilinear sampling algorithm becomes much simpler. Basically for each alternating row and column of pixels:

y[i/2][j/2] = (x[i][j] + x[i+1][j] + x[i][j+1] + x[i+1][j+1]) / 4;


There is an excellent article at The Code Project showing the effects of various image filters.

For shrinking an image I suggest the bicubic algorithm; this has a natural sharpening effect, so detail in the image is retained at smaller sizes.


There's one special case: downsizing JPG's by more than a factor of 8. A direct factor of 8 rescale can be done on the raw JPG data, without decompressing it. JPG's are stored as compressed blocks of 8x8 pixels, with the average pixel value first. As a result, it typically takes more time to read the file from disk or the network than it takes to downscale it.


Normally I would stick to a bilinear filter for scaling down. For resizing images to tiny sizes, though, you may be out of luck. Most icons are pixel-edited by hand to make them look their best.

Here is a good resource which explains the concepts quite well.

0

精彩评论

暂无评论...
验证码 换一张
取 消