SigPack - the C++ signal processing library
 
Loading...
Searching...
No Matches
image.cpp

Output

Source

#include "sigpack.h"
using namespace arma;
int main()
{
sp::PNM ppm; // Portable Pixel Map
int R = 120, C = 160;
mat x( R, C );
cx_mat X( R, C );
mat mag( R, C );
sp::FFTW ss( R, C, FFTW_ESTIMATE );
sp::gplot gp0, gp1;
gp0.window( "Image", 10, 10, 2 * C + 80, 2 * R + 50 );
gp1.window( "FFT Blue channel", 640, 10, 2 * C + 80 + 50, 2 * R + 50 );
// Generate test image
cube x3( R, C, 3, fill::randu );
x3 *= 100;
x3.slice( 0 ).submat( span( 20, 51 ), span( 20, 51 ) ) = 250 * ones( 32, 32 ); // Red box
x3.slice( 1 ).submat( span( 80, 111 ), span( 70, 101 ) ) = 250 * ones( 32, 32 ); // Green box
x3.slice( 2 ).submat( span( 20, 51 ), span( 110, 141 ) ) = 250 * ones( 32, 32 ); // Blue box
// Write to file
ppm.write( "test.ppm", ppm.PPM_B, x3, "Test picture" );
// Do FFT of blue channel
x = x3.slice( 2 );
X = ss.fft2( x );
mag = 20 * log10( abs( sp::fftshift( X ) ) );
// Plot
gp0.set_term( "qt" );
gp0.image( x3 );
gp1.set_term( "qt" );
gp1.send2gp( "set palette grey" );
gp1.image( mag );
return 0;
}
int main()
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