主要代码如下:
package chapter6;import java.awt.*;
import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage;/**
Created by LENOVO on 18-2-1.
*/ public class Histogram extends AbstractBufferedImageOp {public BufferedImage filter(BufferedImage src,BufferedImage dest){
int[] histogram = new int[256]; int width = src.getWidth(); int height = src.getHeight(); if(dest == null){ dest = creatCompatibleDestImage(src,null); } int[] inPixels = new int[width*height]; getRGB(src,0,0,width,height,inPixels);//获取直方图数据 for(int i=0;i
> 16) & 0xff; histogram[tr] ++; } } double maxFrequency = 0;//计算像素出现的最大频率值 for(int i=0;i }
}
测试代码同上