Skip to main content

[How it's done?] - GaussianBlurFilter filter

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
3 replies [Last post]
ricardolexix
Offline
Joined: 2012-04-19

Hi guys.

Recently I've been participating in a project in my work, and am trying to manipulate filters on images. I'm trying to produce an image following this logical order:

1 - I produce an image that will be painted a geometric shape (Shape object).
2 - I produce another image by applying the previous image with the filter GraussianBlurFilter.

The result I have is that the gaussian blur is applied only on pixels that are "misaligned" pixels diagonally, not vertically or horizontally.

Here's the code (it's a method):

private BufferedImage getImage()
{
// Build image with the desired shape.
BufferedImage temp = new BufferedImage(
this.width ,
this.height ,
BufferedImage.TYPE_INT_ARGB);

Graphics2D gTemp = temp.createGraphics();

gTemp.setColor(Color.BLACK);
gTemp.fill(this.getShape());
gTemp.dispose();

// Build another image with the previous blurred image.
int radius = 8;

BufferedImage ret = new BufferedImage(
this.width + radius * 2 ,
this.height + radius * 2 ,
BufferedImage.TYPE_INT_ARGB);

GaussianBlurFilter gaussianFilter = new GaussianBlurFilter(radius);

Graphics2D gRet = ret.createGraphics();

// Paints a white background to show the missing actions (?) from the filter.
gRet.setColor(Color.WHITE);
gRet.fillRect(0 , 0 , ret.getWidth() , ret.getHeight());

gRet.drawImage(temp , gaussianFilter , radius , radius);
gRet.dispose();

return ret;
}

And here's a screen shot:


If the image does not appear: http://www.freeimagehosting.net/7av86

Can somebody tell me what I'm doing wrong?

Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kschaefe
Offline
Joined: 2006-06-08

Sounds like you need a different radius for the blur effect. Try using the second constructor.

Karl

ricardolexix
Offline
Joined: 2012-04-19

Hi Karl.

Well, actually it would not solve the problem. What happens is that the more I change the radius parameter, the effect of gaussian blur should be applied equally to all pixels of an image. The only other GaussianBlurFilter constructor has no parameters, and of course, this does not give me the ability to set the radius.

I believe GaussianBlurFilter is immutable. I do not know, because I do not find api to study (it is hard to program without being able to use the api).

Here is a more didactic demonstration of what actually happens with this filter:

Link 1: http://postimage.org/image/g62qihj4x/
Mirror: http://i.imgur.com/ZDEvl.png

1 - A normal image without any filter. This image was produced with geometric shapes of java.
2 - Applying the GaussianBlurFilter, I get a result quite unexpected.
3 - This indeed is the desired result by applying the filter.

Aww... What am I doing wrong? :(

Thanks for the reply.

ricardolexix
Offline
Joined: 2012-04-19

Hi guys.

Heh... Err... I kind was doing a little thing wrong. What was happening was that the geometric shape painted the first image was in need of more space (pixels). The filter GaussianBlurFilter applies its effect on the first image, and this result is only painted in the picture returns. With the blur effect, you need more pixels to that effect is displayed.

I'll summarize, the first image needed to be higher ... :B

I'm sorry people, hahahahaha! But thanks anyway.

Bye!