如何选择图像插值方法? (Emgu/OpenCV)
Emgu(OpenCV 的 .net 包装器)提供的图像大小调整功能可以使用 四种插值方法中的任何一种:
- CV_INTER_NN(默认)
- CV_INTER_LINEAR
- CV_INTER_CUBIC
- CV_INTER_AREA
我大致了解线性插值,但只能猜测三次或面积的作用。我怀疑 NN 代表最近邻,但我可能是错的。
我调整图像大小的原因是为了减少像素数量(它们将在某个时刻迭代),同时保持它们的代表性。我提到这一点是因为在我看来插值是实现此目的的核心 - 因此获得正确的类型应该非常重要。
那么我的问题是,每种插值方法的优缺点是什么?它们有何不同以及我应该使用哪一个?
The image resizing function provided by Emgu (a .net wrapper for OpenCV) can use any one of four interpolation methods:
- CV_INTER_NN (default)
- CV_INTER_LINEAR
- CV_INTER_CUBIC
- CV_INTER_AREA
I roughly understand linear interpolation, but can only guess what cubic or area do. I suspect NN stands for nearest neighbour, but I could be wrong.
The reason I'm resizing an image is to reduce the amount of pixels (they will be iterated over at some point) whilst keeping them representative. I mention this because it seems to me that interpolation is central to this purpose - getting the right type ought therefore be quite important.
My question then, is what are the pros and cons of each interpolation method? How do they differ and which one should I use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最近的邻居将尽可能快,但在调整大小时您将丢失大量信息。
线性插值速度较慢,但不会导致信息丢失,除非您缩小图像(实际上就是这样)。
三次插值(可能实际上是“双三次”)使用合并多个相邻像素的许多可能公式之一。这对于缩小图像来说要好得多,但在不丢失信息的情况下可以缩小多少仍然受到限制。根据算法的不同,您可能可以将图像缩小 50% 或 75%。这种方法的主要缺点是速度慢得多。
不确定“面积”是什么 - 它实际上可能是“双三次”。很可能,此设置将为您提供最佳结果(就信息丢失/外观而言),但代价是最长的处理时间。
更新:此链接提供了更多详细信息(包括列表中未包含的第五种类型):
http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html?highlight=resize#resize
Nearest neighbor will be as fast as possible, but you will lose substantial information when resizing.
Linear interpolation is less fast, but will not result in information loss unless you're shrinking the image (which you are).
Cubic interpolation (probably actually "Bicubic") uses one of many possible formulas that incorporate multiple neighbor pixels. This is much better for shrinking images, but you are still limited as to how much shrinking you can do without information loss. Depending on the algorithm, you can probably reduce your images by 50% or 75%. The primary con of this approach is that it is much slower.
Not sure what "area" is - it may actually be "Bicubic". In all likelihood, this setting will give your best result (in terms of information loss / appearance), but at the cost of the longest processing time.
Update: this link gives more details (including a fifth type not included in your list):
http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html?highlight=resize#resize
这些算法是:(描述来自 OpenCV 文档)
如果您想要更快的速度,请使用最近邻方法。
如果您想在下采样后保持图像质量,可以考虑使用基于 INTER_AREA 的插值,但这又取决于图像内容。
可以找到速度比较的详细分析 此处
下面是从上述链接获取的 400*400 px 图像的速度比较
The algorithms are: (descriptions are from the OpenCV documentation)
If you want more speed use Nearest Neighbor method.
If you want to preserve quality of Image after downsampling, you can consider using INTER_AREA based interpolation, but again it depends on image content.
You can find detailed analysis of speed comparison here
Below is the speed comparison on 400*400 px image taken from the above link
使用的插值方法取决于您想要实现的目标:
CV_INTER_LINEAR 或 CV_INTER_CUBIC 应用低通滤波器(平均)以实现视觉质量和边缘去除(低通滤波器倾向于去除边缘以减少图像中的锯齿)。在这两者之间,我建议您CV_INTER_CUBIC。
CV_INTER_NN 方法实际上是最近邻方法,它是最基本的方法,您将获得更清晰的边缘(不会应用低通滤波器)。然而这种方法只是简单地“缩放”图像,并没有视觉增强。
The interpolation method to use depends on what you are trying to achieve:
CV_INTER_LINEAR or CV_INTER_CUBIC apply a lowpass filter (average) in order to achieve a trade-off between visual quality and edge removal (lowpass filters tend to remove edges in order to reduce aliasing in images). Between these two, i'd recommend you CV_INTER_CUBIC.
CV_INTER_NN method actually is Nearest neighbour, it's the most basic method and you'll get sharper edges (no lowpass filter will be applied). However this method simply is like "zooming" the image, no visual enhancement.
它们都会丢失信息,您使用哪种信息取决于您需要的速度、您可以承受丢失多少信息以及图像的性质。
抱歉,没有正确答案 - 这就是为什么有一个选择
They all lose information, which you use depends on the speed you need, how much information you can afford to lose and the nature of your image.
Sorry there is no correct answer - that's why there is a choice