Excel表格网

求解直方图java代码

79 2024-02-28 04:12 admin   手机版
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%
相关评论
我要评论
用户名: 验证码:点击我更换图片
上一篇:返回栏目