[SciPy-User] Help optimizing an algorithm
Wed Jan 30 11:47:37 CST 2013
Right, I should have clarified that g is different for each pixel. It looks
like scipy.interpolate.interp1d ought to do exactly what I want, though
I'll have to handle the bounds conditions (where the input data is outside
the range of the interpolation function that interp1d generates) myself.
Thanks for the help!
On Wed, Jan 30, 2013 at 9:38 AM, <email@example.com> wrote:
> On Wed, Jan 30, 2013 at 12:29 PM, Chris Weisiger <firstname.lastname@example.org>
> > We have a camera at our lab that has a nonlinear (but monotonic)
> response to
> > light. I'm attempting to linearize the data output by the camera. I'm
> > this by sampling the response curve of the camera, generating a linear
> > of the sample, and mapping new data to the linear fit by way of the
> > In other words, we have the following functions:
> > f(x): the response curve of the camera (maps photon intensity to reported
> > counts by the camera)
> > g(x): an approximation of f(x), composed of line segments
> > h(x): a linear fit of g(x)
> > We get a new pixel value Y in -- this is counts reported by the camera.
> > invert g() to get the approximate photon intensity for that many counts.
> > then we plug that photon intensity into the linear fit.
> > Right now I believe I have a working algorithm, but it's very slow
> (which in
> > turn makes testing for validity slow), largely because inverting g()
> > involves iterating over each datapoint in the approximation to find the
> > that bracket Y so that I can linearly interpolate between them. Having to
> > iterate over every pixel in the image in Python isn't doing me any favors
> > either; we typically deal with 528x512 images so that's 270k iterations
> > image.
> > If anyone has any suggestions for optimizations I could make, I'd love to
> > hear them. My current algorithm can be seen here:
> > http://pastebin.com/mwaxWHGy
> np.searchsorted or scipy.interp1d
> If g is the same for all pixels, then there is no loop necessary and
> can be done fully vectorized
> > -Chris
> > _______________________________________________
> > SciPy-User mailing list
> > SciPy-User@scipy.org
> > http://mail.scipy.org/mailman/listinfo/scipy-user
> SciPy-User mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-User