Skip to content

Correct (fast) way to convert Array2<RGBA8> into Array3<u8>? #1125

@fzyzcjy

Description

@fzyzcjy

Hi thanks for the lib!

Context: I have a color image Array2<RGBA8>, and want to visualize it using rust-numpy lib (a binding to python numpy). However, .to_pyarray() complains, so I should convert it into Array3<u8>.

Question: How can I do that - what is the correct/fast way to do so? IMHO the fastest way should even have no memory copy at all, since RGBA8 is compact 4-byte data. But one memory copy is also acceptable.

I have come up with a very slow method but I hope there are other ways: extract Array2<RGBA8> into four Array<u8> for each of 4 channels, and stack! them together. Its performance seems to be quite slow.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions