Created
April 25, 2023 02:29
-
-
Save tuna2134/85e1b7c97b971c22221e91cc66ef8fef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use image::{DynamicImage, GenericImageView}; | |
| use ndarray::{Array, Array3, Axis}; | |
| fn image_to_ndarray(img: &DynamicImage) -> Array3<u8> { | |
| let (width, height) = img.dimensions(); | |
| let mut data = vec![0u8; (width * height * 3) as usize]; | |
| img.to_rgb8().into_raw().iter().enumerate().for_each(|(i, pixel)| { | |
| data[i] = *pixel; | |
| }); | |
| Array::from_shape_vec((height as usize, width as usize, 3), data).unwrap().reversed_axes() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment