Advice on using FFTW

  • Thread starter Stephen.Schoenberger
  • Start date
S

Stephen.Schoenberger

Hello,

I am looking for some advice/guidance on using the FFTW (fftw.org)
package to do 2D FFT on some bitmap images. I have bitmaps broken up
into small fragments and need to perform the 2D FFT on each of those.
The documentation on performing this task is a bit sparse so I figured
my best luck would be to turn to the newsgroups.

Thanks
 
U

user923005

Hello,

I am looking for some advice/guidance on using the FFTW (fftw.org)
package to do 2D FFT on some bitmap images. I have bitmaps broken up
into small fragments and need to perform the 2D FFT on each of those.
The documentation on performing this task is a bit sparse so I figured
my best luck would be to turn to the newsgroups.

Did you try their sample programs?

You want instead of They (the MIT authors) offer commercial support for commercial use,
according to my understanding.
They also offer free help from time to time.

Follow-ups set.
 
S

Stephen.Schoenberger

Did you try their sample programs?

You want instead of They (the MIT authors) offer commercial support for commercial use,
according to my understanding.
They also offer free help from time to time.

Follow-ups set.

I am attempting to perform this task in ANSI C...
 
J

jameskuyper

I am attempting to perform this task in ANSI C...

That doesn't matter. Expertise in ANSI/ISO C (which is quite abundant
in this newsgroup) is very nearly irrelevant to your question.
Experience with FFTW is far more relevant, and far less abundant here.
Whether there's anybody familiar with it in sci.math.num-analysis I
have no idea, but it sounds like a far more likely place to find such
experience that comp.lang.c.
 
C

CBFalconer

I am looking for some advice/guidance on using the FFTW (fftw.org)
package to do 2D FFT on some bitmap images. I have bitmaps broken
up into small fragments and need to perform the 2D FFT on each of
those. The documentation on performing this task is a bit sparse
so I figured my best luck would be to turn to the newsgroups.

You have first to make the source of that package, written in pure
ISO standard C, available. You can publish it on some appropriate
URL if it is too large to post here (i.e. over about 200 lines or
so). I have no idea if such action is permitted to you. Then you
can see if anyone is willing to attack it. Include the available
documentation.
 
K

Keith Thompson

CBFalconer said:
You have first to make the source of that package, written in pure
ISO standard C, available. You can publish it on some appropriate
URL if it is too large to post here (i.e. over about 200 lines or
so). I have no idea if such action is permitted to you. Then you
can see if anyone is willing to attack it. Include the available
documentation.

(Oh, good grief!)

Stephen: CBFalconer is obliquely making a point about the topicality
guidelines for this newsgroup. The topic of this newsgroup is the C
programming language, which is defined by the ISO C standard(s). If
you were to provide the information he suggests, then your question
would probably be topical -- but it would mean that we'd have to study
the software in question and learn it thoroughly enough, based our
expertise in standard C, to be able to help you solve your problem.
In effect, we would have to become experts on FFTW. I, for one, lack
the time to do so.

Since there undoubtedly already are plenty of experts on FFTW, your
best course of action is to go find them. "user923005" and James
Kuyper have already suggested some more appropriate forums.

Chuck, surely it's better to help the OP find a better place to ask
his question than to make obscure CLC-specific points that he has no
particular reason to care about.
 
U

user923005

(Oh, good grief!)

Stephen: CBFalconer is obliquely making a point about the topicality
guidelines for this newsgroup.  The topic of this newsgroup is the C
programming language, which is defined by the ISO C standard(s).  If
you were to provide the information he suggests, then your question
would probably be topical -- but it would mean that we'd have to study
the software in question and learn it thoroughly enough, based our
expertise in standard C, to be able to help you solve your problem.
In effect, we would have to become experts on FFTW.  I, for one, lack
the time to do so.

This query:
http://groups.google.com/groups/sea...0&q=fftw+group:sci.math.num-analysis&safe=off

