编辑:这是一个图像,所以建议的(How can I efficiently process a numpy array in blocks similar to Matlab's blkproc (blockproc) function)对我来说不太合适
我有下面的matlab代码
fun = @(block_struct) ...
std2(block_struct.data) * ones(size(block_struct.data));
B=blockproc(im2double(Icorrected), [4 4], fun);
我想重新编写代码,但这次是用Python编写的。我已经安装了Scikit,我正努力解决这个问题
^{pr2}$问题当然是我并没有像上面一样,在很多街区都应用std。在
我怎么能做这样的事?启动一个循环并尝试为每个X*X块调用函数?那我就不会保持原来的尺寸了。在
有没有其他更有效的方法?在
我做了以下事情
我认为这是正确的。在图像上迭代2,取每个相邻节点,将它们添加到一个列表中并计算std
编辑*稍后编辑4x4块。在
如果窗口中没有重叠,则可以根据需要重新调整数据形状:
求9x9数组的3x3个窗口的平均值。在
找到新形状
^{pr2}$沿第一轴和第三轴求平均值。在
4x4阵列的2x2个窗口:
如果窗口大小不均匀地划分为数组大小,它将不起作用。在这种情况下,您需要在窗口中进行一些重叠,或者如果您只希望重叠
numpy.lib.stride_tricks.as_strided
是一种可行的方法,一个通用的N-D函数可以在Efficient Overlapping Windows with Numpy找到2d数组的另一个选项是sklearn.feature_extraction.image.extract_patches_2d和ndarray的-sklearn.feature_extraction.image.extract_patches。每一个操作数组的步进以生成补丁/窗口。在
相关问题 更多 >
编程相关推荐