(cross post of SO: https://stackoverflow.com/questions/27345861/extending-1d-function-across-3-dimensions-for-data-windowing )

For the sake of image (volume) registration, I'd like to apply a windowing function to input data, such that the non-periodic image boundaries do not cause streaking in the FFT. I'm using the example from here for 2D data:


h = scipy.signal.hamming(n)
ham2d = sqrt(outer(h,h))

Is this extensible to 3D or even N-D?


Yes, a window function just applies a weighting function to your data.

For N-D data you can view the window function as a combination of N 1-D windows which are all orthogonal to each other.

As the weights of the 1-D windows to not depend on the other dimensions you can either apply each separately or combine them to get a single N-D window.

e.g. for 3D (in matlab, it should be simple enough to translate to python)

hammx=hamming(L); %1D window
hamz=permute(hamx, [3, 2, 1]);
ham3=ones(L, L, L);
for i=1:100               % there is probably a much better way to compute this
ham2(i, :)=hamx(i).*hamy;
for j=1:100
ham3(i, j, :)=ham2(i, j).*hamz;
  • $\begingroup$ I have posted my Python code solution on Stack Overflow: stackoverflow.com/questions/27345861/… Thanks for your suggestion. $\endgroup$ – msarahan Dec 21 '14 at 3:02
  • $\begingroup$ I down voted because it only discussed the trivial extension. There are more ways of going from 1d to 2d $\endgroup$ – Stanley Pawlukiewicz Jun 15 '17 at 23:30

this question is old, but I needed same function.

I wrote a function that receive one-dimensional window as parameter and transformed into a cube window

function [win] = window3D(w)

    L = size(w,1);
    m1 = w(:)*w(:).';
    win1 = repmat(m1, [1 1 L]);
    m2 = w(:)*ones(1,L);
    win2 = repmat(m2, [1 1 L]);
    win2 = permute(win2, [3, 2, 1]);
    win = win1.*win2;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.