NPL
Neurological Programs and Libraries
mrimage_utils.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2014 Micah C Chambers (micahc.vt@gmail.com)
3  *
4  * NPL is free software: you can redistribute it and/or modify it under the
5  * terms of the BSD 2-Clause License available in LICENSE or at
6  * http://opensource.org/licenses/BSD-2-Clause
7  *
8  * @file mrimage_utils.h
9  * @brief This file contains common functions which are useful for image
10  * processing. Note that ndarray_utils.h has utilities which are more general
11  * whereas this file contains functions which are specifically for image
12  * processing.
13  ******************************************************************************/
14 
15 #ifndef MRIMAGE_UTILS_H
16 #define MRIMAGE_UTILS_H
17 
18 #include "ndarray.h"
19 #include "mrimage.h"
20 #include "basic_functions.h"
21 #include "npltypes.h"
22 
23 #include <string>
24 #include <iostream>
25 #include <iomanip>
26 #include <cassert>
27 #include <memory>
28 
29 namespace npl {
30 
31 using std::vector;
32 
46 std::ostream& operator<<(std::ostream &out, const MRImage& img);
47 
48 /*****************************************************************************
49  * Kernel Functions
50  ****************************************************************************/
51 
60 void gaussianSmooth1D(ptr<MRImage> inout, size_t dim, double stddev);
61 
62 
63 /******************************************************
64  * Resample Image Functions
65  ******************************************************/
66 
78 ptr<MRImage> smoothDownsample(ptr<const MRImage> in,
79  double sigma, double spacing = -1);
80 
90 ptr<MRImage> resample(ptr<const MRImage> in, double* spacing,
91  double(*window)(double, double) = hannWindow);
92 
93 /******************************************************
94  * FFT Tools
95  *****************************************************/
106 ptr<MRImage> shiftImage(ptr<MRImage> in, size_t len, double* vect);
107 
118 void writeComplex(std::string basename, ptr<const MRImage> in,
119  bool absPhase = false);
120 
131 ptr<MRImage> fft_forward(ptr<const MRImage> in,
132  const std::vector<size_t>& in_osize);
133 
145 ptr<MRImage> fft_backward(ptr<const MRImage> in,
146  const std::vector<size_t>& in_osize);
147 
159 int rotateImageShearKern(ptr<MRImage> inout, double rx, double ry, double rz,
160  double(*kern)(double,double) = npl::lanczosKern);
161 
174 int rotateImageShearFFT(ptr<MRImage> inout, double rx, double ry, double rz,
175  double(*window)(double,double) = npl::sincWindow);
176 
188 ptr<MRImage> rigidTransform(ptr<MRImage> in, double rx, double ry, double rz,
189  double sx, double sy, double sz);
190 
200 ptr<MRImage> diffOfGauss(ptr<const MRImage> in, double sd1, double sd2);
201 
210 double overlapRatio(ptr<const MRImage> a, ptr<const MRImage> b);
211 
221 ptr<MRImage> resampleNN(ptr<const MRImage> in, ptr<const MRImage> atlas,
222  PixelT type = UNKNOWN_TYPE);
223 
224 
234 ptr<MRImage> resampleNN(ptr<const MRImage> in, double* newspace,
235  PixelT type = UNKNOWN_TYPE);
236 
250 ptr<MRImage> randImage(PixelT type, double mean, double sd,
251  size_t x, size_t y, size_t z, size_t t);
252 
254 } // npl
255 #endif //MRIMAGE_UTILS_H
Definition: accessors.h:29
ptr< MRImage > fft_backward(ptr< const MRImage > in, const std::vector< size_t > &in_osize)
Performs inverse FFT transform in N dimensions.
int rotateImageShearFFT(ptr< MRImage > inout, double rx, double ry, double rz, double(*window)(double, double)=npl::sincWindow)
Rotates an image around the center using shear decomposition followed by FFT-based shearing...
int rotateImageShearKern(ptr< MRImage > inout, double rx, double ry, double rz, double(*kern)(double, double)=npl::lanczosKern)
Rotates an image around the center using shear decomposition followed by kernel-based shearing...
ptr< MRImage > fft_forward(ptr< const MRImage > in, const std::vector< size_t > &in_osize)
Performs forward FFT transform in N dimensions.
std::ostream & operator<<(std::ostream &os, const Matrix< D1, D2 > &b)
PixelT
Definition: ndarray.h:35
double sincWindow(double x, double a)
Sinc function centered at 0, with radius a, range should be = 2a.
ptr< MRImage > diffOfGauss(ptr< const MRImage > in, double sd1, double sd2)
Computes difference of gaussians.
ptr< MRImage > resampleNN(ptr< const MRImage > in, ptr< const MRImage > atlas, PixelT type=UNKNOWN_TYPE)
Performs nearest neighbor resasmpling of input to atlas.
double hannWindow(double x, double a)
ptr< MRImage > resample(ptr< const MRImage > in, double *spacing, double(*window)(double, double)=hannWindow)
Performs fourier resampling using fourier transform and the provided window function.
void gaussianSmooth1D(ptr< MRImage > inout, size_t dim, double stddev)
Gaussian smooths an image in 1 direction. Questionable whether it works. Seems to shift image...
ptr< MRImage > rigidTransform(ptr< MRImage > in, double rx, double ry, double rz, double sx, double sy, double sz)
Rigid Transforms an image.
ptr< MRImage > randImage(PixelT type, double mean, double sd, size_t x, size_t y, size_t z, size_t t)
Create random image, with gaussian distribution.
ptr< MRImage > shiftImage(ptr< MRImage > in, size_t len, double *vect)
Uses fourier shift theorem to shift an image.
ptr< MRImage > smoothDownsample(ptr< const MRImage > in, double sigma, double spacing=-1)
Performs smoothing in each dimension, then downsamples so that pixel spacing is roughly equal to FWHM...
double lanczosKern(double x, double a)
Derivative of lanczos kernel with respect to x.
void writeComplex(std::string basename, ptr< const MRImage > in, bool absPhase=false)
Writes a pair of images, one real, one imaginary or if absPhase is set to true then an absolute image...
double overlapRatio(ptr< const MRImage > a, ptr< const MRImage > b)
Computes the overlap of the two images' in 3-space.