Skip to content

Feature: Faster version of cv2.mixChannels #247

@ternaus

Description

@ternaus

Describe what you are looking for

There is a transform in Albumentations, called ChannelShuffle, it takes numpy array and shuffles channels.

Could be done in cv2:

def channel_shuffle(img: np.ndarray, channels_shuffled: np.ndarray) -> np.ndarray:    
    from_to = []
    for i, j in enumerate(channels_shuffled):
        from_to.extend([i, j])
    cv2.mixChannels([img], [img], from_to)
    return img

in numpy

def channel_shuffle(img: np.ndarray, channels_shuffled: np.ndarray) -> np.ndarray:
    return img[..., channels_shuffled]

The request it have similar operation in simsimd that can:

  • runs inplace (cv2 version runs inplace)
  • can work with any shape, say (height, width, num_channels) or (depth, height, width, num, channels), or (num_volumes, depth, height, width, num_channels)) (numpy allows this, cv2 does not, but it could be achieved with reshape)
  • The most important: Run faster, as right now, benchmark shows that torchvision performs this operation on tensors faster than OpenCV on numpy arrays.

Can you contribute to the implementation?

  • I can contribute

Is your feature request specific to a certain interface?

Python bindings

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions