【数字摄影测量】C#双线性插值、最近邻法、双三次卷积法对矩阵进行插值

使用C#实现双线性插值、最近邻法、双三次卷积法插值,目标是矩阵而不是图像,锻炼编写程序的能力。数据来源采用读取txt的方式。

【同班同学不要来抄我的。】

1、最近邻法插值:

目标矩阵:

[1, 1

2 ,2]

实现代码:

using System;

namespace 最近邻像元法
{
    class 最近邻像元法
    {
        static void Main(string[] args)
        {
            Console.WriteLine("最邻近像元法");
            float[,] ZB;
            ZB = new float[,] { { 10, 20 }, { 30, 40 } };
            Console.WriteLine("四个像素的值为:");
            int i, j;
            for (i = 0; i < 2; i++)
            {
                for (j = 0; j < 2; j++)
                {
                    Console.Write(ZB[i, j] + " ");
                }
                Console.WriteLine();
            }

            float x = 0.4F;
            float y = 0.3F;
            Console.WriteLine("采样点的坐标为:" + "(" + x + "," + y + ")");

            float result;
            int Xn = (int)(x + 0.5);
            int Yn = (int)(y + 0.5);
            result = ZB[Xn, Yn];
            Console.WriteLine("采样结果为:" + result);//输出结果
            Console.ReadLine();
        }
    }
}

 2、双线性内插

目标2x2矩阵

1 1

2 2

代码:

采用读取txt的方式,比较复杂。

using System;
using System.IO;
namespace 内插1
{
    class 双线性内插
    {
        static void Main(string[] args)
        {
            //   float[,] ZB;

            //     ZB = new float[,] { { 10, 10 }, { 20, 20 }  };

            Console.WriteLine("相对路径下的请输入文件名:(例如test.txt)");
            string Path = @"test.txt";
            Path = Convert.ToString(Console.ReadLine());

            float x = 0.5F;
            float y = 0.5F;
            Console.WriteLine("请输入采样点的x坐标:");
            x = (float)Convert.ToDoubl
  • 4
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值