Gre*_*che 6 python image matplotlib
我正在脚本中编写一些迭代图像处理算法(我不想使用iPython),我希望可视化每次迭代后生成的图像.在Matlab中很容易做到,而不会阻塞主线程,但我很难在Python中做到这一点.
在pylab中,show()函数是阻塞的,我需要关闭窗口以继续执行我的脚本.我看到有些人使用了ion()函数,但在我的情况下没有效果,例如:
pylab.ion()
img = pylab.imread('image.png')
pylab.imshow(img)
pylab.show()
Run Code Online (Sandbox Code Playgroud)
还在阻止.我也看到有人说"使用绘画代替情节"可以解决这个问题.但是,我不是在使用情节,而是使用imshow/show,这里有什么我想念的吗?
另一方面,PIL也有一些显示功能,但它似乎生成一个临时图像然后用imagemagick显示它,所以我假设这里没有办法显示图像并用这种方法在同一窗口中更新它.
我正在使用Ubuntu 10.10.
有没有人知道如何简单地做,或者我是否必须开始使用像Qt这样的东西来拥有一个我可以轻松更新的最小GUI?
你可以尝试将你的 pylab 内容线程化:
import pylab
import threading
pylab.ion()
img = pylab.imread('map.png')
def create_show():
pylab.imshow(img)
pylab.show()
thread = threading.Thread(target=create_show)
thread.start()
#do your stuff
thread.join()
Run Code Online (Sandbox Code Playgroud)