Re: code optimization help



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
of pixels from the source image that contribute to the corresponding
element of the output image. So lookupRegion represents a single
pixel of the output image. lookupRegion(:,1) and lookupRegion(:,2)
are the x and y coordinates of the contributing source image
pixels. lookupRegion(:,3) are the fraction that those pixels
contribute to the output pixel (for sub pixel accuracy). The lookup
table is created using a seperate function. So can anyone optimize
this code further or think of a faster way of doing it?

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 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. ... reverse map the coordinate into the source image ... transformation equations are complex and take a long time to ... You are converting the interpolation to a lookup table as ...
    (comp.soft-sys.matlab)
  • Re: Image scaling (sign taken from a Pc Pen)
    ... Min/Maxfunctions) so as to not overflow since each pixel is represented as a byte with a 0-255 range. ... than the main image processing loop need only query the lookup table for the corresponding range adjusted value rather than having ... the method to produce the LUT is increased. ...
    (microsoft.public.vb.winapi.graphics)
  • Re: Questions about the Log Polar Transform.
    ... >transform maps radial lines in Cartesian space to horizontal lines in polar ... coordinates of the pixel in the source image. ... If you want a log-polar output image, not just a polar one, you'll also ...
    (sci.image.processing)
  • Re: Newbie to Forums, SIMD question
    ... Peter Dove wrote: ... > for every pixel in order to apply a gamma value. ... To generate the lookup table (C code for a fixed 1001-entry table, ... This should leave you with a value of ~8-10 bits of precision. ...
    (comp.lang.asm.x86)
  • Re: using a pixel shader for undistorting an image?
    ... This is what you plan to use as a lookup table ... on the GPU right? ... pixel transforms are given is too computationally intensive to move to ... calibration, now I need to use the results of it to undistort the ...
    (sci.image.processing)