image-ndarray
Zero-copy implementations for the Image crate to convert to and from ndarrays.
Working with ndarrays allows for easy manipulation of pixel values.
While there is another crate called ndarray-image, that works with dedicated types.
This crate does not and implements the methods directly onto the ImageBuffer objects.
Usage
Add the crate to your project:
Then in your project, when you want to use the ndarrays on the images, make sure to add the prelude:
use *;
Example
Adding a simple value:
use Rgba32FImage;
use *;
let mut my_image = new;
assert!;
let mut array = my_image.as_ndarray_mut;
array += 1.0;
assert!;
Adding another image:
use Rgba32FImage;
use *;
let mut my_image = new;
let second_image = from_vec.unwrap;
assert!;
let mut array = my_image.as_ndarray_mut;
array += &second_image.as_ndarray;
assert!;
Dividing another image (just any math operation supported by ndarray):
use Rgba32FImage;
use *;
let mut my_image = from_vec.unwrap;
let second_image = from_vec.unwrap;
assert!;
let mut array = my_image.as_ndarray_mut;
array /= &second_image.as_ndarray;
assert!;
Convert image to array:
use Rgba32FImage;
use *;
let my_image = from_vec.unwrap;
let array = my_image.to_ndarray;
assert!;
Or just create an image from the provided array:
use Rgba32FImage;
use *;
use Array3;
let array = from_elem;
let my_image = from_ndarray.unwrap;
assert!;
And convert an u8 image into a f32 array:
use *;
use Array3;
let array = from_elem;
let float_array = array.map;
let max_value = float_array.iter.cloned.fold;
assert!;