Will show that people yammer on about FFTW in analysis all the time.
Since there undoubtedly already are plenty of experts on FFTW, your
best course of action is to go find them.  "user923005" and James
Kuyper have already suggested some more appropriate forums.

Chuck, surely it's better to help the OP find a better place to ask
his question than to make obscure CLC-specific points that he has no
particular reason to care about.

FFTW is a huge package. Posting the source would not be helpful.
However, for those who are curious, here is the home page:
http://www.fftw.org/
 
M

Malcolm McLean

CBFalconer said:
You have first to make the source of that package, written in pure
ISO standard C, available. You can publish it on some appropriate
URL if it is too large to post here (i.e. over about 200 lines or
so). I have no idea if such action is permitted to you. Then you
can see if anyone is willing to attack it. Include the available
documentation.
Don't be silly.
Some people here won't know what a Fourier transform is, but it is
sufficiently fundamental to assume that most people will.
We know that Stephen is using a Fourier transform on images. So he needs to
pass a 2-dimensional real array to the transform, and he will get a
2-dimensional complex result out. So all we need is the prototype of the
fftw fucntions, and we can tell him how to call it.

What he need to do is

1) Call a bitmap loading fucntion, such as the one I provided.

eg

unsigned char *rgb;
int width, height;
float *red;
int i, ii;

rgb = loadbmp("directory\\myfile.bmp", &width, &height);
if(!rgb)
{
/* didn't load */
}

2)
/* Now make the rgb pixel values into real numbers, range 0-1 */
red = malloc(width * height * sizeof(float));
for(i=0;i<height;i++)
for(ii=0;ii<width;ii++)
red[i*width+ii] = rgb[i * width * 3 + ii * 3]/ 255.0f;

3)
/* now we need the fftw prototype to know how to get out data into the right
format */

This bit we cannot yet do without the function prototype. Often you need to
pad to powers of 2, and probably the fucntions inist on input as well as
output being complex - which means setting the imaginary part to 0.
 
F

Flash Gordon

Malcolm McLean wrote, On 27/12/07 10:29:
Don't be silly.

I agree he is being silly.
Some people here won't know what a Fourier transform is, but it is
sufficiently fundamental to assume that most people will.

I happen to know what it is, but for reasons which have nothing to do
with my being a SW developer. I would not be surprised if a *lot* of SW
developers don't know about them, and I know some very good programmers
I've worked with don't (they don't work in a domain where the knowledge
would be of use).
We know that Stephen is using a Fourier transform on images. So he needs
to pass a 2-dimensional real array to the transform, and he will get a
2-dimensional complex result out. So all we need is the prototype of the
fftw fucntions, and we can tell him how to call it.

No, you need to know more than that.
What he need to do is

1) Call a bitmap loading fucntion, such as the one I provided.

<snip>

He does not need that as he already has the smaller fragments.
2)
/* Now make the rgb pixel values into real numbers, range 0-1 */
red = malloc(width * height * sizeof(float));
for(i=0;i<height;i++)
for(ii=0;ii<width;ii++)
red[i*width+ii] = rgb[i * width * 3 + ii * 3]/ 255.0f;

This shows many assumptions. That the package works on an array of
floats for a start, that it requires that they be normalised etc.
3)
/* now we need the fftw prototype to know how to get out data into the
right format */

This bit we cannot yet do without the function prototype. Often you need
to pad to powers of 2, and probably the fucntions inist on input as well
as output being complex - which means setting the imaginary part to 0.

Which just goes to show you need more than the function prototypes
(there may be more than one involved, there certainly was in the FFT
package I used to use).

The OP has already been pointed at a more appropriate group.
 
S

Stephen.Schoenberger

You have first to make the source of that package, written in pure
ISO standard C, available. You can publish it on some appropriate
URL if it is too large to post here (i.e. over about 200 lines or
so). I have no idea if such action is permitted to you. Then you
can see if anyone is willing to attack it. Include the available
documentation.

