C#图像插值算法

时间:2022-07-23
本文章向大家介绍C#图像插值算法,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

重置图像和大小

高斯金字塔是固定比例来改变图像的分辨率,有些时候我们的需求并非

是长和宽缩放比例都一样,所以接来介绍任意比例缩放,来改变图像的分辨

率。

EmguCv 实现:

EmguCv 可以通过CvInvoke 类里面的方法来实现高斯金字塔,也可以通

过Image<TColor,TDepth> method 来实现,这边主要讲解前者。

Resize()函数介绍:

public static void Resize(IInputArray src, IOutputArray dst, Size dsize,

double fx = 0, double fy = 0, Inter interpolation = Inter.Linear);//指定比例缩放图

像。

参数解析:

IInputArray src:输入图像,即原图像。

IOutputArray dst:输出图像,采样后得到的图像。

Size dsize:输出图像的大小,如果这边dsize 为0,则输出图像大

小有fx 和fy 决定。同时说明dsize 的权大于fx,fy。

dsize=Size(round(fx*scr.cols),round(fy*scr.rows));其中fx!=0,fy!=0。

double fx = 0:水平缩放比例。

double fy = 0:垂直缩放比例。

Inter interpMethod = Inter.Linear:插值类型的标识符,具体如表

实现代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Emgu.CV;
using Emgu.CV.CvEnum;


namespace WindowsFormsApp28
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Mat scr = new Mat(@"C:UserslinDesktopimagelena.jpg", LoadImageType.AnyColor);
            Mat dst = new Mat();
            //CvInvoke.Resize(scr, dst, new Size(150, 200), 0, 0, Inter.Cubic);//三次样条插值
            CvInvoke.Resize(scr, dst, new Size(150, 200), 0, 0, Inter.Lanczos4);//兰索斯算法插值

            label1.Text = "size:" + scr.Size.ToString();
            label2.Text = "size:" + dst.Size.ToString();
            imageBox1.Image = scr;
            imageBox2.Image = dst;

        }
    }
}