我该怎么做一个图像的高品质缩放? [英] How do I do high quality scaling of a image?

查看:195
本文介绍了我该怎么做一个图像的高品质缩放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一些code扩展在C / C 32位的RGBA图像++。我写了已经有些成功的一些尝试,但他们慢,最重要的是大小的图像质量是不能接受的。我比较了OpenGL的比例相同的图像(即我的视频卡)和我的例行和它的质量除了远的。我有谷歌code搜查,冲刷的事情我认为会提供一些​​线索(SDL,快板,wxWidgets的,CxImage的,GD,ImageMagick的,等等),但源代码树通常是他们code要么是令人费解和散在地方或充满了汇编,很少或没有意见。我也看到了维基百科上的多篇文章和其他地方,而我只是没有找到什么,我需要一个明确的解释。我理解插值和采样的基本概念,但我挣扎着爬了算法的权利。我不想依靠外部库一个常规,必须把它们转换成图像格式和背部。此外,我想知道怎么反正做我自己。 :)

I'm writing some code to scale a 32 bit RGBA image in C/C++. I have written a few attempts that have been somewhat successful, but they're slow and most importantly the quality of the sized image is not acceptable. I compared the same image scaled by OpenGL (i.e. my video card) and my routine and it's miles apart in quality. I've Google Code Searched, scoured source trees of anything I thought would shed some light (SDL, Allegro, wxWidgets, CxImage, GD, ImageMagick, etc.) but usually their code is either convoluted and scattered all over the place or riddled with assembler and little or no comments. I've also read multiple articles on Wikipedia and elsewhere, and I'm just not finding a clear explanation of what I need. I understand the basic concepts of interpolation and sampling, but I'm struggling to get the algorithm right. I do NOT want to rely on an external library for one routine and have to convert to their image format and back. Besides, I'd like to know how to do it myself anyway. :)

我看到之前堆栈溢出问过类似的问题,但它是不是真的这样回答了,但我希望有一个人在那里谁可以帮我轻推在正确的方向。也许我指向一些文章或伪code ...任何帮助我学习和做的。

I have seen a similar question asked on stack overflow before, but it wasn't really answered in this way, but I'm hoping there's someone out there who can help nudge me in the right direction. Maybe point me to some articles or pseudo code... anything to help me learn and do.

下面就是我在寻找:
1.没有汇编(我写非常便携code多种类型的处理器)。
2.外部库没有依赖关系。
3.我主要关注的缩减,但也将需要在以后写一个规模例程。
4.结果和算法的清晰度的质量是最重要的(以后可以优化它)。

Here's what I'm looking for: 1. No assembler (I'm writing very portable code for multiple processor types). 2. No dependencies on external libraries. 3. I am primarily concerned with scaling DOWN, but will also need to write a scale up routine later. 4. Quality of the result and clarity of the algorithm is most important (I can optimize it later).

我的日常主要采用以下形式:
DrawScaled(UINT32 * SRC,UINT32 * DST,从src_x,src_y,src_w,src_h,dst_x,dst_y,dst_w,dst_h);

My routine essentially takes the following form: DrawScaled( uint32 *src, uint32 *dst, src_x, src_y, src_w, src_h, dst_x, dst_y, dst_w, dst_h );

谢谢!

更新:为了澄清,我需要的东西比一箱重采样的降尺度模糊其形象太先进得多。我怀疑我要的是某种形式的双三次(或其他)过滤器是有点相反,以双三次倍增算法(即每个目标像素从所有贡献源像素,保持事物尖锐加权算法相结合来计算。

UPDATE: To clarify, I need something more advanced than a box resample for downscaling which blurs the image too much. I suspect what I want is some kind of bicubic (or other) filter that is somewhat the reverse to a bicubic upscaling algorithm (i.e. each destination pixel is computed from all contributing source pixels combined with a weighting algorithm that keeps things sharp.

例子:
下面就是我从wxWidgets的BoxResample算法与获得的一个例子,我想在一个256x256的位图缩放到55x55。什么

EXAMPLE: Here's an example of what I'm getting from the wxWidgets BoxResample algorithm vs. what I want on a 256x256 bitmap scaled to 55x55.

最后:原来的256×256图像

推荐答案

现在,我看到你的原始图像,我认为这是OpenGL的使用最近邻算法。它不仅是最简单的方式来调整,但它也是最快的。唯一的缺点是,它看起来很粗糙,如果有在原始图像的任何细节。

Now that I see your original image, I think that OpenGL is using a nearest neighbor algorithm. Not only is it the simplest possible way to resize, but it's also the quickest. The only downside is that it looks very rough if there's any detail in your original image.

这个想法是从原始图像采取均匀分布的样本;你的情况,55出256,或者一个每4.6545的。刚轮数,以获得像素选择。

The idea is to take evenly spaced samples from your original image; in your case, 55 out of 256, or one out of every 4.6545. Just round the number to get the pixel to choose.

这篇关于我该怎么做一个图像的高品质缩放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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