4 ms·
Using PIL's im.convert to do lightening and desaturation is a great trick! I've used PIL and love it for ease of use, but had to look elsewhere for performance.
by dahart 11y ago
Using PIL's im.convert to do lightening and desaturation is a great trick! I've used PIL and love it for ease of use, but had to look elsewhere for performance. It strikes me as funny how the function name and docs saying that convert() is for color space conversion prevented me from considering other possibilities.
The numpy example is amusing though; sending a python lambda into a numpy op, especially a lambda that does something numpy is designed to do natively... no wonder it went slow. But if they'd used native numpy ops, it would be comparable to this PIL solution, with or without pre-multiplying the matrix ops. I haven't tried it, but it's possible it would even be faster. And you have a lot more options for non-affine operations with numpy, whereas the 4x3 is PIL's limit. Making numpy fast makes you have to organize your programs differently, but it is well worth learning.