From f1837fb8ce3ef4950b4c52fb287f7ee7f71c025d Mon Sep 17 00:00:00 2001 From: Li Fengmin <2080291162@qq.com> Date: Fri, 31 Jul 2026 19:35:57 +0800 Subject: [PATCH] feat: public histogram API (luma + per-channel RGB) --- histogram.mbt | 32 +++++++++++++++++ histogram_test.mbt | 86 ++++++++++++++++++++++++++++++++++++++++++++++ pkg.generated.mbti | 2 ++ 3 files changed, 120 insertions(+) create mode 100644 histogram.mbt create mode 100644 histogram_test.mbt diff --git a/histogram.mbt b/histogram.mbt new file mode 100644 index 0000000..015035c --- /dev/null +++ b/histogram.mbt @@ -0,0 +1,32 @@ +///| +/// Public histogram API. The luma histogram reuses the same 256-bin +/// BT.601 integer binning that Otsu and histogram equalization are built +/// on, so every consumer of the library sees one consistent definition. + +///| +/// 256-bin luma histogram (BT.601 integer weights): `result[v]` counts the +/// pixels whose luma is exactly `v`. +pub fn Image::histogram_luma(self : Image) -> FixedArray[Int] { + self.luma_histogram() +} + +///| +/// Per-channel 256-bin histograms, returned as `(red, green, blue)`. +pub fn Image::histogram_rgb( + self : Image, +) -> (FixedArray[Int], FixedArray[Int], FixedArray[Int]) { + let hr = FixedArray::make(256, 0) + let hg = FixedArray::make(256, 0) + let hb = FixedArray::make(256, 0) + let n = self.pixel_count() + for p in 0.. Self pub fn Image::get_pixel(Self, Int, Int) -> (Byte, Byte, Byte, Byte) pub fn Image::grayscale(Self) -> Self pub fn Image::histogram_equalize(Self) -> Self +pub fn Image::histogram_luma(Self) -> FixedArray[Int] +pub fn Image::histogram_rgb(Self) -> (FixedArray[Int], FixedArray[Int], FixedArray[Int]) pub fn Image::hue_rotate(Self, Double) -> Self pub fn Image::integral_image(Self) -> Integral pub fn Image::invert(Self) -> Self