在numpy中使用as_strided函数的滑动窗口?

Sliding window using as_strided function in numpy?(在numpy中使用as_strided函数的滑动窗口?)
本文介绍了在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 暗矩阵.前两个代表图像的 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)

step代表两个连续窗口之间的位移.

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

如果我选择方形滑动窗口,这种表示效果很好.但我仍然有一个问题要让它适用于 e.x. 的 Windows.(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.

我的代码有什么问题.有任何想法吗?是否有更好的方法在 python 中让滑动窗口美观整洁地进行图像处理?

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函数的滑动窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Generate a sequence by appending values without clash in other values(通过在不与其他值冲突的情况下追加值来生成序列)
How to concatenate two columns containing list (series) in Pandas(如何在Pandas中连接包含List(Series)的两列)
How to speed up groupby().sum() on a dask dataframe with 5 millions of rows and 500 thousands of groups?(如何在具有500万行和50万组的Dask数据帧上加速groupby().sum()?)
How to generate sequence but avoid numbering duplicates in groups?(如何在生成序列的同时避免分组编号重复?)
quot;TypeError: Cannot convert bool to numpy.ndarrayquot; when grouping by multiple columns(TypeError:按多列分组时,无法将bool转换为numpy.ndarrayquot;)
Python Dataframe Groupby Mean and STD(Python Dataframe Groupby Mean和Std)