Don't be silly.
Some people here won't know what a Fourier transform is, but it is
sufficiently fundamental to assume that most people will.
We know that Stephen is using a Fourier transform on images. So he needs to
pass a 2-dimensional real array to the transform, and he will get a
2-dimensional complex result out. So all we need is the prototype of the
fftw fucntions, and we can tell him how to call it.

What he need to do is

1) Call a bitmap loading fucntion, such as the one I provided.

eg

unsigned char *rgb;
int width, height;
float *red;
int i, ii;

rgb = loadbmp("directory\\myfile.bmp", &width, &height);
if(!rgb)
{
/* didn't load */

}

2)
/* Now make the rgb pixel values into real numbers, range 0-1 */
red = malloc(width * height * sizeof(float));
for(i=0;i<height;i++)
for(ii=0;ii<width;ii++)
red[i*width+ii] = rgb[i * width * 3 + ii * 3]/ 255.0f;

3)
/* now we need the fftw prototype to know how to get out data into the right
format */

This bit we cannot yet do without the function prototype. Often you need to
pad to powers of 2, and probably the fucntions inist on input as well as
output being complex - which means setting the imaginary part to 0.

When I try to compile your bmp.c file you provided with my source
(under unix) problems occur. What enviornment was used to develop the
c file?
 
M

Malcolm McLean

Flash Gordon said:
Which just goes to show you need more than the function prototypes (there
may be more than one involved, there certainly was in the FFT package I
used to use).
Here's the 2d fft prototype from Basic Algorithms.

int fft2d(COMPLEX **c,int nx,int ny,int dir);

If I also gave you the compiled library file, but nothing else, you could
probably work out how to use it with only one or two experimental calls.
 
S

Stephen Montgomery-Smith

Malcolm said:
Here's the 2d fft prototype from Basic Algorithms.

int fft2d(COMPLEX **c,int nx,int ny,int dir);

If I also gave you the compiled library file, but nothing else, you
could probably work out how to use it with only one or two experimental
calls.


But the OP was asking about FFTW. If you look at
http://www.fftw.org/fftw3_doc/, you will see that it doesn't fit your
model at all.

On the other hand, I think that the OP might be better off using a
different FFT package than FFTW. To use FFTW, you really need to read
the documentation very carefully. Personally I think the FFTW
documentation is extremely good, but it is a steepish learning curve.
Unless he wants high performance, he might be better off using fft2d
from the "Basic Algorithms" package that you suggest, simply because it
is a lot easier to use.

Stephen
 
M

Malcolm McLean

When I try to compile your bmp.c file you provided with my source
(under unix) problems occur. What enviornment was used to develop the
c file?
Both Windows and a Unix mainframe.
Unfortunately the version I have in my "Basic Algorithms source" folder
appears to be an intermediate. For instance the rgb order for 24-bit and 32
bit files is wrong. Something nasty has probably happened - you get this
chaos if you write books due to publishers needing different formats to the
ones you wrote in, etc.

Probably it my evil freebie compiler from MS messing things up as I cut and
paste, if the code won't compile. I've sent you the source by email as an
attachment. It has been incorporated into BASICdraw, so it ought to work -
it's loaded a variety of bitmaps successfully.
 
F

Flash Gordon

Stephen Montgomery-Smith wrote, On 27/12/07 19:10:
Given that, how am I going to work out all possible error codes? For all
I know you could use 0 and positive primes to indicate success, negated
primes to indicate warnings, and some other numbers to indicate errors.
But the OP was asking about FFTW. If you look at
http://www.fftw.org/fftw3_doc/, you will see that it doesn't fit your
model at all.

