This week's book giveaway is in the Other Languages forum.We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!

# fourier image

mustakim
Greenhorn
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
Posts: 13411
"mustakim md",
-Ben

fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
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.

Campbell Ritchie
Sheriff
Posts: 50196
79

mustakim
Greenhorn
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
Posts: 50196
79
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
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.

fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
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.