• 频率域滤波


    频率域滤波步骤

    共7步骤:
    1在这里插入图片描述
    2.
    在这里插入图片描述
    3.
    在这里插入图片描述4
    在这里插入图片描述
    5.
    在这里插入图片描述
    6.在这里插入图片描述
    7.
    在这里插入图片描述

    cv::Mat input = cv::imread("1.JPG", cv::IMREAD_GRAYSCALE);
     cv::imshow("step0_ori", input);
     int w = cv::getOptimalDFTSize(input.cols);
     int h = cv::getOptimalDFTSize(input.rows);
     cv::Mat padded;
     cv::copyMakeBorder(input, padded, 0, h - input.rows, 0, w - input.cols,
      cv::BORDER_CONSTANT, cv::Scalar::all(0));
     padded.convertTo(padded, CV_32FC1);
     cv::imshow("step1_padded", padded);
     for (int i = 0; i < padded.rows; i++)
     {
      float* ptr = padded.ptr<float>(i);
      for (int j = 0; j < padded.cols; j++)
       ptr[j] *= pow(-1, i + j);
     }
     cv::imshow("step2_center", padded);
     cv::Mat plane[] = { padded,cv::Mat::zeros(padded.size(),CV_32F) };
     cv::Mat complexImg;
     cv::merge(plane, 2, complexImg);
     cv::dft(complexImg, complexImg);
     cv::split(complexImg, plane);
     cv::magnitude(plane[0], plane[1], plane[0]);
     plane[0] += cv::Scalar::all(1);
     cv::log(plane[0], plane[0]);
     cv::normalize(plane[0], plane[0], 1, 0, cv::NORM_MINMAX);
     cv::imshow("dft", plane[0]);
    
     cv::Mat gaussianBlur(padded.size(), CV_32FC2);
     float D0 = 2 * 10 * 10;
     for (int i = 0; i < padded.rows; i++)
     {
      float* p = gaussianBlur.ptr<float>(i);
      for (int j = 0; j < padded.cols; j++)
      {
       float d = pow(i - padded.rows / 2, 2) + pow(j - padded.cols / 2, 2);
       p[2 * j] = expf(-d / D0);
       p[2 * j + 1] = expf(-d / D0);
      }
     }
     cv::split(gaussianBlur, plane);
     cv::magnitude(plane[0], plane[1], plane[0]);
     plane[0] += cv::Scalar::all(1);
     cv::log(plane[0], plane[0]);
     cv::normalize(plane[0], plane[0], 1, 0, cv::NORM_MINMAX);
     cv::imshow("gaussianBlurKernel", plane[0]);
    
     multiply(complexImg, gaussianBlur, gaussianBlur);
     cv::split(gaussianBlur, plane);
     cv::magnitude(plane[0], plane[1], plane[0]);
     plane[0] += cv::Scalar::all(1);
     cv::log(plane[0], plane[0]);
     cv::normalize(plane[0], plane[0], 1, 0, cv::NORM_MINMAX);
     cv::imshow("gaussianBlurOnDFT", plane[0]);
    
     cv::idft(gaussianBlur, gaussianBlur);
     cv::split(gaussianBlur, plane);
     cv::magnitude(plane[0], plane[1], plane[0]);
     cv::normalize(plane[0], plane[0], 1, 0, cv::NORM_MINMAX);
     cv::imshow("idft-gaussianBlur", plane[0]);
    
     cv::waitKey();
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
  • 相关阅读:
    如何用在线模版快速制作活动海报?
    【Vue】描述项目中两个功能模块的业务(一点见解)
    搞懂Python正则表达式,这一篇就够了
    中英文说明书丨IQ Products巨细胞病毒CMV感染检测试剂盒
    如何快速解决d3dcompiler_43.dll缺失问题?五种方法快速解决
    Spring Boot 整合RabbitMQ
    Golang 实现word和Excel处理
    逐步学习 Swagger enum:从入门到精通
    解决常见的电脑故障
    vivado里那些看不懂的原语
  • 原文地址:https://blog.csdn.net/Taiyang625/article/details/136338661