SigPack - the C++ signal processing library
image.cpp
Go to the documentation of this file.
1 
9 #include "sigpack.h"
10 using namespace arma;
11 using namespace sp;
12 
13 int main()
14 {
15  PNM ppm; // Portable Pixel Map
16 
17  int R = 120, C = 160;
18  mat x(R, C);
19  cx_mat X(R, C);
20  mat mag(R, C);
21  FFTW ss(R, C, FFTW_ESTIMATE);
22 
23  gplot gp0, gp1;
24  gp0.window("Image", 10, 10, 2 * C + 80, 2 * R + 50);
25  gp1.window("FFT Blue channel", 640, 10, 2 * C + 80 + 50, 2 * R + 50);
26 
27  // Generate test image
28  cube x3(R, C, 3, fill::randu);
29  x3 *= 100;
30  x3.slice(0).submat(span(20, 51), span(20, 51)) =
31  250 * ones(32, 32); // Red box
32  x3.slice(1).submat(span(80, 111), span(70, 101)) =
33  250 * ones(32, 32); // Green box
34  x3.slice(2).submat(span(20, 51), span(110, 141)) =
35  250 * ones(32, 32); // Blue box
36 
37  // Write to file
38  ppm.write("test.ppm", ppm.PPM_B, x3, "Test picture");
39 
40  // Do FFT of blue channel
41  x = x3.slice(2);
42  X = ss.fft2(x);
43  mag = 20 * log10(abs(fftshift(X)));
44 
45  // Plot
46  gp0.set_term("qt");
47  gp0.image(x3);
48  gp1.set_term("qt");
49  gp1.send2gp("set palette grey");
50  gp1.image(mag);
51 
52  return 0;
53 }
int main()
Definition: image.cpp:13
bool write(std::string fname, const imtype _type, const arma::cube &img, const std::string info="")
Write the .pnm file.
Definition: image.h:150
Gnuplot class.
Definition: gplot.h:25
Definition: base.h:7
void fft2(arma::mat &x, arma::cx_mat &Pxx)
FFT of real 2D input.
Definition: fftw.h:233
void image(const arma::Mat< T > &x)
Plot mat as image.
Definition: gplot.h:473
void set_term(const char *ttype)
Set output terminal.
Definition: gplot.h:759
arma::Col< T > fftshift(const arma::Col< T > &Pxx)
1D FFT shift.
Definition: base.h:143
FFTW class.
Definition: fftw.h:25
void window(const int fig, const char *name, const int x, const int y, const int width, const int height)
Configure the figure used Windows environment.
Definition: gplot.h:182
Portable anymap format class.
Definition: image.h:22
void send2gp(const char *cmdstr)
Send command to Gnuplot pipe.
Definition: gplot.h:141