basic working otsu number binarizer

This commit is contained in:
Henry Schimke
2023-02-02 18:57:54 -06:00
parent 0ccb222b1a
commit 66543f9098
5 changed files with 112 additions and 1 deletions

View File

@@ -709,6 +709,22 @@ impl fmt::Display for BitMatrix {
}
}
#[cfg(feature = "image")]
/// This should only be used if you *know* that the `DynamicImage` is binary.
impl TryFrom<image::DynamicImage> for BitMatrix {
type Error = Exceptions;
fn try_from(value: image::DynamicImage) -> Result<Self, Self::Error> {
let mut new_bitmatrix = BitMatrix::new(value.width(), value.height())?;
for (x, y, value) in value.as_luma8().unwrap().enumerate_pixels() {
if value.0[0] != u8::MAX {
new_bitmatrix.set(x, y)
}
}
Ok(new_bitmatrix)
}
}
#[cfg(feature = "image")]
impl From<BitMatrix> for image::DynamicImage {
fn from(value: BitMatrix) -> Self {