nshare icon indicating copy to clipboard operation
nshare copied to clipboard

To image?

Open maufl opened this issue 4 years ago • 2 comments

I tried to figure out how to use this crate to convert a Array2 to and grayscale image, and I found the ToImageLuma trait. It seems like this trait is not implemented by anything, right? So this crate does not provide conversions to images?

maufl avatar Jan 02 '22 18:01 maufl

@maufl It does not directly support it, but a trick you can do until someone implements it is that you can use the following:

https://docs.rs/nshare/0.8.0/nshare/trait.MutNdarray2.html#impl-MutNdarray2-for-%26%27a%20mut%20ImageBuffer%3CLuma%3CA%3E%2C%20Container%3E

This implementation allows you to take a luma image buffer and get an ndarray 2d mutable slice over it. You can then easily copy the data from one ndarray to the other using assign: https://docs.rs/ndarray/0.15.4/ndarray/struct.ArrayBase.html#method.assign

Contributions are absolutely welcome as well if you would like to implement it.

vadixidav avatar Jan 02 '22 18:01 vadixidav

Thanks for the quick response! I can give it a try, I'm not yet feeling to comfortable with ndarray though.

maufl avatar Jan 02 '22 20:01 maufl