Hello! I'm looking for a 2D hamming window function. As far as I can see, numpy only supports 1D windows and googling didn't show a simple way of extending it in two dimensions.
Thanks for your help,
Henrik
Henrik Ronellenfitsch wrote:
Hello! I'm looking for a 2D hamming window function. As far as I can see, numpy only supports 1D windows and googling didn't show a simple way of extending it in two dimensions.
Thanks for your help,
Henrik
Hi Henrik,
I haven't looked at the "correct" way to do this, but I recently wanted to do the same thing and ended up with the following solution. This may well be mathematically incorrect, but in my application it wasn't important:
import numpy as np import scipy.signal as ss
# read heightmap here  in my case it's a square numpy float array
# build 2d window hm_len = heightmap.shape[0] bw2d = np.outer(ss.hamming(hm_len), np.ones(hm_len)) bw2d = np.sqrt(bw2d * bw2d.T) # I don't know whether the sqrt is correct
# window the heightmap heightmap *= bw2d
 Gary R.
Hi, Gary Ruben wrote:
import numpy as np import scipy.signal as ss
# read heightmap here  in my case it's a square numpy float array
# build 2d window hm_len = heightmap.shape[0] bw2d = np.outer(ss.hamming(hm_len), np.ones(hm_len)) bw2d = np.sqrt(bw2d * bw2d.T) # I don't know whether the sqrt is correct
# window the heightmap heightmap *= bw2d
 Gary R.
Thanks very much for your solution, this is exactly what I needed! If I'm not mistaken, though, you can achieve the same result with
h = hamming(n) ham2d = sqrt(outer(h,h))
which is a bit more compact.
Regards, Henrik
Henrik Ronellenfitsch wrote: <snip>
Thanks very much for your solution, this is exactly what I needed! If I'm not mistaken, though, you can achieve the same result with
h = hamming(n) ham2d = sqrt(outer(h,h))
which is a bit more compact.
Regards, Henrik
Yes, that's nicer.
regards, Gary
participants (2)

Gary Ruben

Henrik Ronellenfitsch