title: Sliding window using as_strided function in numpy?
body: <p>As I get to implement a sliding window using python to detect objects in still images, I get to know the nice function:</p>
  
  <pre><code>numpy.lib.stride_tricks.as_strided
  </code></pre>
  
  <p>So I tried to achieve a general rule to avoid mistakes I may fail in while changing the size of the sliding windows I need. Finally I got this representation:</p>
  
  <pre><code>all_windows = as_strided(x,((x.shape[0] - xsize)/xstep ,(x.shape[1] - ysize)/ystep ,xsize,ysize), (x.strides[0]*xstep,x.strides[1]*ystep,x.strides[0],x.strides[1])
  </code></pre>
  
  <p>which results in a 4 dim matrix. The first two represents the number of windows on the x and y axis of the image. and the others represent the size of the window (xsize,ysize)</p>
  
  <p>and the <code>step</code> represents the displacement from between two consecutive windows.</p>
  
  <p>This representation works fine if I choose a squared sliding windows. but still I have a problem in getting this to work for windows of e.x. (128,64), where I get usually unrelated data to the image.</p>
  
  <p>What is wrong my code. Any ideas? and if there is a better way to get a sliding windows nice and neat in python for image processing?</p>
  
  <p>Thanks</p>