您现在的位置是:首页 > 文章详情

数字图像几何变换代码

日期:2018-10-23点击:237
原文: 数字图像几何变换代码

版权声明:本文为博主原创文章,转载请附上链接地址。 https://blog.csdn.net/ld15102891672/article/details/80628817

数字图像的旋转变换、镜像变换、错切变换以及平移变换等称为数字图像的几何变换。下文是数字图像旋转变换、镜像变换以及错切变换的基本原理的介绍以及C#代码的实现。

(1)数字图像旋转变换。

        

        数字图像旋转变换基本原理:

        

        数字图像旋转变换代码实现:

 private void btn_Rotate_Click(object sender, EventArgs e)//旋转变换按钮 { BmapNew = Rotate(60.0, BmapOld); this.pictureNew.Image = BmapNew; } private Bitmap Rotate(double Angle,Bitmap mapOld)//旋转变换代码 { double rad=Math.PI/180.0*Angle; Matrix T = new Matrix(3, 3); T.setElem(0, 0, Math.Cos(rad)); T.setElem(0, 1, -Math.Sin(rad)); T.setElem(1,0, Math.Sin(rad)); T.setElem(1, 1, Math.Cos(rad)); T.setElem(2, 2,1); int w = mapOld.Width; int h = mapOld.Height; Bitmap mapNew = new Bitmap((int)(w * Math.Cos(rad) + h * Math.Sin(rad)) + 1, (int)(w * Math.Sin(rad) + h * Math.Cos(rad)) + 1); Matrix map = new Matrix(3, 1); for (int j = 0; j < h; j++) { for (int i = 0; i< w; i++) { map.setElem(0, 0, i); map.setElem(1, 0, j); map.setElem(2, 0, 1); map = T.mult(map); Color pixel=mapOld.GetPixel(i,j); mapNew.SetPixel((int)map.getElem(0, 0) + (int)(h* Math.Sin(rad)), (int)map.getElem(1, 0), pixel); } } return mapNew; }

(2)数字图像镜像变换

     

     数字图像镜像变换基本原理:

     


     数字图像镜像变换代码实现:

 private void btn_JingXiang_Click(object sender, EventArgs e)//镜像变换按钮 { BmapNew = Mirror(BmapOld); this.pictureNew.Image = BmapNew; } private Bitmap Mirror(Bitmap mapOld)//图片镜像变换代码 { int w = mapOld.Width; int h = mapOld.Height; Matrix T = new Matrix(3, 3); T.setElem(0, 0, -1); T.setElem(0, 2, w); T.setElem(1, 1, 1); T.setElem(2, 2, 1); Bitmap mapNew =new Bitmap(w,h); Matrix map = new Matrix(3, 1); for (int j = 0; j < h; j++) { for (int i = 0; i < w; i++) { map.setElem(0, 0, i); map.setElem(1, 0, j); map.setElem(2, 0, 1); map = T.mult(map); Color pixel = mapOld.GetPixel(i, j); mapNew.SetPixel((int)map.getElem(0, 0)-1, (int)map.getElem(1, 0), pixel); } } return mapNew; }

(3)数字图像错切变换


        数字图像错切变换基本原理:


     数字图像错切变换代码实现:

 private void btn_ShearMapping_Click(object sender, EventArgs e)//错切变换按钮 { BmapNew = ShearMapping(30.0, BmapOld); this.pictureNew.Image = BmapNew; } private Bitmap ShearMapping(double Angle,Bitmap mapOld)//图片错切变换代码 { double rad = Math.PI / 180.0 * Angle; int w = mapOld.Width; int h = mapOld.Height; int newW = w + (int)(h * Math.Tan(rad)); Bitmap mapNew = new Bitmap(newW, h); for (int j = 0; j < h; j++) { for (int i = 0; i < w; i++) { Color pixel = mapOld.GetPixel(i, j); mapNew.SetPixel((int)((h-j)*Math.Tan(rad))+i, j, pixel); } } return mapNew; }

原文链接:https://yq.aliyun.com/articles/676885
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章