[PyQt] Pixel Manipulation Very Slow?

Nick Gaens mail at nickgaens.com
Fri Aug 20 13:46:32 BST 2010


Hello,

First, you might want to change both range()-methods in the for-loops to *
xrange()*, since the latter is way faster.

Anyway, to recognize which calls are slowing down your calculations, try to
profile your application (using e.g. valgrind).

In an ultimate case, when in need of some serious responsiveness on
multi-megapixel-images, you can use SIP, SWIG, Cython or cTypes  to let a
C(++)-method do this job at a blazing speed: I once reached sub-second color
conversion runs on a 16Mpixel image on an average laptop CPU.. Python is ok
for this as long as it's good enough for you, but since it's quite slow by
implemenation, you might want to take a look at some alternative approaches.


On Fri, Aug 20, 2010 at 2:21 PM, zhang jian <zhangmdev at gmail.com> wrote:

> Hello,
>
> This is my first post. I want to write a simply app layering several images
> each with different weighting. This problem is pixel manipulation by QImage
> appears to be quite slow. My code is:
>
>         w = image.width()
>         h = image.height()
>
>         for j in range(h):
>             for i in range(w):
>                  col = QtGui.QColor(image.pixel(i, j))
>
>                  col.setRed(col.red()*self.fKd)
>                  image.setPixel(i, j, col.rgb());
>
>
>
> painter.drawImage(0, 0, image)
>
> Just one image changed in red channel. It took about 5 seconds to redraw a
> 1280 X 720 image any time I changed Kd. Far from interactive. I'd like to
> know is there any way to do stuff like that faster? Or calculating a million
> pixels in PyQt is just a bad idea? Any advice should be appreciated.
>
> Thanks,
>
> zhang
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>



-- 
Nick Gaens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100820/aa78edd3/attachment.html>


More information about the PyQt mailing list