That does not surprise me. With the package I used we made 3 or 4
function calls on to start from the data obtained from a scope and
obtain the frequency data.
On the other hand, I think that the OP might be better off using a
different FFT package than FFTW. To use FFTW, you really need to read
the documentation very carefully. Personally I think the FFTW
documentation is extremely good, but it is a steepish learning curve.
Unless he wants high performance, he might be better off using fft2d
from the "Basic Algorithms" package that you suggest, simply because it
is a lot easier to use.

If the OP needs a given level of accuracy and precision I would not
recommend using *any* FFT package written and tested by one person even
if I knew the person to be an expert in the field. So if fftw is widely
used I would be more inclined to use that and pay the penalty of the
learning curve. I would also ask in one of the places others have
advised where you will be more likely to get good advice including on
whether the library is suitable for the intended purpose.
 
S

Stephen Montgomery-Smith

Flash said:
Stephen Montgomery-Smith wrote, On 27/12/07 19:10:

If the OP needs a given level of accuracy and precision I would not
recommend using *any* FFT package written and tested by one person even
if I knew the person to be an expert in the field. So if fftw is widely
used I would be more inclined to use that and pay the penalty of the
learning curve. I would also ask in one of the places others have
advised where you will be more likely to get good advice including on
whether the library is suitable for the intended purpose.

Well, when the OP posted on sci.math.num-analysis, all he got was a
couple of replies from me saying that the FFTW docs are plenty good. I
really think that his issues are with programming rather than with
numerical analysis issues.

Next, once you understand FFT, it is actually quite easy to program
yourself. My guess is that most FFT code is relatively bug free. And
there are plenty of places to get it from. Now if I was making mission
critical stuff, I would definitely opt for FFTW, and take on the steep
learning curve of using FFTW. But if I was doing a one-off job, or
doing a homework problem for a graduate class, or something like that, I
would definitely opt for easy over correct or fast.

Anyway, if the OP really wants to use FFTW, what I think the OP should
do is sit down with a cup of strong coffee, spend several hours trying
to decode the documentation, and THEN ask questions in a newsgroup. And
then people trying to answer will see what his issues really are.

Stephen
 
C

CBFalconer

Keith said:
(Oh, good grief!)

Stephen: CBFalconer is obliquely making a point about the topicality
guidelines for this newsgroup. The topic of this newsgroup is the C
programming language, which is defined by the ISO C standard(s). If
you were to provide the information he suggests, then your question
would probably be topical -- but it would mean that we'd have to study
the software in question and learn it thoroughly enough, based our
expertise in standard C, to be able to help you solve your problem.
In effect, we would have to become experts on FFTW. I, for one, lack
the time to do so.

Since there undoubtedly already are plenty of experts on FFTW, your
best course of action is to go find them. "user923005" and James
Kuyper have already suggested some more appropriate forums.

Chuck, surely it's better to help the OP find a better place to ask
his question than to make obscure CLC-specific points that he has no
particular reason to care about.

:) Well, I have/had absolutely no idea what FFTW is or was. I
did try to give the OP some idea of what was required here. Your
response certainly filled things out nicely. I couldn't very well
represent a location to ask questions about what I am unaware of,
could I? :) However, I challenge the 'obscure' characterization.
I tried to be clear.
 
U

user923005

On Dec 27, 1:20 pm, Stephen Montgomery-Smith
Anyway, if the OP really wants to use FFTW, what I think the OP should
do is sit down with a cup of strong coffee, spend several hours trying
to decode the documentation, and THEN ask questions in a newsgroup.

This sort of advice is to be printed out, mounted in a frame, and then
put on the wall for constant perusal.

IMO-YMMV

Paraphrasal:
When in doubt in the usage of any tool, try reading the fine manual
first.
[snip]
 
K

Keith Thompson

CBFalconer said:
Keith said:
CBFalconer said:
(e-mail address removed) wrote:

