NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/

Easy Java Simulations (2001- ) => Questions related to EJS => Topic started by: lookang on January 01, 2010, 07:06:09 pm



Title: how to model intensity and blurring of image in Ejs ?
Post by: lookang on January 01, 2010, 07:06:09 pm
how to model intensity and blurring of image in Ejs ?
to see the real image we need a screen. yet i notice most simulation dun include a screen. I request that someone create an simulation that is something like the one in this thread but add a screen that is adjustable so we can see how does adjusting the screen affect the image. thx 8) :D :) ;) :P :-*

I noticed in http://www.yenka.com/en/Yenka_Light_and_Sound/ there is a similar concept for reference viewable in the image there.
http://www.yenka.com/en/Yenka_Light_and_Sound/attachments/y-t2-1-1.gif
Thanks!

I have been testing on this, i managed to model the size X and Y but what transformation do i do to make picture blur ?

I have not seen any blurring effect on Ejs applets, can it be done?
anyway i been looking at http://www.huxtable.com/ip/blurring.html
seems like i need View GaussianFilter.java


Title: Re: how to model intensity and blurring of image in Ejs ?
Post by: Fu-Kwun Hwang on January 01, 2010, 11:08:43 pm
I do not think the current version of EJS GUI can do the effect you need.
But you can ask Paco to add it as part of EJS image property. Just provide him the source code and he should be able to implement it soon (if he think it is necessary).
 


Title: Re: how to model intensity and blurring of image in Ejs ?
Post by: lookang on January 05, 2010, 09:46:52 pm
i have been looking at the codes by Paco.

Code:
public void setImage () {
  java.awt.image.BufferedImage myImage = org.opensourcephysics.tools.ResourceLoader.getBufferedImage("./tmp3D/TEXTURES/fixed_stars.jpg");
  _view.image.setImage(myImage);
}

public void blurImage() {
    float[] matrix = {
        0.111f, 0.111f, 0.111f,
        0.111f, 0.111f, 0.111f,
        0.111f, 0.111f, 0.111f,
    };

  java.awt.image.BufferedImage sourceImage = org.opensourcephysics.tools.ResourceLoader.getBufferedImage("./tmp3D/TEXTURES/fixed_stars.jpg");
  java.awt.image.BufferedImage destImage = new java.awt.image.BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), sourceImage.getType());
  java.awt.image.BufferedImageOp op = new java.awt.image.ConvolveOp( new java.awt.image.Kernel(3, 3, matrix) );
  op.filter(sourceImage, destImage);
  _view.image.setImage(destImage);
}

but i have little clue have to add a variable to make the blur depend on a variable control by a slider.

then i go look at
http://www.huxtable.com/ip/blurring.html http://www.huxtable.com/ip/ConvolveFilter.java

so i try to add the variable as the number 400 by instead i used numbertodivide

is the code correct?

public void setImage () {
  java.awt.image.BufferedImage myImage = org.opensourcephysics.tools.ResourceLoader.getBufferedImage("./tmp3D/TEXTURES/fixed_stars.jpg");
  _view.image.setImage(myImage);
}
integer rows;
integer columns;
numbertodivide = rows*columns;

public void blurImage(integer numbertodivide) {

float[] matrix = new float[numbertodivide];
   for (int i = 0; i < numbertodivide; i++)
      matrix = 1.0f/numbertodivide*1.0f;
      
//    BufferedImageOp op = new ConvolveOp( new Kernel(20, 20, matrix), ConvolveOp.EDGE_NO_OP, null );
//   blurredImage = op.filter(sourceImage, destImage);
 java.awt.image.BufferedImage sourceImage = org.opensourcephysics.tools.ResourceLoader.getBufferedImage("./tmp3D/TEXTURES/fixed_stars.jpg");
  java.awt.image.BufferedImage destImage = new java.awt.image.BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), sourceImage.getType());
  java.awt.image.BufferedImageOp op = new java.awt.image.ConvolveOp( new java.awt.image.Kernel(rows, columns, matrix) );
  op.filter(sourceImage, destImage);
  _view.image.setImage(destImage);
}

the error message is
C:\Users\160\Desktop\EJS_4.2_091119\EJS_4.2\workspace\output\users\sgeducation\lookang\ejs_ImageTest\ImageTest.java:167: expected
  numbertodivide = rows*columns;  // > Custom.Lib Page:7
                 ^
1 error
Compilation produced an error!

any tips why error?
First attachment is orginal from Paco
Second is my working  ;D


Title: Re: how to model intensity and blurring of image in Ejs ?
Post by: Fu-Kwun Hwang on January 05, 2010, 10:50:49 pm
You should have define
public void blurImage(int numbertodivide)
instead of public void blurImage(intwger numbertodivide)

and you do not need
Code:
integer rows;
integer columns;
numbertodivide = rows*columns;
in the lib panel.

There are other errors: for example you call it with blurImage(); without any parameter.

I corrected several error in your code (see attached file).
However, you are not consistant. for exmaple:yo have
Code:
  java.awt.image.BufferedImageOp op = new java.awt.image.ConvolveOp( new java.awt.image.Kernel(rows, columns, matrix) );
which involve rows and columns. However, it is not related to numbertodivide in your code, and the setting of matrix.

You should modify the following code to make it more consistant.
Code:
float[] matrix = new float[numbertodivide];
for (int i = 0; i < numbertodivide; i++)
matrix[i] = 1.0f/numbertodivide*1.0f;




Title: Re: how to model intensity and blurring of image in Ejs ?
Post by: lookang on January 06, 2010, 11:08:30 pm
thanks! i am working on it!


Title: Re: how to model intensity and blurring of image in Ejs ?
Post by: lookang on January 26, 2010, 02:58:10 pm
i think the codes i modified to
Code:
float[] matrix = new float[numbertodivide];
for (int i = 0; i < numbertodivide; i++)
matrix[i] = 1.0f/numbertodivide*1.0f;
it does not blur.

i changed the picture, it seems to only dim ( reduce the intensity ).

i suspect the code in wrong "matrix = 1.0f/numbertodivide*1.0f;" some how the "f" which i think means float is not working correctly when i change the codes from

original code from http://www.huxtable.com/ip/blurring.html
Code:
float[] matrix = new float[400];
for (int i = 0; i < 400; i++)
matrix[i] = 1.0f/400.0f;

thanks for your help!