使用pylab同时显示两个png图像 [英] display two png images simultaneously using pylab

查看:115
本文介绍了使用pylab同时显示两个png图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打开两个png图像文件并排显示以进行视觉比较. 我有以下代码来打开一个png文件(我是从stackoverflow.com上的unutbu获得的):

I want to open two png image files and display them side by side for visual comparison. I have this code for opening one png file (which I got from unutbu on stackoverflow.com):

import numpy as np
import pylab
import matplotlib.cm as cm
import Image

fname='file.png'
image=Image.open(fname).convert("L")
arr=np.asarray(image)
pylab.imshow(arr,cmap=cm.Greys_r)
pylab.title('title')
pylab.show()

是否可以修改此代码以打开并显示2个png文件及其标题?

Is there a way to modify this code to open and display 2 png files side by side with their own titles?

推荐答案

以下内容对我有用(您可以注释/取消注释代码中的行,以更改复合"图像的布局):

The following works for me (you can comment/uncomment the lines in the code to change the layout of the "composite" image):

#!/usr/bin/env python
#-*- coding:utf-8 -*-

import numpy as np
import pylab
import matplotlib.cm as cm
import Image

f = pylab.figure()
for n, fname in enumerate(('1.png', '2.png')):
    image=Image.open(fname).convert("L")
    arr=np.asarray(image)
    f.add_subplot(2, 1, n)  # this line outputs images on top of each other
    # f.add_subplot(1, 2, n)  # this line outputs images side-by-side
    pylab.imshow(arr,cmap=cm.Greys_r)
pylab.title('Double image')
pylab.show()

编辑:屏幕截图:

这篇关于使用pylab同时显示两个png图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