From bf5429cd0c9e7f5f0bc4903de33d54e20d4ce8b7 Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Thu, 10 Oct 2013 20:06:12 -0400 Subject: [PATCH] Add Gaussian kernel generating function. --- Base/include/Image.h | 2 ++ Base/src/Image.cpp | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/Base/include/Image.h b/Base/include/Image.h index ddd0428..1c70712 100644 --- a/Base/include/Image.h +++ b/Base/include/Image.h @@ -125,6 +125,8 @@ namespace FasTC { void ConvertFromBlockStreamOrder(); }; + extern void GenerateGaussianKernel(Image &out, uint32 size, float sigma); + } // namespace FasTC #endif // __TEXCOMP_IMAGE_H__ diff --git a/Base/src/Image.cpp b/Base/src/Image.cpp index 1e8561c..dcff088 100644 --- a/Base/src/Image.cpp +++ b/Base/src/Image.cpp @@ -350,4 +350,22 @@ template class Image; template class Image; template class Image; +void GenerateGaussianKernel(Image &out, uint32 size, float sigma) { + + assert(size % 2); + + out = Image(size, size); + if(size == 1) { + out(0, 0) = 1.0f; + return; + } + + int32 halfSz = static_cast(size) / 2; + for(int32 j = -halfSz; j < halfSz; j++) { + for(int32 i = -halfSz; i < halfSz; i++) { + out(i, j) = exp(- (j*j + i*i) / (2*sigma*sigma)); + } + } +} + } // namespace FasTC