6 Replies - 400 Views - Last Post: 24 September 2012 - 03:18 AM Rate Topic: -----

#1 JavaLilly  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 05-September 12

image blurring

Posted 22 September 2012 - 12:02 PM

This is a homework assignment .

I am trying to blur a buffered image, so I created a kernel to blur the image, but I keep getting the same image back over and over.


 public void blur (BufferedImage image)
    {
        BufferedImage destImage = null;
        float[] matrix = new float[16000];
             
                for (int i = 0; i < 16000; i++)
                    matrix[i] = 1.0f/16000.0f;

                BufferedImageOp pic = new ConvolveOp( new Kernel(10,10, matrix));

                BufferedImage finalBlurImage = pic.filter(image, destImage);
            }
        }
        save("image.jpg");

    }



Is there something wrong with my logic?

I've imported all the right libraries and checked out javadocs to make sure I wrote everything correctly.

Any suggestion is appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: image blurring

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2831
  • View blog
  • Posts: 11,996
  • Joined: 20-September 08

Re: image blurring

Posted 22 September 2012 - 12:34 PM

Quote

Is there something wrong with my logic?

How would we know if you don't post your save method?
Was This Post Helpful? 0
  • +
  • -

#3 JavaLilly  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 05-September 12

Re: image blurring

Posted 22 September 2012 - 12:39 PM

sorry.
the save came with the starter code.

   // save to given filename - suffix must be png, jpg, or gif
    public void save(String filename) { save(new File(filename)); }

    // save to given filename - suffix must be png, jpg
    public void save(File file) {
        String filename = file.getName();
        String suffix = filename.substring(filename.lastIndexOf('.') + 1);
        suffix = suffix.toLowerCase();
        if (suffix.equals("jpg") || suffix.equals("png")) {
            try { ImageIO.write(image, suffix, file); }
            catch (IOException e) { e.printStackTrace(); }
        }
        else {
            System.out.println("Error: filename must end in .jpg or .png");
        }
    }


Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2831
  • View blog
  • Posts: 11,996
  • Joined: 20-September 08

Re: image blurring

Posted 22 September 2012 - 01:38 PM

This is a good illustration of why using global variables is a bad idea. I'd guess that 'image' in save is referring to the original image. You should pass the changed image to your save method, then you'll prevent yourself saving the wrong one
Was This Post Helpful? 1
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8347
  • View blog
  • Posts: 31,910
  • Joined: 06-March 08

Re: image blurring

Posted 22 September 2012 - 05:17 PM

Hope that you realize that correctly indented your code looks like this
	public void blur (BufferedImage image)
	{
		BufferedImage destImage = null;
		float[] matrix = new float[16000];

		for (int i = 0; i < 16000; i++)
			matrix[i] = 1.0f/16000.0f;

		BufferedImageOp pic = new ConvolveOp( new Kernel(10,10, matrix));

		BufferedImage finalBlurImage = pic.filter(image, destImage);
	}


Was This Post Helpful? 0
  • +
  • -

#6 JavaLilly  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 05-September 12

Re: image blurring

Posted 23 September 2012 - 05:15 PM

View Postpbl, on 22 September 2012 - 05:17 PM, said:

Hope that you realize that correctly indented your code looks like this
	public void blur (BufferedImage image)
	{
		BufferedImage destImage = null;
		float[] matrix = new float[16000];

		for (int i = 0; i < 16000; i++)
			matrix[i] = 1.0f/16000.0f;

		BufferedImageOp pic = new ConvolveOp( new Kernel(10,10, matrix));

		BufferedImage finalBlurImage = pic.filter(image, destImage);
	}


okay...is there something wrong with that? Are you saying the pic BufferedImageOp should be in the for loop? That's the only thing that I can think you might be suggesting.
Was This Post Helpful? 0
  • +
  • -

#7 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2831
  • View blog
  • Posts: 11,996
  • Joined: 20-September 08

Re: image blurring

Posted 24 September 2012 - 03:18 AM

Quote

You should pass the changed image to your save method, then you'll prevent yourself saving the wrong one

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1