pub struct ImageProcessor;Expand description
Processor for image binarization operations
Provides functionaility to convert images to binary format using Otsu’s thresholding method with parallel processing.
Implementations§
Source§impl ImageProcessor
impl ImageProcessor
Sourcepub fn process_image(
image_path: &str,
processing_method: ImageProcessingMethod,
) -> Result<ImageBuffer<Luma<u16>, Vec<u16>>, Box<dyn Error>>
pub fn process_image( image_path: &str, processing_method: ImageProcessingMethod, ) -> Result<ImageBuffer<Luma<u16>, Vec<u16>>, Box<dyn Error>>
Loads an image, converts it to grayscale, and binarizes it using Otsu’s method
§Arguments
image_path- Path to the input image file
§Returns
Ok(ImageBuffer): Binary image buffer with white pixels (255) where original > threshold, black(0) otherwiseErr: If image loading fails or buffer creation fails
§Process
- Load image from path
- Convert to 16-bit grayscale
- Calculate Otsu threshold
- Apply threshold in parallel to create binary image
- Return new image buffer
§Example
let binary_img = ImageProcessor::process_image("input.png")?;
binary_img.save("binary.png")?;Sourcepub fn calculate_otsu_threshold(img: &ImageBuffer<Luma<u16>, Vec<u16>>) -> u16
pub fn calculate_otsu_threshold(img: &ImageBuffer<Luma<u16>, Vec<u16>>) -> u16
Calculates optimal threshold for binarization using Otsu’s method
§Arguments
img- 16-bit grayscale image reference
§Returns
Optimal threshold value (0-65535) that maximizes inter-class variance
§Process
- Build 16-bit histogram (0-65535)
- Iterate all possible thresholds:
- Split histogram into foreground/background
- Calculate class weights and means
- Compute between-class variance
- Return threshold with maximum variance
pub fn calculate_kapur_threshold(img: &ImageBuffer<Luma<u16>, Vec<u16>>) -> u16
pub fn calculate_sauvola_threshold( img: &ImageBuffer<Luma<u16>, Vec<u16>>, ) -> u16
pub fn calculate_bernsen_threshold( img: &ImageBuffer<Luma<u16>, Vec<u16>>, ) -> u16
pub fn calculate_wolf_threshold(img: &ImageBuffer<Luma<u16>, Vec<u16>>) -> u16
Auto Trait Implementations§
impl Freeze for ImageProcessor
impl RefUnwindSafe for ImageProcessor
impl Send for ImageProcessor
impl Sync for ImageProcessor
impl Unpin for ImageProcessor
impl UnsafeUnpin for ImageProcessor
impl UnwindSafe for ImageProcessor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more