pub fn dev_image_to_glyph_set(
    image: &RgbImage,
    only_line: Option<usize>,
    colors: &[crate::RGB],
    out_dir: &Option<&str>,
) -> GlyphSet {
    let mut result: GlyphSet = Default::default();

    optionally_save_image(&image, out_dir, "dev_histogram_input.png");

    // let filtered = filter_white(image);
    let image_colors = colors.iter().map(|x| x.to_rgb()).collect::<Vec<Rgb<u8>>>();
    let filtered = filter_colors(image, &image_colors);

    optionally_save_image(&filtered, out_dir, "dev_histogram_filter_white.png");

    let mut lines = line_splitter(&filtered);

    let image_with_rect = image.clone();

    // let mut image_with_rect = filter_white(&image_with_rect);
    let mut image_with_rect = filter_colors(&image_with_rect, &image_colors);
    for b in lines.iter() {
        image_with_rect =
            imageproc::drawing::draw_hollow_rect(&image_with_rect, *b, Rgb([255u8, 0u8, 255u8]));
    }
    optionally_save_image(&image_with_rect, out_dir, "dev_histogram_lines.png");

    if let Some(index) = only_line {
        lines = vec![lines[index]];
    }

    for (r, b) in lines.iter().enumerate() {
        let sub_img = image::SubImage::new(
            &filtered,
            b.left() as u32,
            b.top() as u32,
            b.width(),
            b.height(),
        );
        result.line_height = std::cmp::max(result.line_height, b.height());
        let sub_img = sub_img.to_image();
        let tokens = token_splitter(&sub_img);
        {
            let row_img_gray = image::DynamicImage::ImageRgb8(sub_img).into_luma8();
            let row_img_histogram = image_to_histogram(&row_img_gray);
            println!("row {r} -> {row_img_histogram:?}");
        }

        for (c, z) in tokens.iter().enumerate() {
            let filtered_token = image::GenericImageView::view(
                &filtered,
                z.left() as u32,
                b.top() as u32,
                z.width(),
                z.height(),
            );
            let sub_img_gray =
                image::DynamicImage::ImageRgb8(filtered_token.to_image()).into_luma8();
            let sub_img_histogram = image_to_histogram(&sub_img_gray);

            let mut drawable = image::GenericImage::sub_image(
                &mut image_with_rect,
                b.left() as u32,
                b.top() as u32,
                b.width(),
                b.height(),
            );
            imageproc::drawing::draw_hollow_rect_mut(&mut drawable, *z, Rgb([0u8, 255u8, 255u8]));
            draw_histogram_mut_xy_a(
                &mut image_with_rect,
                z.left() as u32,
                b.bottom() as u32 - if b.bottom() > 1 { 1 } else { 0 },
                &sub_img_histogram,
                Rgb([255u8, 0u8, 0u8]),
                0.5,
            );
            let _global_rect =
                Rect::at(b.left() + z.left(), b.top() + z.top()).of_size(z.width(), z.height());

            result
                .entries
                .push(Glyph::new(&sub_img_histogram, &format!("{r}-{c}")));
        }
    }
    optionally_save_image(&image_with_rect, out_dir, "dev_histogram_boxes.png");

    result.prepare();
    result
}
/// Something that analyses an image with glyphs on it, creating the glyphset with histograms.
Something that analyses an image with glyphs on it, creating the glyphset with histograms.
Something that analyses an image with glyphs on it creating the glyphset with histograms .
pub fn dev_image_to_glyph_set(
    image: &RgbImage,
    only_line: Option<usize>,
    colors: &[crate::RGB],
    out_dir: &Option<&str>,
) -> GlyphSet {
    let mut result: GlyphSet = Default::default();
    optionally_save_image(&image, out_dir, "dev_histogram_input.png");
    // let filtered = filter_white(image);
    let image_colors = colors.iter().map(|x| x.to_rgb()).collect::<Vec<Rgb<u8>>>();
    let filtered = filter_colors(image, &image_colors);
    optionally_save_image(&filtered, out_dir, "dev_histogram_filter_white.png");
    let mut lines = line_splitter(&filtered);
    let image_with_rect = image.clone();
    // let mut image_with_rect = filter_white(&image_with_rect);
    let mut image_with_rect = filter_colors(&image_with_rect, &image_colors);
    for b in lines.iter() {
        image_with_rect =
            imageproc::drawing::draw_hollow_rect(&image_with_rect, *b, Rgb([255u8, 0u8, 255u8]));
    }
    optionally_save_image(&image_with_rect, out_dir, "dev_histogram_lines.png");
    if let Some(index) = only_line {
        lines = vec![lines[index]];
    }
    for (r, b) in lines.iter().enumerate() {
        let sub_img = image::SubImage::new(
            &filtered,
            b.left() as u32,
            b.top() as u32,
            b.width(),
            b.height(),
        );
        result.line_height = std::cmp::max(result.line_height, b.height());
        let sub_img = sub_img.to_image();
        let tokens = token_splitter(&sub_img);
        {
            let row_img_gray = image::DynamicImage::ImageRgb8(sub_img).into_luma8();
            let row_img_histogram = image_to_histogram(&row_img_gray);
            println!("row {r} -> {row_img_histogram:?}");
        }
        for (c, z) in tokens.iter().enumerate() {
            let filtered_token = image::GenericImageView::view(
                &filtered,
                z.left() as u32,
                b.top() as u32,
                z.width(),
                z.height(),
            );
            let sub_img_gray =
                image::DynamicImage::ImageRgb8(filtered_token.to_image()).into_luma8();
            let sub_img_histogram = image_to_histogram(&sub_img_gray);
            let mut drawable = image::GenericImage::sub_image(
                &mut image_with_rect,
                b.left() as u32,
                b.top() as u32,
                b.width(),
                b.height(),
            );
            imageproc::drawing::draw_hollow_rect_mut(&mut drawable, *z, Rgb([0u8, 255u8, 255u8]));
            draw_histogram_mut_xy_a(
                &mut image_with_rect,
                z.left() as u32,
                b.bottom() as u32 - if b.bottom() > 1 { 1 } else { 0 },
                &sub_img_histogram,
                Rgb([255u8, 0u8, 0u8]),
                0.5,
            );
            let _global_rect =
                Rect::at(b.left() + z.left(), b.top() + z.top()).of_size(z.width(), z.height());
            result
                .entries
                .push(Glyph::new(&sub_img_histogram, &format!("{r}-{c}")));
        }
    }
    optionally_save_image(&image_with_rect, out_dir, "dev_histogram_boxes.png");
    result.prepare();
    result
}
pub fn dev_image_to_glyph_set ( image : & RgbImage , only_line : Option < usize > , colors : & [ crate :: RGB ] , out_dir : & Option < & str > , ) -> GlyphSet { let mut result : GlyphSet = Default :: default ( ) ; optionally_save_image ( & image , out_dir , " " ) ; // let filtered = filter_white(image); let image_colors = colors . iter ( ) . map ( | x | x . to_rgb ( ) ) . collect :: < Vec < Rgb < u8 > > > ( ) ; let filtered = filter_colors ( image , & image_colors ) ; optionally_save_image ( & filtered , out_dir , " " ) ; let mut lines = line_splitter ( & filtered ) ; let image_with_rect = image . clone ( ) ; // let mut image_with_rect = filter_white(&image_with_rect); let mut image_with_rect = filter_colors ( & image_with_rect , & image_colors ) ; for b in lines . iter ( ) { image_with_rect = imageproc :: drawing :: draw_hollow_rect ( & image_with_rect , * b , Rgb ( [ 255u8 , 0u8 , 255u8 ] ) ) ; } optionally_save_image ( & image_with_rect , out_dir , " " ) ; if let Some ( index ) = only_line { lines = vec ! [ lines [ index ] ] ; } for ( r , b ) in lines . iter ( ) . enumerate ( ) { let sub_img = image :: SubImage :: new ( & filtered , b . left ( ) as u32 , b . top ( ) as u32 , b . width ( ) , b . height ( ) , ) ; result . line_height = std :: cmp :: max ( result . line_height , b . height ( ) ) ; let sub_img = sub_img . to_image ( ) ; let tokens = token_splitter ( & sub_img ) ; { let row_img_gray = image :: DynamicImage :: ImageRgb8 ( sub_img ) . into_luma8 ( ) ; let row_img_histogram = image_to_histogram ( & row_img_gray ) ; println ! ( " " ) ; } for ( c , z ) in tokens . iter ( ) . enumerate ( ) { let filtered_token = image :: GenericImageView :: view ( & filtered , z . left ( ) as u32 , b . top ( ) as u32 , z . width ( ) , z . height ( ) , ) ; let sub_img_gray = image :: DynamicImage :: ImageRgb8 ( filtered_token . to_image ( ) ) . into_luma8 ( ) ; let sub_img_histogram = image_to_histogram ( & sub_img_gray ) ; let mut drawable = image :: GenericImage :: sub_image ( & mut image_with_rect , b . left ( ) as u32 , b . top ( ) as u32 , b . width ( ) , b . height ( ) , ) ; imageproc :: drawing :: draw_hollow_rect_mut ( & mut drawable , * z , Rgb ( [ 0u8 , 255u8 , 255u8 ] ) ) ; draw_histogram_mut_xy_a ( & mut image_with_rect , z . left ( ) as u32 , b . bottom ( ) as u32 - if b . bottom ( ) > 1 { 1 } else { 0 } , & sub_img_histogram , Rgb ( [ 255u8 , 0u8 , 0u8 ] ) , 0.5 , ) ; let _global_rect = Rect :: at ( b . left ( ) + z . left ( ) , b . top ( ) + z . top ( ) ) . of_size ( z . width ( ) , z . height ( ) ) ; result . entries . push ( Glyph :: new ( & sub_img_histogram , & format ! ( " " ) ) ) ; } } optionally_save_image ( & image_with_rect , out_dir , " " ) ; result . prepare ( ) ; result }
Something that analyses an image with glyphs on it, creating the glyphset with histograms.
Something that analyses an image with glyphs on it creating the glyphset with histograms .
image
&RgbImage
only_line
Option<usize>
colors
&[crate::RGB]
out_dir
&Option<&str>