QT实现图像处理-傅立叶变换、傅立叶反变换、平滑、锐化与模板匹配 实验环境: 1,Linux 操作系统 2,QT3 编程开发环境 3,C++编程语言 傅立叶变换和傅立叶反变换 1.1. 主要源代码 readImage() 从图像中读取数据 writeImage() 往图像中写入数据 fft() 快速傅立叶变换 ifft() 快速傅立叶反变换 adjustImageSize() 调整图像大小 fourier() 傅立叶变换 ifourier() 傅立叶反变换 1.1.1 从图像中读取数据 void ImageProcess::readImage(complex data[], const QImage &srcImage) { byte *pImageBytes = srcImage.bits(); //数据首地址 int depth = srcImage.depth(); //每个像素的 bit 数 int lineBytes = srcImage.bytesPerLine(); //每行的字节数 int w = srcImage.width(); //宽 int h = srcImage.height(); //高 byte *pByte; //遍历读取每个像素,并转换为灰度值 int i, j; for(i = 0; i < h; i++) { for(j = 0; j < w; j++) { if(8 == depth) //采用了 256 色调色板,8 位颜色索引 { pByte = pImageBytes + i * lineBytes + j; data[i * w + j] = complex( *pByte, 0); } else if(32 == depth)//32 位表示,数据格式为 0xFFBBGGRR 或 0xAABBGGRR { pByte = pImageBytes + i * lineBytes + j * 4; //根据RGB 模式转化成YIQ 色彩模式的方式,取Y 作为灰度值 byte pixelValue = (byte)(0.299 * (float)pByte[0] + 0.587 * (float)pByte[1] + 0.114 * (float)pByte[2]); data[i * w + j] = complex( pixelValue, 0); } else { cout << "invalid format. depth = " << depth << "\n"; return; } } } } 1 .1 .2 将数据写入图像 //coef 为比例系数,主要用来调整灰度值以便于观察 void ImageProcess::writeImage(QImage &destImage, const complex data[], double coef) { int lineBytes = destImage.bytesPerLine(); int depth = destImage.depth(); int w = destImage.width(); int h = destImage.height(); byte *pImageBytes = destImage.bits(); byte *pByte; for(int i = 0; i < h; i++) { for(int j = 0; j < w; j++) { double spectral = abs(data[i * w + j...