What is the fastest way to draw an image from discrete pixel values in Python?

前端 未结 5 1853
时光取名叫无心
时光取名叫无心 2020-12-07 18:41

I wish to draw an image based on computed pixel values, as a means to visualize some data. Essentially, I wish to take a 2-dimensional matrix of color triplets and render it

5条回答
  •  北海茫月
    2020-12-07 19:19

    I think you use PIL to generate an image file on the disk, and you later load it with an image reader software.

    You should get a small speed improvement by rendering directly the picture in memory (you will save the cost of writing the image on the disk and then re-loading it). Have a look at this thread https://stackoverflow.com/questions/326300/python-best-library-for-drawing for how to render that image with various python modules.

    I would personally try wxpython and the dc.DrawBitmap function. If you use such a module rather than an external image reader you will have many benefits:

    • speed
    • you will be able to create an interactive user interface with buttons for parameters.
    • you will be able to easily program a Zoomin and Zoomout function
    • you will be able to plot the image as you compute it, which can be quite useful if the computation takes a lot of time

提交回复
热议问题