Crates.io | imgproc-rs |
lib.rs | imgproc-rs |
version | 0.3.0 |
source | src |
created_at | 2021-02-03 00:14:48.878455 |
updated_at | 2021-12-07 07:12:15.095123 |
description | Image processing library for Rust |
homepage | https://github.com/tiffany1618/imgproc-rs |
repository | https://github.com/tiffany1618/imgproc-rs |
max_upload_size | |
id | 349928 |
size | 173,710 |
A Rust image processing library.
imgproc-rs
uses the i/o functions provided in the image
crate. A list of
supported image formats can be found here.
use imgproc_rs::io;
fn main() {
// Read an image from a path
let img = io::read("path/to/some_image.png").unwrap();
// Print image information
println!("{:?}", img.info());
// Write the image to a path as a PNG
io::write(&img, "path/to/save_image.png").unwrap();
}
Images can be created from existing vectors, slices, vectors of vectors, and vectors of slices. A few examples are shown below.
use imgproc_rs::image::{Image, ImageInfo};
fn main() {
let vec = vec![1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12];
// Create an image from a slice
let img_slice = Image::from_slice(2, 2, 3, false, &vec);
// Create an image from a vector
let img_vec = Image::from_vec(2, 2, 3, false, vec);
// Create a blank (black) image
let img_blank: Image<u8> = Image::blank(ImageInfo::new(2, 2, 3, false));
// Create an empty image
let img_empty: Image<u8> = Image::empty(ImageInfo::new(2, 2, 3, false));
}
use imgproc_rs::io;
use imgproc_rs::image::{Image, ImageInfo};
fn main() {
let img = io::read("path/to/some_image.png").unwrap();
// Get width and height of image
let (width, height) = img.info().wh();
// Get width, height, and channels of image
let (width, height, channels) = img.info().whc();
// Get width, height, channels, and alpha of image
let (width, height, channels, alpha) = img.info().whca();
/* Print image information
* Example output:
*
* width: 2
* height: 2
* channels: 3
* alpha: false
*
*/
println!("{}", img.info());
}
Image pixels can be accessed using either 1D or 2D indexing. 1D indexing reads the image data row by row from left to right, starting in the upper left corner of the image. 2D coordinates start at zero in the upper left corner of the image and increase downwards and to the right.
use imgproc_rs::io;
use imgproc_rs::image::{Image, BaseImage};
fn main() {
let img = io::read("path/to/some_image.png").unwrap();
// Set an image pixel using a 1D index
img.set_pixel_indexed(0, &[1, 1, 1]);
// Get an image pixel using a 1D index
let pixel_1d = &img[0];
// Set an image pixel using 2D coordinates
img.set_pixel(1, 1, &[1, 1, 1]);
// Get an image pixel using 2D coordinates
let pixel_2d = img.get_pixel(1, 1);
}
To enable multithreading, include the parallel
feature in your Cargo.toml
:
[dependencies.imgproc-rs]
version = "0.3.0"
default-features = false
features = ["parallel"]
Alternatively, pass the features flag to cargo run
:
cargo run --features parallel
transform
module
crop
scale
scale_lanczos
filter
module, except:
threshold
residual
median_filter
alpha_trimmed_mean_filter
SIMD support is enabled by default via the simd
feature. Supported functions will only use SIMD where AVX2 is
supported (x86/x86_64
); otherwise an alternate implementation is used.
simd
module)tone::brightness()
tone::saturation()
colorspace::rgb_to_grayscale()