图像平移变换
来源:互联网 发布:社交软件发展前景 编辑:程序博客网 时间:2024/06/04 18:14
作为代码界的菜鸟,最近在尝试着用vs实现《数字图像处理与机器视觉》一书中有关图像处理的VC++代码。目前先从简单的图像几何变换做起,希望能记录自己的成长^_^
本篇是图像平移变换的实现。
#include <iostream>#include <opencv2\core\core.hpp>#include <opencv2\highgui\highgui.hpp>#include <opencv2\imgproc\imgproc.hpp>using namespace std;using namespace cv;/********************************************void imMove(Mat img,Mat &dst,int x,int y)功能: 平移图像注: 图像范围不变参数: Mat img:原图像 Mat dst: 处理后得到的图像 int x: 水平右移距离 int y: 垂直下移距离返回值: 无*********************************************/void imMove(Mat img,Mat &dst, int x, int y){ int nHeight = img.rows; int nWidth = img.cols; int i, j; if (x > nWidth || y > nHeight) { cout << "超出图片大小" << endl; return; } for (i = 0; i < nHeight; i++) { for (j = 0; j < nWidth; j++) { if (i - x>0 && i - x<nHeight&&j - y>0 && j - y < nWidth) dst.at<Vec3b>(i, j) = img.at<Vec3b>(i - x, j - y); else { dst.at<Vec3b>(i, j)[0] = 0; dst.at<Vec3b>(i, j)[1] = 0; dst.at<Vec3b>(i, j)[2] = 0; } } }}int main(){ Mat img = imread("1.jpg"); Mat dst=img.clone(); imshow("原图", img); //平移变换后 imMove(img,dst, 40, 60); imshow("平移变换", dst); waitKey(0); return 0;}
结果图如下:
0 0
- 图像平移变换
- opencv 数字图象处理 图像平移变换
- OpenCV 几何变换-图像平移
- 图像几何变换之图像位置变换之图像平移
- matlab 图像几何变换 平移、旋转、缩放
- matlab 图像几何变换 平移、旋转、缩放
- 【OpenCV3图像处理】图像简单几何变换:旋转、平移、缩放
- Matlab图像的几何变换之图像平移
- 平移变换
- 平移变换
- vc对图像进行平移,转置等几何变换
- Win8Metro(C#)数字图像处理--2.18图像平移变换
- 图像处理学习笔记之图像的几何变换(2)平移变换
- 平移图像
- 图像平移
- 图像平移
- 图像平移
- 图像基本变换--- 平移、旋转、缩放、仿射变换、镜像
- 哈希的拓展——位图
- Page Object Model (POM) & Page Factory in Selenium: Ultimate Guide
- Android dialog 详解七中方法!
- Spring transaction 事务 --Isolation & Progation
- 原来多线程中的join()是这么回事
- 图像平移变换
- RecyclerView 使用时空指针异常
- Apache Log4j配置说明
- 还教室 (线段树+暴力)
- 数据库脏读、不可重复读、幻象读
- 亲和数
- Elasticsearch2.4.1 数据库数据同步 oracle
- AeroSpike 启动关闭命令
- 动态代理