#
# This file is part of fluid3d - a software for image registration
#
# Copyright (c) Madrid 2013
#
# fluid3d is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with fluid3d; if not, see <http://www.gnu.org/licenses/>.
#
#
import numpy as np
def create_gausskernel(hwidth):
"""
Create a gaussian filter kernel of the given half width and return it as numpy array.
"""
kernlen = 2*hwidth+1
kern = np.zeros(2*hwidth+1).astype(np.float32)
tmp = np.zeros(2*hwidth).astype(np.float32)
kern[0] = 1.0
if hwidth < 1:
return kern
kern[1] = 1.0
i = 2
while i < kernlen:
kern[i] = 1
tmp[0:i] = kern[0:i]
kern[1:i] = np.add(kern[1:i], tmp[0:i-1])
i = i+1
return np.multiply(kern, 1.0 / np.sum(kern))