monster2
asked on
How to blur ?
Hi,
I'm interested how to achive blur effect
I will like to know what kind of algoritam is used and if possible some code or urls with source and explanation
I wont to understand logic behind this effects so i need some explanation or url's where to finde some
Thanks
Vedran
I'm interested how to achive blur effect
I will like to know what kind of algoritam is used and if possible some code or urls with source and explanation
I wont to understand logic behind this effects so i need some explanation or url's where to finde some
Thanks
Vedran
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Strangely there is no setPixel(x,y). At least not in a straightforward way that I know of (if anyone knows of one then let me know...)
You could probably implement one, but I'd stick to drawLine and drawRect even though you are right in assuming they are a bit clumsy.
If you want, make your own setPixel function by wrapping drawdrawRect, for example:
setPixel(int x,int y, Graphics g) {
g.drawRect(x,y,0,0);
}
this should work, but if nothing appears then try:
setPixel(int x,int y, Graphics g) {
g.drawRect(x,y,1,1);
}
At least this way you can remove the offensive drawLine from your code....:-)
You will be pleased to know that the java.awt.image package provides a large amount of support for this sort of image processing.
Check the following code to get an example of how to build a filter and process an image (storead a BufferedImage which is basically a two by two array of pixels).
In this standard example, you can see that each of the weightings in the array has already been divided by 9.
this turns your basic
1 1 1
1 1 1
1 1 1
filter into
0.111 0.111 0.111
0.111 0.111 0.111
0.111 0.111 0.111
Each weighting has already been divided by 9. The advantage is, that you now do not have to divide your result by 9. Just multiply each underlying pixel by it's weighting and add them up.
In the long run this is not quite as accurate due to the way computers round numbers, but does the job all the same.
float weight = 1.0f/9.0f;
float[] elements = new float[9]; // create 2D array
// fill the array with nine equal elements
for (i = 0; i < 9; i++) {
elements[i] = weight;
}
// use the array of elements as argument to create a Kernel
private Kernel myKernel = new Kernel(3, 3, elements);
public ConvolveOp simpleBlur = new ConvolveOp(myKernel);
// sourceImage and destImage are instances of BufferedImage
simpleBlur.filter(sourceIm age, destI mage) // blur the image
You could probably implement one, but I'd stick to drawLine and drawRect even though you are right in assuming they are a bit clumsy.
If you want, make your own setPixel function by wrapping drawdrawRect, for example:
setPixel(int x,int y, Graphics g) {
g.drawRect(x,y,0,0);
}
this should work, but if nothing appears then try:
setPixel(int x,int y, Graphics g) {
g.drawRect(x,y,1,1);
}
At least this way you can remove the offensive drawLine from your code....:-)
You will be pleased to know that the java.awt.image package provides a large amount of support for this sort of image processing.
Check the following code to get an example of how to build a filter and process an image (storead a BufferedImage which is basically a two by two array of pixels).
In this standard example, you can see that each of the weightings in the array has already been divided by 9.
this turns your basic
1 1 1
1 1 1
1 1 1
filter into
0.111 0.111 0.111
0.111 0.111 0.111
0.111 0.111 0.111
Each weighting has already been divided by 9. The advantage is, that you now do not have to divide your result by 9. Just multiply each underlying pixel by it's weighting and add them up.
In the long run this is not quite as accurate due to the way computers round numbers, but does the job all the same.
float weight = 1.0f/9.0f;
float[] elements = new float[9]; // create 2D array
// fill the array with nine equal elements
for (i = 0; i < 9; i++) {
elements[i] = weight;
}
// use the array of elements as argument to create a Kernel
private Kernel myKernel = new Kernel(3, 3, elements);
public ConvolveOp simpleBlur = new ConvolveOp(myKernel);
// sourceImage and destImage are instances of BufferedImage
simpleBlur.filter(sourceIm
ASKER
Thank's again Jod
Thanks JOD.... and for just 2 points!
ASKER
what are you wont to say hank1 ?
This question was awarded, but never cleared due to the JSP-500 errors of that time. It was "stuck" against userID -1 versus the intended expert whom you awarded. This corrects the problem and the expert will now receive these points; points verified.
Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them. If you are an EE Pro user, you can also choose Power Search to find all your open questions.
This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.
https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
https://www.experts-exchange.com/jsp/zonesAll.jsp
Thank you,
Moondancer
Moderator @ Experts Exchange
Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them. If you are an EE Pro user, you can also choose Power Search to find all your open questions.
This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.
https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
https://www.experts-exchange.com/jsp/zonesAll.jsp
Thank you,
Moondancer
Moderator @ Experts Exchange
ASKER
I have one more question is there a command in jdk1.1 which can draw a single pixel on image (line is somehow stupid to use) ?
Regards Vedrab