1

Note: This question is originally asked at OpenCV forum a couple of days ago.

I'm building an image processing program which extensively uses 2-dimensional dft, discrete Fourier transform. I'm trying to speed up so as to run in real-time.

In that application I only use a part of dft output specified by a rectangular ROI. My current implementation follows the steps below:

  1. Compute dft of the input image f (typically size of 512x512) and get the entire dft result F
  2. Crop F into a pre-specified region of interest (ROI, typically size of 32x32, located arbitrary), R

This process basically works well, but involves useless calculation since I only need partial information of F. I'm looking for a way to accelerate this calculation only by computing necessary part of dft.

I found OpenCV with Intel IPP computes dft with Intel IPP functions, which results in an order of magnitude faster than naive OpenCV implementation. I'm wondering if I can even accelerate this computation by only computing pre-specified frequency domain of dft.

Since I'm new to OpenCV, I've lost my way here, so I hope you could provide a way to do this.

Kindly note that I don't mean to do a dft to an ROI of an image, i.e. dft(ROI(f)), but I want to compute ROI(dft(f)).

Thanks in advance.

mhirano
  • 11
  • 3
  • Do you have any source code you can provide? It may be a good question for [Code Review](https://codereview.stackexchange.com/) as you have functioning code but want to know how to improve performance. – Lex May 25 '18 at 04:02
  • Thank you for the pointer to Code Review. Unfortunately, I can provide no code fragment that tells more than in the question. I'll think about migrating from SO to Code Review. – mhirano May 25 '18 at 04:18

1 Answers1

3

Just a partial idea.

The DFT is separable. It is always computed by first applying the FFT algorithm to rows of the image, then to the columns of the result (or the other way around, the order doesn't matter).

If you want only an ROI of the output, in the second step you only need to process the columns that fall within the ROI.

I don't think you'll find a way to compute only a subset of frequencies along each 1D row/column. That would likely entail hacking your own FFT, which will likely be more computationally expensive than using the one in IPP or FFTW.

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
  • Much appreciated. Is it possible to go even faster by computing frequencies that fall within the ROI at the first stage? (or full computation of the first stage is mandatory for the second process in this case?) – mhirano May 25 '18 at 08:01
  • @mhirano: I guess it is possible, but the tools that I know do not allow to compute only a subset of the FFT, they always compute the whole thing. If you can, compute, for each row, only the output of the FFT that falls within the columns of your ROI. Then compute for those columns, only the output of the FFT that falls within the ROI. – Cris Luengo May 29 '18 at 18:04