[go: up one dir, main page]

Menu

[2694c9]: / src / GaussKernel.py  Maximize  Restore  History

Download this file

46 lines (38 with data), 1.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#
# 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))