qt图像算法—图像的镜像变换之c++实现(不调包)
1.基本原理
1.水平镜像变化
设图像的宽度为width,则水平镜像变化的映射关系如下:
2.垂直镜像变化
设图像的宽度为height,则垂直镜像变化的映射关系如下:
2.代码实现(代码是我以前自学图像处理时写的,代码很粗糙没做任何优化,但很好理解)
/*水平镜像变换函数*/
QImage* MainWindow::HMirrorTrans(QImage* image)
{
QImage* newImage = new QImage(image->width(),image->height(),QImage::Format_ARGB32);
//方法1:通过映射关系进行变换
int x = 0;
int y = 0;
unsigned char* copyPixel = NULL;
unsigned char* objPixel = NULL;
for (int j = 0; j< image->height(); j++)
{
y = j;
for(int i = 0; i < image->width(); i++)
{
x = image->width() - i - 1;
copyPixel = image->bits() + j * image->width() * 4 + i * 4;
objPixel = newImage->bits() + y * image->width() * 4 + x * 4;
memcpy(objPixel,copyPixel,4);
}
}
return newImage;
}
/*垂直镜像变换函数*/
QImage* MainWindow::VMirrorTrans(QImage* image)
{
QImage* newImage = new QImage(image->width(),image->height(),QImage::Format_ARGB32);
//方法1:通过映射关系进行变换
int x = 0;
int y = 0;
unsigned char* copyPixel = NULL;
unsigned char* objPixel = NULL;
for (int j = 0; j< image->height(); j++)
{
y = image->height() - j - 1;
for(int i = 0; i < image->width(); i++)
{
x = i;
copyPixel = image->bits() + j * image->width() * 4 + i * 4;
objPixel = newImage->bits() + y * image->width() * 4 + x * 4;
memcpy(objPixel,copyPixel,4);
}
}
return newImage;
}
3.项目源码下载:
整套算法系列:
https://blog.csdn.net/u013289254/category_12811658.html?spm=1001.2014.3001.5482https://blog.csdn.net/u013289254/category_12811658.html?spm=1001.2014.3001.5482项目源码下载地址:关注WX【AI街潜水的八角】,回复【qt图像算法】即可下载
整套项目源码内容包含
[1].根据算法原理,编写纯c++源码,不调用外源库opencv 等;
[2].包括各种图像处理的基本算法,包含腐蚀膨胀,缩放,转置,镜像,平移,均衡变化,灰度拉升,灰度阈值,灰度非线性,转灰度,灰度线性,旋转,简单平滑,高斯平滑,轮廓跟踪,种子算法,hough直线检测,拉普拉斯,带方向边缘检测,常规边缘检测(梯度算子、Roberts算子和Sobel算子),中值滤波,反色操作等;
[3].程序中有完整的注释,便于大家很好理解代码。
原文地址:https://blog.csdn.net/u013289254/article/details/143079752
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!