Class HistogramOp
java.lang.Object
cloud.opencode.base.image.histogram.HistogramOp
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 | 使用示例:
BufferedImage image = ImageIO.read(new File("photo.png"));
HistogramOp.Histogram gray = HistogramOp.computeGray(image);
System.out.println("Mean: " + gray.mean());
HistogramOp.Histogram[] rgb = HistogramOp.compute(image);
// 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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordHistogram data for a single channel. -
Method Summary
Modifier and TypeMethodDescriptionstatic HistogramOp.Histogram[]compute(BufferedImage image) Compute per-channel (R, G, B) histograms of an image.static HistogramOp.HistogramcomputeGray(BufferedImage image) Compute the grayscale histogram of an image.
-
Method Details
-
computeGray
Compute the grayscale histogram of an image. 计算图像的灰度直方图。The image is first converted to grayscale using ITU-R BT.601 coefficients.
图像首先使用 ITU-R BT.601 系数转换为灰度。
- Parameters:
image- the source image | 源图像- Returns:
- the grayscale histogram (channel=0) | 灰度直方图(channel=0)
- Throws:
NullPointerException- if image is null | 当图像为 null 时抛出
-
compute
Compute per-channel (R, G, B) histograms of an image. 计算图像的逐通道(R、G、B)直方图。- Parameters:
image- the source image | 源图像- Returns:
- an array of 3 histograms: [0]=Red(channel=1), [1]=Green(channel=2), [2]=Blue(channel=3) | 3 个直方图数组:[0]=红色(channel=1), [1]=绿色(channel=2), [2]=蓝色(channel=3)
- Throws:
NullPointerException- if image is null | 当图像为 null 时抛出
-