fn convert_u32_to_u8_img(image: Image<Luma<u32>>) -> GrayImage {
    let (width, height) = image.dimensions();
    let mut out: GrayImage = ImageBuffer::new(width, height);

    let max_value = image.pixels().fold(0u32, |max, px| max.max(px[0]));
    let scaler = if max_value > 0 {
        255. / (max_value as f32)
    } else {
        0.
    };

    for y in 0..height {
        for x in 0..width {
            let pixel = unsafe { image.unsafe_get_pixel(x, y) };
            let v = pixel[0].to_f32().unwrap();
            let scaled = (v * scaler).to_u8().unwrap();
            unsafe { out.unsafe_put_pixel(x, y, [scaled].into()) }
        }
    }

    out
}
/// Helper function to map u32 value range to u8 value range.
Helper function to map u32 value range to u8 value range.
Helper function to map u32 value range to u8 value range .
fn convert_u32_to_u8_img(image: Image<Luma<u32>>) -> GrayImage {
    let (width, height) = image.dimensions();
    let mut out: GrayImage = ImageBuffer::new(width, height);
    let max_value = image.pixels().fold(0u32, |max, px| max.max(px[0]));
    let scaler = if max_value > 0 {
        255. / (max_value as f32)
    } else {
        0.
    };
    for y in 0..height {
        for x in 0..width {
            let pixel = unsafe { image.unsafe_get_pixel(x, y) };
            let v = pixel[0].to_f32().unwrap();
            let scaled = (v * scaler).to_u8().unwrap();
            unsafe { out.unsafe_put_pixel(x, y, [scaled].into()) }
        }
    }
    out
}
fn convert_u32_to_u8_img ( image : Image < Luma < u32 > > ) -> GrayImage { let ( width , height ) = image . dimensions ( ) ; let mut out : GrayImage = ImageBuffer :: new ( width , height ) ; let max_value = image . pixels ( ) . fold ( 0u32 , | max , px | max . max ( px [ 0 ] ) ) ; let scaler = if max_value > 0 { 255. / ( max_value as f32 ) } else { 0. } ; for y in 0 .. height { for x in 0 .. width { let pixel = unsafe { image . unsafe_get_pixel ( x , y ) } ; let v = pixel [ 0 ] . to_f32 ( ) . unwrap ( ) ; let scaled = ( v * scaler ) . to_u8 ( ) . unwrap ( ) ; unsafe { out . unsafe_put_pixel ( x , y , [ scaled ] . into ( ) ) } } } out }
Helper function to map u32 value range to u8 value range.
Helper function to map u32 value range to u8 value range .
image
Image<Luma<u32>>
image
Image<Luma<u32>>