Re: code optimization help




[adding in quotes from the thread. Please quote appropriately for context]

Peter Boettcher wrote:

Peter Bone <peterbone@xxxxxxxxxxx> writes:

I need to make this code as fast as possible. It creates an image
from a source image of a particular mapping transformation using an
interpolation lookup table for speed. The lookup table is a 2D array
the same size as the output image, each element of which is a list

I think the problem is the data structure itself. You might be better
off reconsidering the entire algorithm, rather than optimizing this
cell array version.

The usual way to do mapping transforms is to iterate over the
*destination* image, reverse map the coordinate into the source image
(as a fractional pixel location), then interpolate that fractional
location from the surrounding locations. This is likely to be much
faster. I can't tell if it fits into your application or not.

If you have the image processing toolbox, there are some functions
that do this stuff for you. If not, then interp2 will help anyway.

Peter Bone <peterbone@xxxxxxxxxxx> writes:

The method of calculating the source pixels for each destination
pixel is what I originally did but it was very slow because my
transformation equations are complex and take a long time to
execute. Creating the lookup table is done using the same technique
but the source pixel values are stored in a lookup table so that the
redundancy of performing the same geometrical transformations on
multiple images is removed. After calculating the lookup table I can
now create transformed image much faster.

Makes sense. But you are storing more than just the transformed
pixels. You are converting the interpolation to a lookup table as
well. I think that is where the problem is. Try a simpler lookup
table, which is just the fractional source pixel locations. Use one
2D array for x coords, and another for y coords.

Then feed these directly into interp2 with each new source image, and
the interpolation method of your choice. That should be much faster.

Even if you are using some strange interpolant, it should still be
faster to interpolate each time than to try to precompute some portion
of.


I have the image processing toolbox but I can't see how I can use it
to perform a completely arbitrary spacial transformation. I think I
have to make a custom tform structure but it doesn't seem to say how
to make a custom tform.

maketform('custom', ...)

You provide forward and inverse transforms as function handles. These
functions take a list of coordinates and return a new list of
coordinates, using whatever technique you want.

But this won't help with the precomputed coordinates that you want.


--
Peter Boettcher <boettcher@xxxxxxxxxx>
MIT Lincoln Laboratory
MATLAB FAQ: http://www.mit.edu/~pwb/cssm/
.



Relevant Pages

  • Re: code optimization help
    ... interpolation lookup table for speed. ... of pixels from the source image that contribute to the corresponding ... contribute to the output pixel. ...
    (comp.soft-sys.matlab)
  • Re: pow/log functions in fixed point
    ... For a table lookup method to work efficiently on most embedded processors ... each for both expand logwith quadratic interpolation. ... a linear one (referring to Eq. ... there is no reason that the "a1" coefficient ...
    (comp.dsp)
  • Re: DTS Lokup %
    ... My Lookup Query looks like this ... Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP) www.SQLDTS.com - The site for all your DTS needs. ... > It works in ExecuteSQL task but it doesnt work in Data Transformation Lookup.. ... I need specifically in lookup because while transformation I have to find corresponding value.. ...
    (microsoft.public.sqlserver.dts)
  • Re: sample rate conversion: Windowed-Sinc v.s. Lagrange v.s. B-Spline?
    ... >>> the simplest and best method is to use a lookup table based (Kaiser windowed ... >>> but finite upsampling ratio and then use linear interpolation in between. ... >> Or would the windowed sinc need to be wider than the polynomial ... besides being better than the polynomial interpolation. ...
    (comp.dsp)
  • Re: Linear interpolation
    ... I teach a some old interpolation techniques in my database classes; ... Classic linear formula: ... FROM LookUp AS F1 LookUp AS F2 ...
    (microsoft.public.sqlserver.programming)