diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-02-28 23:13:39 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-02-28 23:13:39 +0800 |
commit | dc1f0c4c0096013799416664894c5194dc7e1f52 (patch) | |
tree | 2f5d235f778cd720f4c39ec3e56b77ba6d99f375 /works/life/digital-image-process-lab/DiscreteFourierTransform.cpp | |
parent | 7299d424d90b1effb6db69e3476ddd5af72eeba4 (diff) | |
download | crupest-dc1f0c4c0096013799416664894c5194dc7e1f52.tar.gz crupest-dc1f0c4c0096013799416664894c5194dc7e1f52.tar.bz2 crupest-dc1f0c4c0096013799416664894c5194dc7e1f52.zip |
chore(store): move everything to store.
Diffstat (limited to 'works/life/digital-image-process-lab/DiscreteFourierTransform.cpp')
-rw-r--r-- | works/life/digital-image-process-lab/DiscreteFourierTransform.cpp | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/works/life/digital-image-process-lab/DiscreteFourierTransform.cpp b/works/life/digital-image-process-lab/DiscreteFourierTransform.cpp deleted file mode 100644 index 31108bb..0000000 --- a/works/life/digital-image-process-lab/DiscreteFourierTransform.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include <opencv2/core.hpp> -#include <opencv2/highgui.hpp> -#include <opencv2/imgcodecs.hpp> -#include <opencv2/imgproc.hpp> - -#include <iostream> - -using namespace cv; - -int main(int argc, char **argv) { - if (argc != 2) { - std::cerr << "Please input an image file path as the only arg." - << std::endl; - return -1; - } - - const char *filename = argv[1]; - Mat I = imread(samples::findFile(filename), IMREAD_GRAYSCALE); - if (I.empty()) { - std::cout << "Error opening image" << std::endl; - return EXIT_FAILURE; - } - Mat padded; // expand input image to optimal size - int m = getOptimalDFTSize(I.rows); - int n = getOptimalDFTSize(I.cols); // on the border add zero values - copyMakeBorder(I, padded, 0, m - I.rows, 0, n - I.cols, BORDER_CONSTANT, - Scalar::all(0)); - Mat planes[] = {Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F)}; - Mat complexI; - merge(planes, 2, complexI); // Add to the expanded another plane with zeros - dft(complexI, complexI); // this way the result may fit in the source matrix - // compute the magnitude and switch to logarithmic scale - // => log(1 + sqrt(Re(DFT(I))^2 + Im(DFT(I))^2)) - split(complexI, planes); // planes[0] = Re(DFT(I), planes[1] = Im(DFT(I)) - magnitude(planes[0], planes[1], planes[0]); // planes[0] = magnitude - Mat magI = planes[0]; - magI += Scalar::all(1); // switch to logarithmic scale - log(magI, magI); - // crop the spectrum, if it has an odd number of rows or columns - magI = magI(Rect(0, 0, magI.cols & -2, magI.rows & -2)); - // rearrange the quadrants of Fourier image so that the origin is at the - // image center - int cx = magI.cols / 2; - int cy = magI.rows / 2; - Mat q0(magI, Rect(0, 0, cx, cy)); // Top-Left - Create a ROI per quadrant - Mat q1(magI, Rect(cx, 0, cx, cy)); // Top-Right - Mat q2(magI, Rect(0, cy, cx, cy)); // Bottom-Left - Mat q3(magI, Rect(cx, cy, cx, cy)); // Bottom-Right - Mat tmp; // swap quadrants (Top-Left with Bottom-Right) - q0.copyTo(tmp); - q3.copyTo(q0); - tmp.copyTo(q3); - q1.copyTo(tmp); // swap quadrant (Top-Right with Bottom-Left) - q2.copyTo(q1); - tmp.copyTo(q2); - normalize(magI, magI, 0, 1, - NORM_MINMAX); // Transform the matrix with float values into a - // viewable image form (float between values 0 and 1). - imshow("Input Image", I); // Show the result - imshow("spectrum magnitude", magI); - waitKey(); - return EXIT_SUCCESS; -} |