app-fft-movie.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef APPMEDIA_APP_FFT_MOVIE_C_DEFINED
00040 #define APPMEDIA_APP_FFT_MOVIE_C_DEFINED
00041
00042 #include "Component/ModelManager.H"
00043 #include "GUI/ImageDisplayStream.H"
00044 #include "Image/ColorOps.H"
00045 #include "Image/Convolver.H"
00046 #include "Image/Coords.H"
00047 #include "Image/CutPaste.H"
00048 #include "Image/DrawOps.H"
00049 #include "Image/FilterOps.H"
00050 #include "Image/FourierEngine.H"
00051 #include "Image/MathOps.H"
00052 #include "Image/Pixels.H"
00053 #include "Media/MPEGStream.H"
00054 #include "rutz/trace.h"
00055
00056 int main(int argc, const char** argv)
00057 {
00058 ModelManager mgr(argv[0]);
00059
00060 nub::soft_ref<InputMPEGStream> ims(new InputMPEGStream(mgr));
00061
00062 mgr.addSubComponent(ims);
00063 mgr.exportOptions(MC_RECURSE);
00064
00065 if (mgr.parseCommandLine(argc, argv, "infile.mpg", 1, 1) == false)
00066 return 1;
00067
00068 mgr.start();
00069
00070 const std::string infile = mgr.getExtraArg(0);
00071
00072 ims->setFileName(infile);
00073
00074 nub::soft_ref<ImageDisplayStream> ids(new ImageDisplayStream(mgr));
00075
00076 Image<float> box(15, 15, NO_INIT);
00077 box.clear(1.0f/(15*15));
00078
00079 LINFO("box sum: %g", sum(box));
00080
00081 FourierEngine<double> eng(ims->peekDims());
00082 FourierInvEngine<double> ieng(ims->peekDims());
00083
00084 Convolver conv(box, ims->peekDims());
00085
00086 while (true)
00087 {
00088 const Image<PixRGB<byte> > img = ims->readRGB();
00089
00090 if (!img.initialized())
00091 break;
00092
00093 const Image<float> lum = luminance(Image<PixRGB<float> >(img));
00094
00095 Image<complexd> res = eng.fft(Image<double>(lum));
00096
00097 const Image<double> rt = ieng.ifft(res) / img.getSize();
00098
00099 const Image<double> logmag = logmagnitude(res);
00100 const Image<double> phz = phase(res);
00101 const Image<double> cart = cartesian(logmag, Dims(256, 256));
00102
00103 ids->writeRGB(img, "input");
00104 ids->writeFloat(logmag, FLOAT_NORM_0_255 | FLOAT_NORM_WITH_SCALE,
00105 "logmag-fft-input");
00106 ids->writeFloat(phz, FLOAT_NORM_0_255 | FLOAT_NORM_WITH_SCALE,
00107 "phase-fft-input");
00108 ids->writeFloat(cart, FLOAT_NORM_0_255 | FLOAT_NORM_WITH_SCALE,
00109 "cartesian-logmag-fft-input");
00110
00111 const Image<float> c1 = conv.spatialConvolve(lum);
00112
00113 const Image<float> c2 = conv.fftConvolve(lum);
00114
00115 ids->writeFloat(c1, FLOAT_NORM_0_255 | FLOAT_NORM_WITH_SCALE,
00116 "c1");
00117 ids->writeFloat(c2, FLOAT_NORM_0_255 | FLOAT_NORM_WITH_SCALE,
00118 "c2");
00119
00120 LINFO("rms conv diff: %e corrcoef: %e",
00121 RMSerr(c1, c2), corrcoef(c1, c2));
00122
00123 LINFO("rms roundtrip fft->ifft diff: %e",
00124 RMSerr(Image<float>(rt), lum));
00125 }
00126
00127 mgr.stop();
00128 }
00129
00130
00131
00132
00133
00134
00135
00136 #endif // APPMEDIA_APP_FFT_MOVIE_C_DEFINED