Hi all,
I'm programming some image convolutions which I want to speed up.When
convolving an image (two-dimensional array of integers) with a filter
matrix
(the same), the center of the filter is placed on every image pixel and
the
elements on top of each other are multiplied and summed. This implies that
a
lot of the same multiplications are performed and I got an optimization
idea
but I don't know if it is possible or practical in C++.
The idea is to generate a look-up table with all the computed
multiplications, so when an output pixel is to be calculated it only
multiplies numbers not previously multiplied. Otherwise it fetches the
result from the table. Provided that a look-up operation is faster than a
multiplication, this will lead to speed improvements.
For the actual implementation I was thinking something along the lines of
having a data structure with keys being two two-tuples for the image and
filter multiplicant indexes respectively and the value would be anonymous
functions returning the multiplication of the appropriate elements. For
example multi(<4,5>, <3,2>) would return a function returning image[4][5]
*
filter[3][2]. After doing this the first, the multi data structure would
be
updated so the anonymous function at multi(<4,5>, <3,2>) next time will
return the result immediately, for example the value 98. The multi
structure
could be pre-allocated with these anoymous functions. I have a feeling
that
this might be faster than setting boolean flags in a smiliar stucture to
determine if a calculation has been performed.
Any ideas on this?
Thanks in advance!
Andreas
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|