当前位置: 首页 > news >正文

图像的平移变换之c++实现(qt + 不调包)

1.基本原理

 

    设dx为水平偏移量,dy为垂直偏移量,则平移变换的坐标映射关系为下公式,图像平移一般有两种方式。

    1.不改变图像大小的平移(一旦平移,相应内容被截掉)

    1)当dx >= width、dx <= -width、dy >= height或dy <= -height时候,此时图像完全移出画布范围,可以不处理

    2)当dx < 0 时候,左侧部分图像将被截取

    3)当dx > 0 时候,右侧部分图像将被截取

    2.改变图像大小的平移(一旦平移,图像会变大)

2.代码实现(代码是我以前自学图像处理时写的,代码很粗糙没做任何优化,但很好理解

/*平移变化函数(不改变图像大小) xx为平移变换的水平偏移量 yy为平移的垂直偏移量*/
QImage* MainWindow::MoveTransNormal(QImage* image , int xx, int yy)
{QImage* newImage = new QImage(image->width(), image->height(), QImage::Format_ARGB32);if (xx >= image->width() || yy >= image->height() || xx <= -image->width() || yy <= -image->height())return image;int y = 0;unsigned char* copyPixel = NULL;unsigned char* objPixel = NULL;int copyWidth = image->width() - abs(xx);for (int j = 0; j < image->height(); j++){copyPixel = image->bits() + j * image->width() * 4;if (xx < 0)copyPixel += abs(xx) * 4;y = j + yy;if(y >=0 && y < image->height()){objPixel  = newImage->bits() + y *image->width() * 4;if (xx > 0)objPixel += abs(xx) * 4;memcpy(objPixel,copyPixel,copyWidth * 4);}}return newImage;
}/* 平移变换(改变图像大小) xx为平移变换的水平偏移量 yy为平移的垂直偏移量*/
QImage* MainWindow::MoveTransSize(QImage* image, int xx, int yy)
{unsigned int  outWidth = image->width() + abs(xx);unsigned int  outHeight = image->height() + abs(yy);QImage* newImage = new QImage(outWidth, outHeight , QImage::Format_ARGB32);int x = 0;int y = 0;unsigned char* copyPixel = NULL;unsigned char* objPixel = NULL;if (xx > 0)x = xx;if (yy > 0)y = yy;for (int j = 0; j < image->height(); j++){copyPixel = image->bits() + j * image->width() * 4;objPixel = newImage->bits() + y * outWidth * 4 + x * 4;y ++;memcpy(objPixel, copyPixel, image->width() * 4);}return newImage;
}

3.参考资料

    数字图像处理——技术详解与Visual C++实践(左飞等著),写代码与写博客的时间相差两年,至于还参考其他的资料不,我已经忘记了,如若需要,我可以补上去

http://www.lryc.cn/news/120374.html

相关文章:

  • 云原生K8S------Yaml文件详解
  • 测试开发环境安装
  • 微信小程序如何引入Iconfont
  • php使用get和post传递数据出现414 Request-URI Too Large的解决方案
  • 复现大华智慧园区综合管理平台SQL注入漏洞
  • 【uniapp】uniapp设置安全区域:
  • Grafana技术文档--基本安装-docker安装并挂载数据卷-《十分钟搭建》-附带监控服务器
  • 24大连交通大学软件工程813题库
  • 数据治理-组织变革
  • html的语义化
  • 8/12 题解
  • 九耶丨阁瑞钛伦特-产品经理面试题
  • 前后端分离项目接口权限检查方案
  • 步入React正殿 - 事件处理
  • NLP(六十四)使用FastChat计算LLaMA-2模型的token长度
  • 个保新标 | 《信息安全技术 敏感个人信息处理安全要求》(征求意见稿)发布
  • 【uniapp 返回顶部】
  • 无代码集成励销云CRM连接更多应用
  • QT自带PDF库的使用
  • SQL | 排序检索的数据
  • 8. yaml文件管理
  • Cobbler自定义yum源
  • 《算法竞赛·快冲300题》每日一题:“特殊数字”
  • 在R中比较两个矩阵是否相等
  • 商城-学习整理-基础-商品服务API-属性分组(七)
  • 什么是响应式设计?列举几种实现响应式设计的方法。
  • Java类和对象(一文读懂)
  • 用友移动管理系统 任意文件上传漏洞复现(HW0day)
  • 启动springboot,出现Unable to start embedded Tomcat
  • 加密和安全