java
public class ImageHistogram {
public int[] calculateHistogram(int[][] image) {
int[] histogram = new int[256];
for (int i = 0; i < image.length; i++) {
for (int j = 0; j < image[i].length; j++) {
int pixelValue = image[i][j];
histogram[pixelValue]++;
}
}
return histogram;
}
public void printHistogram(int[] histogram) {
for (int i = 0; i < histogram.length; i++) {
System.out.println("灰度级别 " + i + " 的像素数量为: " + histogram[i]);
}
}
public static void main(String[] args) {
int[][] image = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}};
ImageHistogram imageHistogram = new ImageHistogram();
int[] histogram = imageHistogram.calculateHistogram(image);
imageHistogram.printHistogram(histogram);
}
}
顶一下
(0)
0%
踩一下
(0)
0%
- 相关评论
- 我要评论
-
上一篇:返回栏目
下一篇:p2p 软件代码java