baocaoxla.compare.java Source code

Java tutorial

Introduction

Here is the source code for baocaoxla.compare.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package baocaoxla;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import org.jfree.chart.ChartPanel;

/**
 *
 * @author tao
 */
public class compare extends javax.swing.JFrame {

    private BufferedImage img;
    private BufferedImage imgcompare;
    private xuly_compare xuly = new xuly_compare();

    public compare() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        lbimagecompare = new javax.swing.JLabel();
        lbimage = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        pnimagehistogram = new javax.swing.JPanel();
        pnimagehistogram1 = new javax.swing.JPanel();
        btprocess = new javax.swing.JButton();
        lbphantram = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        lbtime = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtratio = new javax.swing.JTextField();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtInput = new javax.swing.JTextField();
        txtOutput = new javax.swing.JTextField();
        btInput = new javax.swing.JButton();
        btOutput = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu2 = new javax.swing.JMenu();
        jMenuOpen = new javax.swing.JMenuItem();
        jMenuSave = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jcbtwo = new javax.swing.JCheckBoxMenuItem();
        jcbmuti = new javax.swing.JCheckBoxMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        lbimage.setBackground(new java.awt.Color(204, 204, 204));
        lbimage.setForeground(new java.awt.Color(255, 255, 255));

        jLabel1.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
        jLabel1.setText("Model Image");

        jLabel2.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
        jLabel2.setText("compare image");

        pnimagehistogram.setLayout(new java.awt.BorderLayout());

        pnimagehistogram1.setLayout(new java.awt.BorderLayout());

        btprocess.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        btprocess.setText("process");
        btprocess.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btprocessActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel3.setText("%");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel4.setText("ms");

