You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think these 2 matlab function im2col and col2im, which rearrange image block to columns and rearrange back, are quite useful. I don't find similar one on numpy or scipy.
Any chance these can be added in future version? If so, I can work on their implementation.
Something like res = np.lib.stride_tricks.sliding_window_view(arr, shape, axis=None), with semantics:
axis is None implies axes = tuple(range(arr.ndim))
Integer axis and shape are promoted to one-element tuples
len(axis) == len(shape)
res.shape == shape + arr.shape (arguably more useful for broadcasting than (arr.shape + shape))
We could perhaps resolve this by having shape be passed as (..., 1, 2, 3) or (1, 2, 3, ...), and have Ellipsis replaced with arr.shape, but there's no precedent for this yet.
The matlab example you link to would become:
a=np.linspace(0,1,16).reshape(4, 4)
b=np.lib.stride_tricks.sliding_window_view(arr, (2,2)) # or (2, 2, Ellipsis)new_a=b.mean(axis=(0,1))
We could consider adding a strides argument later, but I think we should leave it out of the initial proposal
Activity
shoyer commentedon Mar 16, 2018
These are too specialized for NumPy.
Maybe they would be appropriate for an image processing library like skimage?
eric-wieser commentedon Mar 16, 2018
This sounds similar to the common sliding window request, which I think would be suitable for numpy in
stride_tricks, if we can pin down an API.fanjin-z commentedon Mar 16, 2018
@shoyer Not just image processing, these 2 function are useful for doing customized convolution.
@eric-wieser It's indeed a sliding window rearragement into columns. 'stride_tricks' could be suitable.
eric-wieser commentedon Mar 16, 2018
Something like
res = np.lib.stride_tricks.sliding_window_view(arr, shape, axis=None), with semantics:axis is Noneimpliesaxes = tuple(range(arr.ndim))axisandshapeare promoted to one-element tupleslen(axis) == len(shape)res.shape == shape + arr.shape(arguably more useful for broadcasting than(arr.shape + shape))We could perhaps resolve this by having shape be passed as
(..., 1, 2, 3)or(1, 2, 3, ...), and haveEllipsisreplaced witharr.shape, but there's no precedent for this yet.The matlab example you link to would become:
We could consider adding a
stridesargument later, but I think we should leave it out of the initial proposaleric-wieser commentedon Mar 16, 2018
Closing as a dupe of #7753