在numpy中使用as_strided函数滑动窗口? [英] Sliding window using as_strided function in numpy?

查看:5506
本文介绍了在numpy中使用as_strided函数滑动窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用python来实现一个滑动窗口来检测静态图片中的对象时,我会得到一个很好的函数:

As I get to implement a sliding window using python to detect objects in still images, I get to know the nice function:

numpy.lib.stride_tricks.as_strided

所以我试图实现一般规则来避免错误可能会失败,同时改变我需要的滑动窗口的大小。最后我得到这个表示:

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:

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])

这将产生一个4 dim矩阵,前两个表示x上的窗口数, y轴,其他代表窗口大小(xsize,ysize)

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)

步骤表示两个连续窗口之间的位移。

and the step represents the displacement from between two consecutive windows.

如果我选择一个平方滑动窗口,这种表示方法可以正常工作,但仍然有一个问题, of ex(128,64),其中我通常与图像无关的数据。

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.

我的代码有什么问题。任何想法?如果有更好的方法

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?

感谢

推荐答案

查看此问题的答案:使用步幅高效移动平均滤波器。基本上步幅不是一个伟大的选择,虽然他们工作。

Check out the answers to this question: Using strides for an efficient moving average filter. Basically strides are not a great option, although they work.

这篇关于在numpy中使用as_strided函数滑动窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