Skip to content

Latest commit

 

History

History
37 lines (23 loc) · 1.16 KB

image_contrast.md

File metadata and controls

37 lines (23 loc) · 1.16 KB

Image Contrast

Contrast of an image means how different the image's pixels are. The pixels in a low contrast image look similar to each other. High contrast image makes its pixels differ a lot.

We can use adjust_contrast to control the contrast of an image.

fn main() {
    let img = image::open("my_image.jpg").unwrap();
    
    let img2 = img.adjust_contrast(20.);
    img2.save("adjust_contrast_positive.jpg").unwrap();
    
    let img3 = img.adjust_contrast(-20.);
    img3.save("adjust_contrast_negative.jpg").unwrap();
}

A positive parameter of adjust_contrast increases the contrast and a negative parameter decreases the contrast.

Original image:

my_image

adjust_contrast_positive.jpg:

adjust_contrast_positive

adjust_contrast_negative.jpg:

adjust_contrast_negative

➡️ Next: Blurring Images

📘 Back: Table of contents