Skip to content

[Feature Request] im2col and col2im #10754

Closed

Description

@fanjin-z

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.

Activity

  1. shoyer commented on Mar 16, 2018

    @shoyer
    Member

    These are too specialized for NumPy.

    Maybe they would be appropriate for an image processing library like skimage?

  2. eric-wieser commented on Mar 16, 2018

    @eric-wieser
    Member

    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.

  3. fanjin-z commented on Mar 16, 2018

    @fanjin-z
    Author

    @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.

  4. eric-wieser commented on Mar 16, 2018

    @eric-wieser
    Member

    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

  5. eric-wieser commented on Mar 16, 2018

    @eric-wieser
    Member

    Closing as a dupe of #7753

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions