I am trying to blur the image
int radius = 11;
int size = radius * 2 + 1;
float weight = 1.0f / (size * size);
float[] data = new float[size * size];
for (int i = 0; i < data.length; i++) {
data[i] = weight;
}
Kernel kernel = new Kernel(size, size, data);
ConvolveOp op = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
//tbi is BufferedImage
BufferedImage i = op.filter(tbi, null);
It will blur the image but not all portion of the image.
Where I am missing so that it will blur complete image. Without any path .
Kernel kernel = new Kernel(size, size, data); BufferedImageOp op = new ConvolveWithEdgeOp(kernel, ConvolveOp. EDGE_REFLECT, null); BufferedImage blurred = op. filter(original, null); The filter should work like any other BufferedImageOp , and should work with any BufferedImage .
Quick tip: You can adjust the blur after the photo is taken as well. If you take a picture in Portrait mode, open it in the Photos app, tap Edit, and then tap the f button at the top left. Use the slider to change the blur effect.
Definition and Usage The blur event occurs when an element loses focus. The blur() method triggers the blur event, or attaches a function to run when a blur event occurs. Tip: This method is often used together with the focus() method.
The standard Java ConvolveOp
only has the two options EDGE_ZERO_FILL
and EDGE_NO_OP
. What you want is the options from the JAI equivalent (ConvolveDescriptor), which is EDGE_REFLECT
(or EDGE_WRAP
, if you want repeating patterns).
If you don't want to use JAI, you can implement this yourself, by copying your image to a larger image, stretching or wrapping the edges, apply the convolve op, then cut off the edges (similar to the technique described in the "Working on the Edge" section of the article posted by @halex in the comments section, but according to that article, you can also just leave the edges transparent).
For simplicity, you can just use my implementation called ConvolveWithEdgeOp
which does the above (BSD license).
The code will be similar to what you had originally:
// ...kernel setup as before...
Kernel kernel = new Kernel(size, size, data);
BufferedImageOp op = new ConvolveWithEdgeOp(kernel, ConvolveOp.EDGE_REFLECT, null);
BufferedImage blurred = op.filter(original, null);
The filter should work like any other BufferedImageOp
, and should work with any BufferedImage
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With