如何选择图像插值方法? (Emgu/OpenCV)

发布于 2024-09-06 14:22:34 字数 486 浏览 9 评论 0原文

Emgu(OpenCV 的 .net 包装器)提供的图像大小调整功能可以使用 四种插值方法中的任何一种

  1. CV_INTER_NN(默认)
  2. CV_INTER_LINEAR
  3. CV_INTER_CUBIC
  4. CV_INTER_AREA

我大致了解线性插值,但只能猜测三次或面积的作用。我怀疑 NN 代表最近邻,但我可能是错的。

我调整图像大小的原因是为了减少像素数量(它们将在某个时刻迭代),同时保持它们的代表性。我提到这一点是因为在我看来插值是实现此目的的核心 - 因此获得正确的类型应该非常重要。

那么我的问题是,每种插值方法的优缺点是什么?它们有何不同以及我应该使用哪一个?

The image resizing function provided by Emgu (a .net wrapper for OpenCV) can use any one of four interpolation methods:

  1. CV_INTER_NN (default)
  2. CV_INTER_LINEAR
  3. CV_INTER_CUBIC
  4. 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 技术交流群。

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

发布评论

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

评论(4

夏花。依旧 2024-09-13 14:22:34

最近的邻居将尽可能快,但在调整大小时您将丢失大量信息。

线性插值速度较慢,但​​不会导致信息丢失,除非您缩小图像(实际上就是这样)。

三次插值(可能实际上是“双三次”)使用合并多个相邻像素的许多可能公式之一。这对于缩小图像来说要好得多,但在不丢失信息的情况下可以缩小多少仍然受到限制。根据算法的不同,您可能可以将图像缩小 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

早乙女 2024-09-13 14:22:34

这些算法是:(描述来自 OpenCV 文档)

  • INTER_NEAREST - 最近邻插值
  • INTER_LINEAR - 双线性插值(默认使用)
  • INTER_AREA - 使用像素区域关系重采样。它可能是图像抽取的首选方法,因为它可以提供无莫尔条纹的结果。但当图像缩放时,与INTER_NEAREST方法类似。
  • INTER_CUBIC - 4x4 像素邻域上的双三次插值
  • INTER_LANCZOS4 - 8x8 像素邻域上的 Lanczos 插值

如果您想要更快的速度,请使用最近邻方法。

如果您想在下采样后保持图像质量,可以考虑使用基于 INTER_AREA 的插值,但这又取决于图像内容。

可以找到速度比较的详细分析 此处

下面是从上述链接获取的 400*400 px 图像的速度比较

速度比较

The algorithms are: (descriptions are from the OpenCV documentation)

  • INTER_NEAREST - a nearest-neighbor interpolation
  • INTER_LINEAR - a bilinear interpolation (used by default)
  • INTER_AREA - resampling using pixel area relation. It may be a preferred method for image decimation, as it gives moire’-free results. But when the image is zoomed, it is similar to the INTER_NEAREST method.
  • INTER_CUBIC - a bicubic interpolation over 4x4 pixel neighborhood
  • INTER_LANCZOS4 - a Lanczos interpolation over 8x8 pixel neighborhood

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

Speed comparison

ま柒月 2024-09-13 14:22:34

使用的插值方法取决于您想要实现的目标:

CV_INTER_LINEARCV_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.

与他有关 2024-09-13 14:22:34

它们都会丢失信息,您使用哪种信息取决于您需要的速度、您可以承受丢失多少信息以及图像的性质。

抱歉,没有正确答案 - 这就是为什么有一个选择

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

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