Switch to full style
General Java code examples
Post a reply

Image Custom Filter In Java

Mon May 06, 2013 11:16 pm

Image Custom Filter In java
java code
package imageviewer;

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ConvolveOp;
import java.awt.image.Kernel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import javax.swing.JTextField;


public class CustomFilter extends JFrame{

/** Creates a new instance of CustomFilter */
public CustomFilter(BufferedImage buffImage) {
setTitle("Custom Filter");
setSize(400,200);
setLocation(250,250);
Orginal=buffImage;
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
myPanel.setLayout(new GridLayout(5,5));

for(int i=0;i<5;i++)
for(int j=0;j<5;j++) {
myfilds[i][j]=new JTextField("0.08",5);
myPanel.add(myfilds[i][j]);
}
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

int count=0;
float foa;
for(int i=0;i<5;i++)
for(int j=0;j<5;j++) {


customfil[count] =Float.parseFloat(myfilds[i][j].getText());

count++;
}

int w =Orginal.getWidth();
int h = Orginal.getHeight();
biop = new ConvolveOp(new Kernel(dim[0][0],dim[0][1],customfil));
BufferedImage bi = new BufferedImage(w,h,Orginal.TYPE_INT_RGB);
biop.filter(Orginal,bi);
new ShowFrame(bi,"Custom Filter");
}
});
Cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
cp.add(myPanel);
cp.add(ok);
cp.add(Cancel);

}
private JTextField [][] myfilds=new JTextField[5][5];
private JPanel myPanel=new JPanel();
private JButton ok=new JButton("OK");
private JButton Cancel=new JButton("Cancel");
private float[] customfil = new float[25];
private BufferedImageOp biop;
private BufferedImage Orginal;
private int dim[][] = {{5,5}};
}


Original Project :
finished-projects/image-viewer-image-processing-filters-noise-enhancements-t639.html



Post a reply
  Related Posts  to : Image Custom Filter In Java
 Image Noise Filter in Java     -  
 apply mean filter to image     -  
 Median filter to image     -  
 apply laplacian filter to image     -  
 Applying canny filter to image     -  
 apply robert filter to image     -  
 apply sobel filter to image     -  
 applying wiener filter to image     -  
 apply prewitt filter to image     -  
 rank order filter effects on image     -  

Topic Tags

Java Image