主要通过获取本地的一张图片,分析图片每一像素点的RGB值,由此获得每一像素点的灰度值,并对这些灰度值进行熵的计算。
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
public class ImageTest {
public static void main(String args[]) {
new MyFrame();
}
}
class MyFrame extends JFrame{
JPanel panel = null;
JLabel label = null;
JPanel panel2 = null;
JLabel label2 = null;
public MyFrame(){
super("测试图片灰度值的熵值");
this.setBounds(400,100