[SciPy-User] my own hist_equal (Vectorization gods required! ; )

Michael Aye kmichael.aye@googlemail....
Fri Apr 9 13:14:46 CDT 2010


Hi David,

thanks for your input!

>
> def hist_equal(data):
>     I = data.ravel().argsort()
>     return numpy.linspace(0, 255, I.size)[I].reshape(data.shape)
>
I quickly pasted it into my code, but something must be wrong here, as
the resulting image is totally messed up
(see
http://dl.dropbox.com/u/139035/FC21A0000000_08239230753F1C.IMG.equal.bad.png
where it should look more like
http://dl.dropbox.com/u/139035/FC21A0000000_08239230753F1C.IMG.equal.png
)

> If this isn't acceptable, you should be able to speed your code up a bit by doing the following:
> 1) - precomputing round((cdf - cdfmin)*255/nPixels)
> 2) - getting rid of numpy.where (which tends to be slow) and just using boolean/fancy indexing (fast) eg:
> nData[data == lum]
>
tried these and they left the speed roughly similar, but nevertheless
important that you reminded me of fancy indexing, thanks! ;)

Wes's numpy.putmask however sped up things a bit at least, maybe 2 to
3 times. (Thanks Wes!)
But shouldn't the mapping to each luminance value be 'puttable' as
well without this darn loop? ;)

Have a good weekend!
Best regards,
Michael


More information about the SciPy-User mailing list