Skip to main content

warp/
main.rs

1use aikit::warp_into;
2use image::{Rgb, RgbImage, Rgba32FImage};
3use nalgebra::{Matrix3, Vector2};
4
5pub fn read_rgb_image(image_path: &str) -> Rgba32FImage {
6    let image = image::open(image_path).unwrap().to_rgba32f();
7
8    return image;
9}
10
11fn to_rgb8(image: Rgba32FImage) -> RgbImage {
12    let output = RgbImage::from_fn(image.width(), image.height(), |i, j| {
13        let px = image.get_pixel(i, j);
14        let p = px.0;
15
16        Rgb::<u8>([
17            (p[0] * 255.0) as u8,
18            (p[1] * 255.0) as u8,
19            (p[2] * 255.0) as u8,
20        ])
21    });
22
23    output
24}
25
26fn main() {
27    let input = read_rgb_image("t1.jpg");
28    let mut output = Rgba32FImage::new(256, 256);
29
30    let mut matrix = Matrix3::identity();
31
32    matrix = matrix.append_translation(&Vector2::new(-100f32, 0f32));
33
34    warp_into(&input, matrix, &mut output);
35
36    _ = to_rgb8(output).save("saved_t1.jpg");
37}