Re: code optimization help
- From: Peter Boettcher <boettcher@xxxxxxxxxx>
- Date: Fri, 02 Jun 2006 13:38:02 -0400
[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/
.
- References:
- Re: code optimization help
- From: Peter Boettcher
- Re: code optimization help
- From: Peter Bone
- Re: code optimization help
- Prev by Date: Simulink to Matlab script
- Next by Date: Re: creating dynamic filename
- Previous by thread: Re: code optimization help
- Next by thread: International Symposium CompIMAGE 2006 - Just a small Reminder
- Index(es):
Relevant Pages
|