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