        jComboBox1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "Intersection", "Correlation", "Chi_square", "BHATTACHARYYA" }));

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel5.setText("Method");

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel6.setText("Ratio(%)");

        btInput.setText("Browser");
        btInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btInputActionPerformed(evt);
            }
        });

        btOutput.setText("Browser");
        btOutput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btOutputActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel7.setText("Input folder");

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel8.setText("Output Folder");

        jMenu2.setText("File");

        jMenuOpen.setText("Open");
        jMenuOpen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuOpenActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuOpen);

        jMenuSave.setText("Save");
        jMenuSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuSaveActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuSave);

        jMenuBar1.add(jMenu2);

        jMenu3.setText("type coparision");

        buttonGroup1.add(jcbtwo);
        jcbtwo.setSelected(true);
        jcbtwo.setText("two_compare");
        jMenu3.add(jcbtwo);

        buttonGroup1.add(jcbmuti);
        jcbmuti.setText("Muti_compare");
        jMenu3.add(jcbmuti);

        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGap(36, 36, 36).addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup().addGroup(layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 106,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(btprocess))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(pnimagehistogram, javax.swing.GroupLayout.PREFERRED_SIZE, 279,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17,
                                        Short.MAX_VALUE)
                                .addGroup(layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addGroup(layout.createSequentialGroup()
                                                .addComponent(lbimagecompare,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 388,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(22, 22, 22))
                                        .addGroup(layout.createSequentialGroup().addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 117,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGroup(layout.createSequentialGroup()
                                                        .addGroup(layout.createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                .addComponent(lbphantram,
                                                                        javax.swing.GroupLayout.Alignment.TRAILING,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 65,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addComponent(lbtime,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 65,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addGroup(layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.TRAILING,
                                                                        false)
                                                                .addComponent(jLabel4,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE, 23,
                                                                        Short.MAX_VALUE)
                                                                .addComponent(jLabel3,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        Short.MAX_VALUE))))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(pnimagehistogram1,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 279,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addContainerGap())))
                        .addGroup(layout.createSequentialGroup().addGroup(layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(layout.createSequentialGroup().addGap(25, 25, 25).addComponent(jLabel5,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 100,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE))
                                .addGap(18, 18, 18)
                                .addGroup(
                                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(txtOutput).addComponent(txtInput)
                                                .addComponent(jComboBox1, 0, 349, Short.MAX_VALUE))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup()
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 69,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(35, 35, 35)
                                                .addComponent(txtratio, javax.swing.GroupLayout.PREFERRED_SIZE, 121,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addContainerGap())
                                        .addGroup(layout.createSequentialGroup().addGap(41, 41, 41).addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(btOutput).addComponent(btInput)).addContainerGap(
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup().addGap(35, 35, 35)
                                .addComponent(lbimage, javax.swing.GroupLayout.PREFERRED_SIZE, 388,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(429, Short.MAX_VALUE))));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGap(43, 43, 43)
                        .addComponent(lbimagecompare, javax.swing.GroupLayout.PREFERRED_SIZE, 221,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup().addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(
                                                        jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGroup(layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addGroup(layout.createSequentialGroup().addGap(18, 18, 18)
                                                                .addComponent(btprocess))
                                                        .addGroup(layout.createSequentialGroup().addGroup(layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.TRAILING,
                                                                        false)
                                                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                                                        layout.createSequentialGroup()
                                                                                .addPreferredGap(
                                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                .addComponent(jLabel3,
                                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                        Short.MAX_VALUE))
                                                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                                                        layout.createSequentialGroup()
                                                                                .addGap(3, 3, 3)
                                                                                .addComponent(lbphantram,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                        23,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                                .addPreferredGap(
                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                .addGroup(layout.createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                                        false)
                                                                        .addComponent(
                                                                                lbtime,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                Short.MAX_VALUE)
                                                                        .addComponent(jLabel4,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                22, Short.MAX_VALUE)))))
                                        .addComponent(pnimagehistogram, javax.swing.GroupLayout.PREFERRED_SIZE, 125,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(pnimagehistogram1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                125, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(txtratio)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jComboBox1, javax.swing.GroupLayout.DEFAULT_SIZE, 37,
                                                Short.MAX_VALUE)
                                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 37,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(40, 40, 40)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(txtInput, javax.swing.GroupLayout.PREFERRED_SIZE, 35,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(btInput))
                                .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 35,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(31, 31, 31)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 35,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txtOutput, javax.swing.GroupLayout.PREFERRED_SIZE, 36,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(btOutput))
                        .addContainerGap(28, Short.MAX_VALUE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup().addGap(43, 43, 43)
                                .addComponent(lbimage, javax.swing.GroupLayout.PREFERRED_SIZE, 221,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(370, Short.MAX_VALUE))));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuSaveActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuSaveActionPerformed

    private void jMenuOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuOpenActionPerformed
        JFileChooser fc = new JFileChooser();
        int f = fc.showOpenDialog(this);
        if (f == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            try {
                img = ImageIO.read(new File(file.getPath()));
                ImageIcon icon = new ImageIcon(
                        img.getScaledInstance(lbimage.getWidth(), lbimage.getHeight(), Image.SCALE_SMOOTH));
                lbimage.setIcon(icon);
                pnimagehistogram.removeAll();
                pnimagehistogram.add(xuly.displayhistogram(img));
                pnimagehistogram.validate();
            } catch (IOException ex) {
                Logger.getLogger(compare.class.getName()).log(Level.SEVERE, null, ex);
            }
            if (jcbtwo.isSelected()) {
                fc.showOpenDialog(this);
                file = fc.getSelectedFile();
                try {
                    imgcompare = ImageIO.read(new File(file.getPath()));
                    ImageIcon icon1 = new ImageIcon(imgcompare.getScaledInstance(lbimagecompare.getWidth(),
                            lbimagecompare.getHeight(), Image.SCALE_SMOOTH));
                    lbimagecompare.setIcon(icon1);
                    pnimagehistogram1.removeAll();
                    pnimagehistogram1.add(xuly.displayhistogram(imgcompare));
                    pnimagehistogram1.validate();
                } catch (IOException ex) {
                    Logger.getLogger(compare.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

    }//GEN-LAST:event_jMenuOpenActionPerformed

    private void btprocessActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btprocessActionPerformed
        long start, end;
        start = System.currentTimeMillis();
        int percent;

        if (jcbtwo.isSelected()) {
            if (jComboBox1.getSelectedItem().equals("Intersection")) {
                percent = xuly.intersection(img, imgcompare);
                lbphantram.setText(String.valueOf(percent));
            }
            if (jComboBox1.getSelectedItem().equals("Correlation")) {
                percent = xuly.Correlation(img, imgcompare);
                lbphantram.setText(String.valueOf(percent));
            }
            if (jComboBox1.getSelectedItem().equals("BHATTACHARYYA")) {
                percent = xuly.BHATTACHARYYA(img, imgcompare);
                lbphantram.setText(String.valueOf(percent));
            }
            if (jComboBox1.getSelectedItem().equals("Chi_square")) {
                percent = xuly.chi_square(img, imgcompare);
                lbphantram.setText(String.valueOf(percent));
            }
        } else {
            File dirsr = new File(txtInput.getText());
            File dirdest = new File(txtOutput.getText());
            File[] file = dirsr.listFiles(new FilenameFilter() {

                @Override
                public boolean accept(File dir, String name) {
                    return name.toLowerCase().endsWith(".jpg");
                }
            });

            if (jComboBox1.getSelectedItem().equals("Intersection")) {

                for (int i = 0; i < file.length; i++) {
                    try {
                        imgcompare = ImageIO.read(new File(file[i].getPath()));

                        if (xuly.intersection(img, imgcompare) >= Integer.parseInt(txtratio.getText())) {
                            InputStream is = null;
                            OutputStream os = null;
                            try {
                                is = new FileInputStream(file[i]);
                                os = new FileOutputStream(new File(txtOutput.getText() + "\\" + file[i].getName()));
                                byte[] buffer = new byte[1024];
                                int length;
                                while ((length = is.read(buffer)) > 0) {
                                    os.write(buffer, 0, length);
                                }
                                is.close();
                                os.close();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }

                    } catch (IOException ex) {
                        Logger.getLogger(compare.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }

            }
            if (jComboBox1.getSelectedItem().equals("Correlation")) {

                for (int i = 0; i < file.length; i++) {
                    try {
                        imgcompare = ImageIO.read(new File(file[i].getPath()));
                        if (xuly.Correlation(img, imgcompare) >= Integer.parseInt(txtratio.getText())) {
                            InputStream is = null;
                            OutputStream os = null;
                            try {

                                is = new FileInputStream(file[i]);
                                os = new FileOutputStream(new File(txtOutput.getText() + "\\" + file[i].getName()));
                                byte[] buffer = new byte[1024];
                                int length;
                                while ((length = is.read(buffer)) > 0) {
                                    os.write(buffer, 0, length);
                                }
                                is.close();
                                os.close();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }

                    } catch (IOException ex) {
                        Logger.getLogger(compare.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }

            }
            if (jComboBox1.getSelectedItem().equals("BHATTACHARYYA")) {

                for (int i = 0; i < file.length; i++) {
                    try {
                        imgcompare = ImageIO.read(new File(file[i].getPath()));
                        if (xuly.BHATTACHARYYA(img, imgcompare) >= Integer.parseInt(txtratio.getText())) {
                            InputStream is = null;
                            OutputStream os = null;
                            try {

                                is = new FileInputStream(file[i]);
                                os = new FileOutputStream(new File(txtOutput.getText() + "\\" + file[i].getName()));
                                byte[] buffer = new byte[1024];
                                int length;
                                while ((length = is.read(buffer)) > 0) {
                                    os.write(buffer, 0, length);
                                }
                                is.close();
                                os.close();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }

                    } catch (IOException ex) {
                        Logger.getLogger(compare.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }

            }
            if (jComboBox1.getSelectedItem().equals("Chi_square")) {

                for (int i = 0; i < file.length; i++) {
                    try {
                        imgcompare = ImageIO.read(new File(file[i].getPath()));
                        if (xuly.chi_square(img, imgcompare) >= Integer.parseInt(txtratio.getText())) {
                            InputStream is = null;
                            OutputStream os = null;
                            try {

                                is = new FileInputStream(file[i]);
                                os = new FileOutputStream(new File(txtOutput.getText() + "\\" + file[i].getName()));
                                byte[] buffer = new byte[1024];
                                int length;
                                while ((length = is.read(buffer)) > 0) {
                                    os.write(buffer, 0, length);
                                }
                                is.close();
                                os.close();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }

                    } catch (IOException ex) {
                        Logger.getLogger(compare.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }

            }

        }
        end = System.currentTimeMillis();
        long time = end - start;
        lbtime.setText(String.valueOf(time));

    }//GEN-LAST:event_btprocessActionPerformed

    private void btInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btInputActionPerformed
        JFileChooser fc = new JFileChooser();
        fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        fc.showOpenDialog(this);
        File dir = fc.getSelectedFile();
        txtInput.setText(dir.toString());
        /* File[] file=dir.listFiles(new FilenameFilter() {
            
         @Override
         public boolean accept(File dir, String name) {
         return name.toLowerCase().endsWith(".jpg"); //To change body of generated methods, choose Tools | Templates.
         }
         });*/
        //File[] file = dir.listFiles();
        //for (int i = 0; i < file.length; i++) {
        //  System.out.println(file[i].getName());
        //}

    }//GEN-LAST:event_btInputActionPerformed

    private void btOutputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOutputActionPerformed
        JFileChooser fc = new JFileChooser();
        fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        fc.showOpenDialog(this);
        File dir = fc.getSelectedFile();
        txtOutput.setText(dir.toString());
    }//GEN-LAST:event_btOutputActionPerformed

    /**
     * @param args the command line arguments
     */
    /* public static void main(String args[]) {
            
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(compare.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(compare.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(compare.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(compare.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
          
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new compare().setVisible(true);
        }
    });
     }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btInput;
    private javax.swing.JButton btOutput;
    private javax.swing.JButton btprocess;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuOpen;
    private javax.swing.JMenuItem jMenuSave;
    private javax.swing.JCheckBoxMenuItem jcbmuti;
    private javax.swing.JCheckBoxMenuItem jcbtwo;
    private javax.swing.JLabel lbimage;
    private javax.swing.JLabel lbimagecompare;
    private javax.swing.JLabel lbphantram;
    private javax.swing.JLabel lbtime;
    private javax.swing.JPanel pnimagehistogram;
    private javax.swing.JPanel pnimagehistogram1;
    private javax.swing.JTextField txtInput;
    private javax.swing.JTextField txtOutput;
    private javax.swing.JTextField txtratio;
    // End of variables declaration//GEN-END:variables
}