Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: blur filter

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default blur filter

    following is the code for filtering an image... can somebody please explain the kernel part in the program or the entire program briefly...
    actually,i downloaded it...





    package thumptrial;



    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.image.BufferedImage;
    import java.awt.image.BufferedImageOp;
    import java.awt.image.ConvolveOp;
    import java.awt.image.Kernel;
    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.JFrame;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;

    class Surface extends JPanel {

    private BufferedImage mshi;
    private BufferedImage databuf;

    public Surface() {

    loadImage();
    createBlurredImage();
    setSurfaceSize();
    }

    private void loadImage() {

    try {

    mshi = ImageIO.read(new File("D://photo//pic//test.jpg"));
    } catch (IOException ex) {

    Logger.getLogger(Surface.class.getName()).log(Leve l.SEVERE, null, ex);
    }
    }

    private void createBlurredImage() {

    databuf = new BufferedImage(mshi.getWidth(null),
    mshi.getHeight(null),
    BufferedImage.TYPE_INT_BGR);

    Graphics g = databuf.getGraphics();
    g.drawImage(mshi, 455, 255, null);

    float[] blurKernel = {
    1 / 9f, 1 / 9f, 1 / 9f,
    1 / 9f, 1 / 9f, 1 / 9f,
    1 / 9f, 1 / 9f, 1 / 9f
    };

    BufferedImageOp blur = new ConvolveOp(new Kernel(3, 3, blurKernel));
    mshi = blur.filter(mshi, new BufferedImage(mshi.getWidth(),
    mshi.getHeight(), mshi.getType()));
    g.dispose();
    }

    private void setSurfaceSize() {

    Dimension d = new Dimension();
    d.width = mshi.getWidth(null);
    d.height = mshi.getHeight(null);
    setPreferredSize(d);
    }

    private void doDrawing(Graphics g) {

    Graphics2D g2d = (Graphics2D) g;
    g2d.drawImage(mshi, null, 3, 3);
    }

    @Override
    public void paintComponent(Graphics g) {

    super.paintComponent(g);
    doDrawing(g);
    }
    }

    class FilteredImage extends JFrame {

    public FilteredImage() {

    setTitle("Filtered image");

    add(new Surface());

    pack();
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLocationRelativeTo(null);
    }

    public static void main(String[] args) {

    SwingUtilities.invokeLater(new Runnable() {

    @Override
    public void run() {

    FilteredImage bi = new FilteredImage();
    bi.setVisible(true);
    }
    });
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: blur filter

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    What does the code do when executed? What goes in and what comes out?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. blur filter
    By Sarah Jose in forum Member Introductions
    Replies: 2
    Last Post: October 28th, 2013, 12:24 PM
  2. Blur Image
    By smack in forum Algorithms & Recursion
    Replies: 2
    Last Post: April 7th, 2012, 10:16 AM
  3. Screen Blur
    By Ludicrous in forum Java Theory & Questions
    Replies: 2
    Last Post: April 1st, 2012, 10:34 AM
  4. Blur Image
    By psrkiran in forum Algorithms & Recursion
    Replies: 10
    Last Post: December 31st, 2009, 06:57 AM
  5. Internet Filter to display some website
    By sundarjothi in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: May 15th, 2008, 05:03 AM