File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes fourier image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "fourier image " Watch "fourier image " New topic
Author

fourier image

mustakim
Greenhorn

Joined: May 29, 2008
Posts: 2
Hi everybody! I'll appreciate help on the display of fourier image. I'm unable to get desired result. The portion of the java program is placed below:

void freq_spect(){

double F[][][];
double FX[][];
double f_r[];
double f_r1[];
double NNN[][];
double Four[][];
int fxy[][];
int wd=new_img.getWidth();//new_img is the bufferedimage.It's fourier image is to be displayed.
int ht=new_img.getHeight();
F=new double[wd][ht][2];
Four=new double[wd][ht];
FX=new double[wd][2];
f_r=new double[wd*ht];
f_r1=new double[wd*ht];
NNN=new double[wd][ht]; img_fourier=newBufferedImage(new_img.getWidth(),new_img.getHeight(),BufferedImage.TYPE_BYTE_GRAY);
rstr_f=img_fourier.getRaster(); //writable raster

for (int u=0;u<new_img.getWidth();u++)
{
for (int v=0;v<new_img.getHeight();v++)
{
NNN[u][v]=rstr.getSample(u,v,0); //rstr is the writable raster of the image.
NNN[u][v]=NNN[u][v]* Math.pow(-1,(u+v));
F[u][v][0]=0;
F[u][v][1]=0;
}
}

for (int u=0;u<new_img.getWidth();u++)
{

FX[u][0]=0; //real array
FX[u][1]=0; //imaginary array

for (int a=0; a<new_img.getWidth();a++)
{
for(int b=0;b<new_img.getHeight();b++)
{
FX[u][0]=FX[u][0]+(NNN[a][b])* Math.cos(Math.PI/180*( (6.28318*((u*a)/wd)));
FX[u][1] =FX[u][1]-((NNN[a][b])* Math.sin(Math.PI/180*( (6.28318*((u*a)/wd))));
}
}
}

vv=0;

for (int u=0;u<new_img.getWidth();u++)
{
for(int v=0;v<new_img.getHeight();v++)
{
for(int b=0;b<new_img.getHeight();b++)
{
//F[u][v][0] - real array
//F[u][v][1] - imaginary array.
F[u][v][0]=F[u][v][0]+(FX[u][0])* Math.cos(Math.PI/180*(6.28318*((v*b)/ht)))+(FX[u][1])* Math.sin(Math.PI/180*(6.28318*((v*b)/ht)));
F[u][v][1] =F[u][v][1]+(FX[u][1])* Math.cos(Math.PI/180*(6.28318*((v*b)/ht)))-((FX[u][0])* Math.sin(Math.PI/180*(6.28318*((v*b)/ht))));
}

double sum11=F[u][v][0]*F[u][v][0];
double sum22=F[u][v][1]*F[u][v][1];
Four[u][v]=(sum11+sum22);
f_r[vv]=Four[u][v];
f_r[vv]=Math.sqrt(f_r[vv]); //power spectrum
vv++;
}
}
for (int a=0; a<new_img.getWidth();a++)
for(int b=0;b<new_img.getHeight();b++)
{
rstr_f.setSample(a,b,0,Four[a][b]);
}

repaint();


}
[ May 30, 2008: Message edited by: mustakim ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

"mustakim md",
Please check your private messages.
-Ben


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11328
    
  16

What is the desired result?

What is wrong with this code? Why do you think it doesn't work? does it compile? does it start then die? does it do nothing? does it do the wrong thing - and if so, what?

we're not here for you to dump your problem on and fix it for you. people will bend over backwards to HELP you, but nobody's gonna do it for you. the more info you can give us on what's wrong, the more likely you are to get help.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38910
    
  23
Please check your private messages again.
mustakim
Greenhorn

Joined: May 29, 2008
Posts: 2
I'm sorry that I could'nt post the topic correctly.Actually for a simple sinusoidal image with u=3 & v=0; using my code the resulting transforms are coming as zeroes.It should not be so. Thanks.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38910
    
  23
Originally posted by mustakim:
I'm sorry that I could'nt post the topic correctly.
The problem is not the form of the posting, but your displayed name.
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
That is really some pretty cryptic code.

This is a great time to learn that its very important to write code that other people can read and understand. Heck, in 6 months you might have to revisit this code and its important that you understand it. Writing readable code means using meaningful names for your reference variables and in this case refactoring into smaller methods which do just one thing, and that have method names that convey exactly what it is they do.

I have no idea what this method is doing, let alone why it's not doing it right.


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11328
    
  16

agreed... variable names like 'F' and 'f_r ' are meaningless. nobody looking at your code would have any idea what these mean or are supposed to represent. And this:

FX[u][1]-((NNN[a][b])* Math.sin(Math.PI/180*( (6.28318*((u*a)/wd))));

is just impenetrable.
 
jQuery in Action, 2nd edition
 
subject: fourier image