Skip to content

Kuuuube/image_mapping

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image Mapping

Transform images using arbitrary functions.

Usage

Note: This is very much a developer tool. There are no options. You may edit the code to change functionality.

  • In the directory you are running the tool, create a directory named output and place an image named source.png.

  • Run cargo run --release. You may want to always build release for this project due how much computation happens. Debug builds will be significantly slower.

Dependencies

Rust: https://www.rust-lang.org/tools/install

Notes

  • By default, it will try to run every transformation on source.png. Here is an example of how to set it to run a single transformation instead:

    fn main() {
        let source_image = image::open("source.png").unwrap().into_rgba8();
        let output_size = transformer::Size { width: 2000, height: 2000, };
        batch_runners::basic_runner_wrapper(
            "square_fg_squircular", // This controls the output filename. You can set this to anything you want.
            &source_image,
            Some(output_size), // Set to `None` to use the source image's size as the output size.
            transformations::circle_to_square::fg_squircular,
        );
    }
  • To run a mapping with your own custom arbitrary transformation:

    fn main() {
        let source_image = image::open("source.png").unwrap().into_rgba8();
        let output_size = transformer::Size { width: 2000, height: 2000, };
        batch_runners::basic_runner_wrapper(
            "awesome_transformation", // This controls the output filename. You can set this to anything you want.
            &source_image,
            Some(output_size), // Set to `None` to use the source image's size as the output size.
            awesome_transformation_function, // Put any function here that takes in a `transformer::Point` and returns a `transformer::Point`.
        );
    }
    
    fn awesome_transformation_function(point: transformer::Point) -> transformer::Point {
        return transformer::Point { x: point.x * 2.0, y: point.y * 2.0 };
    }

    If you need more control, use transformer::transform_image directly:

    fn main() {
        let source_image = image::open("source.png").unwrap().into_rgba8();
        let output_size = transformer::Size { width: 2000, height: 2000, };
        transformer::transform_image(&source_image, Some(output_size), |point| {
            awesome_transformation_function(point)
        })
        .save(&format!("output/{}.png", "awesome_transformation"))
        .expect(&format!("Failed to generate {}", "awesome_transformation"));
    }
    
    fn awesome_transformation_function(point: transformer::Point) -> transformer::Point {
        return transformer::Point { x: point.x * 2.0, y: point.y * 2.0 };
    }
  • With some mappings can end up with "holes" leftover from the stretching. Scaling the output size of the image down a bit can help alleviate this.

About

Transform images using arbitrary functions.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Packages

No packages published

Languages