76 lines
1.6 KiB
C++
76 lines
1.6 KiB
C++
#ifndef CONVOLUTION2D_H
|
|
#define CONVOLUTION2D_H
|
|
|
|
#ifndef __USE_SQUARE_BRACKETS_FOR_ELEMENT_ACCESS_OPERATOR
|
|
#define __USE_SQUARE_BRACKETS_FOR_ELEMENT_ACCESS_OPERATOR
|
|
#endif
|
|
|
|
#include "../../math/boxkde/Image2D.h"
|
|
#include "../../lib/simple_fft/fft.h"
|
|
|
|
|
|
namespace DSP {
|
|
|
|
template <typename Scalar> class Convolution2D {
|
|
|
|
public:
|
|
|
|
static inline Image2D<Scalar> convolve(Image2D<Scalar> signal, Image2D<Scalar> kernel){
|
|
|
|
RealArray2D signalReal;
|
|
ComplexArray2D signalSpectrum;
|
|
|
|
RealArray2D kernelReal;
|
|
ComplexArray2D kernelSpectrum;
|
|
|
|
//convert image2d single vector to 2d vector, just use pointers
|
|
int signal_x = signal.width;
|
|
int signal_y = signal.height;
|
|
int kernel_x = kernel.width;
|
|
int kernel_y = kernel.height;
|
|
|
|
//check if power of 2, if not fill with zeros
|
|
while(!isPowerOfTwo(signal_x)){
|
|
|
|
}
|
|
|
|
if(!isPowerOfTwo(kernel.size)){
|
|
|
|
}
|
|
|
|
/** TODO:
|
|
* Image2D Funktion make powertwo schreiben
|
|
* die Bild zeilenweise durchgeht und mit nullen füllt und in neuen vektor speichert.
|
|
* Ggf. Nen konstruktor dafür keine Funktion? Dann pfusch ich net im original rum.
|
|
*/
|
|
|
|
//calculate FFT for both
|
|
|
|
simple_fft::FFT();
|
|
|
|
//multiplay the results pointwise
|
|
|
|
//IFFT
|
|
simple_fft::IFFT();
|
|
|
|
//profit?
|
|
}
|
|
|
|
private:
|
|
|
|
typedef std::vector<std::vector<complex_type> > ComplexArray2D;
|
|
typedef std::vector<std::vector<real_type> > RealArray2D;
|
|
|
|
|
|
|
|
bool isPowerOfTwo (unsigned int x)
|
|
{
|
|
return ((x != 0) && !(x & (x - 1)));
|
|
}
|
|
|
|
};
|
|
}
|
|
|
|
|
|
#endif // CONVOLUTION_H
|