views:

395

answers:

1

There is a good function that I need, which is implemented in Java program: ImageJ I need to understand the algorithm used there. The function has several parameters: link text

And before using FFT it converts image to a special one: The Bandpass Filter uses a special algorithm to reduce edge artifacts (before the Fourier transform, the image is extended in size by attaching mirrored copies of image parts outside the original image, thus no jumps occur at the edges)

Can you tell me more about this special transform? Actually tiling mirrored image.

I am writing on C++ and wish to rewrite that part of the program on C++.

EDIT1: I need to understand how it does that tiling mirrored image operation, may be it is special one. Actually at first it converts image to a new sized image, so for my images it will be: convertion from 600X480 to 1024X1024 sized image. How the tiling is used here?

EDIT2: Also it is hard to understand this description of tileMirrored function:

Puts ImageProcessor (ROI) into a new ImageProcessor of size width x height y at position (x,y). The image is mirrored around its edges to avoid wrap around effects of the FFT. What is meant by "...of size width x height y at position (x,y). "?

EDIT3: I implemented that bandpass filter, and it gives the same results as the original program. But, the algorithm itself in original program (also in my program) is very slow I want to use that filter not once in my program, but it calculates approximately 0.5 to 2 seconds each call (depending on parameter value). There is used an FHT transform (not FFT), is it more quicly than FFT? I think the filter itself is not optimized, please see filterLargeSmall function implementation: source code

+1  A: 

I don't know exactly how that function works, but here's the basic algorithm for a similar function:

  1. Determine the smallest power of two (call it newSize) that is larger than the larger of the two dimensions of the image (call them xSize & ySize).

  2. Create a new square image of size newSize by newSize and copy the contents of the image to the center of the new image (ie. the top-left of the image should start at (newSize / 2 - xSize / 2, newSize / 2 - ySize / 2)).

  3. Fill in the remaining pixels as follows, for each pixel at (x, y):

    • if x < (newSize / 2 - xSize / 2), copy the pixel at column (newSize / 2 - xSize / 2) + (newSize / 2 - xSize / 2) - x and row y.
    • if y < (newSize / 2 - ySize / 2), copy the pixel at row (newSize / 2 - ySize / 2) + (newSize / 2 - ySize / 2) - y and column x.
    • if both of the above are true, copy the pixel at column (newSize / 2 - xSize / 2) + (newSize / 2 - xSize / 2) - x, row (newSize / 2 - ySize / 2) + (newSize / 2 - ySize / 2) - y.
    • if x > (newSize / 2 + xSize / 2), copy the pixel at column (newSize / 2 + xSize / 2) + (newSize / 2 + xSize / 2) - x and row y.
    • if y > (newSize / 2 + ySize / 2), copy the pixel at row (newSize / 2 + ySize / 2) + (newSize / 2 + ySize / 2) - y and column x.
    • if both of the above are true, copy the pixel at column (newSize / 2 + xSize / 2) + (newSize / 2 + xSize / 2) - x and row (newSize / 2 + ySize / 2) + (newSize / 2 + ySize / 2) - y.

There are probably libraries that will make this easier (ie. flipping and copying image data), but I am not familiar with C++, and this should be pretty easy to code yourself as long as performance isn't a huge issue. Be careful of rounding issues for images with odd dimensions: make sure they're consistent.

tloflin
It seems too be correct, At least it determines the coordinates where to put image right to the middle of a new size image.Thanks! I still will look at source, and may be they do something different.
maximus