Class HistogramOp

java.lang.Object
cloud.opencode.base.image.histogram.HistogramOp

public final class HistogramOp extends Object
Histogram Computation Operations 直方图计算操作工具类

Computes histograms for grayscale and color images. Provides per-channel statistics including counts, min, max, and mean values.

计算灰度图像和彩色图像的直方图。提供每个通道的统计信息, 包括计数、最小值、最大值和均值。

Features | 主要功能:

  • Grayscale histogram computation - 灰度直方图计算
  • Per-channel (R, G, B) histogram computation - 逐通道(R、G、B)直方图计算
  • Statistics: min, max, mean per histogram - 统计: 每个直方图的最小值、最大值、均值

Usage Examples | 使用示例:

Raster raster = OpenImage.readRaster(Path.of("photo.png"));
HistogramOp.Histogram gray = HistogramOp.computeGray(raster);
System.out.println("Mean: " + gray.mean());

HistogramOp.Histogram[] rgb = HistogramOp.compute(raster);
// rgb[0] = Red, rgb[1] = Green, rgb[2] = Blue

Performance | 性能特性:

  • Time complexity: O(w * h) - 时间复杂度: O(w * h)
  • Space complexity: O(256) per histogram - 空间复杂度: 每个直方图 O(256)

Security | 安全性:

  • Thread-safe: Yes (stateless) - 线程安全: 是(无状态)
  • Null-safe: No - 空值安全: 否
Since:
JDK 25, opencode-base-image V2.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • computeGray

      public static HistogramOp.Histogram computeGray(Raster raster)
      Compute the grayscale histogram of a Raster. 计算 Raster 的灰度直方图。

      Uses ITU-R BT.601 luminance to derive the gray value of each pixel.

      使用 ITU-R BT.601 亮度公式得到每个像素的灰度值。

      Parameters:
      raster - the source raster | 源 raster
      Returns:
      the grayscale histogram (channel=0) | 灰度直方图(channel=0)
      Throws:
      NullPointerException - if raster is null | 当 raster 为 null 时抛出
      Since:
      opencode-base-image V1.0.4
    • compute

      public static HistogramOp.Histogram[] compute(Raster raster)
      Compute per-channel (R, G, B) histograms of a Raster. 计算 Raster 的逐通道(R、G、B)直方图。
      Parameters:
      raster - the source raster | 源 raster
      Returns:
      an array of 3 histograms ordered R, G, B | R/G/B 三个直方图
      Throws:
      NullPointerException - if raster is null | 当 raster 为 null 时抛出
      Since:
      opencode-base-image V1.0.4