Documente Academic
Documente Profesional
Documente Cultură
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import prak6.prak6Hisogram;
/**
*
* @author riska
*/
BufferedImage image=null;
private int width;
private int height;
String input=null,
srcIm="rose.jpg";
/**
* Creates new form citra6
*/
public citra6() {
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() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("Load");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Grayscale");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText("Histogram");
jButton3.addActionListener(new java.awt.event.ActionListener() {
jButton4.setText("CDF");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jButton5.setText("H Red");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
jButton6.setText("H Green");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});
jButton7.setText("H Blue");
jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton7ActionPerformed(evt);
}
});
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 28,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 28,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton7)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25,
Short.MAX_VALUE)
.addComponent(jLabel3))
);
pack();
}// </editor-fold>//GEN-END:initComponents
int blue=(int)(w.getGreen());
int xg= (int) (blue+blue+blue)/3;
hist[xg]+=1;
}
}
int red=(int)(w.getRed());
int blue=(int)(w.getBlue());
int green=(int)(w.getGreen());
int xg= (int) (red+green+blue)/3;
int red=(int)(w.getRed());
int blue=(int)(w.getBlue());
int green=(int)(w.getGreen());
int xg= (int) (red+green+blue)/3;
hist[xg]+=1;
}
}
height = image.getHeight();
int red=(int)(w.getRed());
int blue=(int)(w.getBlue());
int green=(int)(w.getGreen());
int xg= (int) (red+green+blue)/3;
hist[xg]+=1;
}
}
int[] cdf =new int [256];
cdf[0]=hist[0];
for (int i = 1; i < 256; i++) {
cdf[i]=cdf[i-1]+hist[i];
}
DefaultCategoryDataset dataset=new DefaultCategoryDataset();
for (int i = 0; i < 256; i++) {
dataset.addValue(cdf[i], i+"", "");
}
JFreeChart chart= ChartFactory.createBarChart("Fungsi Distribusi Kumulatif", "grayscale",
"nilai",
dataset,PlotOrientation.VERTICAL,false,true,false);
ChartFrame frame=new ChartFrame("CDF", chart);
frame.setSize(600,400);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
}//GEN-LAST:event_jButton4ActionPerformed
int red=(int)(w.getRed());
int xg= (int) (red);
hist[xg]+=1;
}
}
int green=(int)(w.getGreen());
int xg= (int) (green+green+green)/3;
hist[xg]+=1;
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
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(citra6.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(citra6.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(citra6.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(citra6.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>