[SciPy-User] scipy.optimize lmder_ and dlopen / dlsym

Sebastian Haase seb.haase at gmail.com
Thu Jan 20 11:05:26 EST 2011


Hi Gregor,

sure. If you don't mind I would like to take a look at your code.
My images are time series of 512x512 pixels. But my spots are only few
pixels in diameter, so that I can - after some filtering and
segmentation - crop the image into many small 7x7 piclets. Those are
the ones where I have to do the 2d Gaussian fitting.
Do you have any pointer on where I can learn about the part where you
say "solving the normal equations instead of qr " ... ?

Thanks,
Sebastian



On Thu, Jan 20, 2011 at 4:45 PM, Gregor Thalhammer
<Gregor.Thalhammer at gmail.com> wrote:
>
> Am 18.1.2011 um 16:38 schrieb Sebastian Haase:
>
>> Hi,
>> I was trying to do some 2d Gaussian fitting on my image data using
>> scipy.optimize.leastsq.
>> This worked, but it still takes about 1ms for fitting sigma and
>> peakHeight on a 7x7 pixel image area.
>> So I'm thinking about speeding things up:
>> Writing the objective function and the Jacobian in C (I like using
>> SWIG) would be one thing.
>> But I'm also thinking that for such small problems, the overhead of
>> function calls back and forth in Python (for each parameter set
>> evaluation) would be problematic.
>>
>
> Once I also once wrote a program to fit a 2d Gaussian to an image, which in my case was about 500x500 in size. Contrary to your approach, I ended up with a pure python replacement for the minpack based leastsq to get better performance. I did some profiling, for my data size most time is indeed spent for calculating the objective function, Jacobian and some linear algebra (dot, qr).
> minpack contains its own implementation for the qr decomposition, which is slower than optimized LAPACK routines. Furthermore, for my data size solving the normal equations instead of qr gave a large speed boost. For your image size the Python overhead might be a problem, cython might be helpful in this regard. In my case, a good choice of the starting values was the most important point to improve the speed. A good algorithm is more important than a fast implementation. If you are interested, I can share the code.
>
> Gregor



More information about the SciPy-User mailing list