I am looking for some advice/guidance on using the FFTW (fftw.org)
package to do 2D FFT on some bitmap images. I have bitmaps broken
up into small fragments and need to perform the 2D FFT on each of
those. The documentation on performing this task is a bit sparse
so I figured my best luck would be to turn to the newsgroups.

You have first to make the source of that package, written in pure
ISO standard C, available. You can publish it on some appropriate
URL if it is too large to post here (i.e. over about 200 lines or
so). I have no idea if such action is permitted to you. Then you
can see if anyone is willing to attack it. Include the available
documentation.

(Oh, good grief!)

Stephen: CBFalconer is obliquely making a point about the topicality
guidelines for this newsgroup. [...]
Chuck, surely it's better to help the OP find a better place to ask
his question than to make obscure CLC-specific points that he has no
particular reason to care about.

:) Well, I have/had absolutely no idea what FFTW is or was. I
did try to give the OP some idea of what was required here. Your
response certainly filled things out nicely. I couldn't very well
represent a location to ask questions about what I am unaware of,
could I? :) However, I challenge the 'obscure' characterization.
I tried to be clear.

Were you honestly trying to help the OP with your response? Did you
seriously expect him to post the full standard C source and
documentation for FFTW either here or someplace where we can access
it? Did you seriously expect anyone here to take the time to become
enough of an expert on it to help?

It seemed blatantly obvious to me that the OP's only sensible course
of action would be to ask elsewhere. If you didn't know anything
about FFTW, you didn't need to say anything.
 
U

user923005

CBFalconer said:
Keith said:
(e-mail address removed) wrote:
I am looking for some advice/guidance on using the FFTW (fftw.org)
package to do 2D FFT on some bitmap images. I have bitmaps broken
up into small fragments and need to perform the 2D FFT on each of
those. The documentation on performing this task is a bit sparse
so I figured my best luck would be to turn to the newsgroups.
You have first to make the source of that package, written in pure
ISO standard C, available.  You can publish it on some appropriate
URL if it is too large to post here (i.e. over about 200 lines or
so).  I have no idea if such action is permitted to you.  Then you
can see if anyone is willing to attack it.  Include the available
documentation.
(Oh, good grief!)
Stephen: CBFalconer is obliquely making a point about the topicality
guidelines for this newsgroup. [...]
Chuck, surely it's better to help the OP find a better place to ask
his question than to make obscure CLC-specific points that he has no
particular reason to care about.
:)  Well, I have/had absolutely no idea what FFTW is or was.  I
did try to give the OP some idea of what was required here.  Your
response certainly filled things out nicely.  I couldn't very well
represent a location to ask questions about what I am unaware of,
could I? :)  However, I challenge the 'obscure' characterization.
I tried to be clear.

Were you honestly trying to help the OP with your response?  Did you
seriously expect him to post the full standard C source and
documentation for FFTW either here or someplace where we can access
it?  Did you seriously expect anyone here to take the time to become
enough of an expert on it to help?

It seemed blatantly obvious to me that the OP's only sensible course
of action would be to ask elsewhere.  If you didn't know anything
about FFTW, you didn't need to say anything.

Probably CBFalconer was expecting a simple example of some code trying
to use an API.
 
M

Malcolm McLean

Keith Thompson said:
It seemed blatantly obvious to me that the OP's only sensible course
of action would be to ask elsewhere. If you didn't know anything
about FFTW, you didn't need to say anything.
Firstly, C experts who post here want to get something out of the group. If
you know C, but don't know about FFTs, then it really is worth advancing
your knowledge a notch. The FFT is a fundamental technique that is used in a
wide variety of applications, it not like a Windows API call which MS will
deprecate next week.

Secondly, we shouldn't draw topicality so tightly that algorithms cannot be
discussed at all, though a post on FFTs rather than on C interfaces to FFTs
belongs elsewhere. In this case, the OP seems to know what an FFT is, and
how it can be used. His problem is getting a C program to call a function he
understands at the mathematical level. Really clc is the right group for
this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top