Hi,

You can load images into numpy arrays (usable by ImageItem, ImageView etc) 
using the scipy.ndimage.imread function. I think it relies on having the 
Python Image Library (PIL) installed. A more modern version of that library 
is Pillow, which you could also use to load image data.

Limitations are though that the ImageView expects each image to have the 
same dimensions.

Simple modification of ImageView example to demonstrate (specify your image 
files on command line).

#!/usr/bin/env python3


import numpy as np
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph as pg
from argparse import ArgumentParser
from scipy.ndimage import imread

argparser = ArgumentParser(description='Load images and display using 
pyqtgraph ImageView widget.')
argparser.add_argument('input_images', help='Input filename(s) of images', 
nargs='+')
args = argparser.parse_args()

imagelist = []
for filename in args.input_images:
    print("Loading {}...".format(filename))
    image = imread(filename)
    imagelist.append(image)
    print('Image shape: {}{}'.format(imagelist[len(imagelist)-1].shape, '' 
if imagelist[len(imagelist)-1].shape == imagelist[0].shape else ' *'))
data=np.stack([ i for i in imagelist if i.shape==imagelist[0].shape ], 0)
if len(args.input_images) != data.shape[0]:
    print('Warning: Shape of all input files must match. Those marked with 
* are skipped.')

# Interpret image data as row-major instead of col-major
pg.setConfigOptions(imageAxisOrder='row-major')

app = QtGui.QApplication([])

## Create window with ImageView widget
win = QtGui.QMainWindow()
win.resize(800,800)
imv = pg.ImageView()
win.setCentralWidget(imv)
win.show()
win.setWindowTitle('pyqtgraph example: ImageView')

## Display the data
imv.setImage(data)

## Set a custom color map
colors = [
    (0, 0, 0),
    (45, 5, 61),
    (84, 42, 55),
    (150, 87, 60),
    (208, 171, 141),
    (255, 255, 255)
]
cmap = pg.ColorMap(pos=np.linspace(0.0, 1.0, 6), color=colors)
imv.setColorMap(cmap)

## Start Qt event loop unless running in interactive mode.
if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()




On Monday, 29 October 2018 15:20:41 UTC+10:30, Dennis Norton wrote:
>
> I'm wondering if there is a convenient way to use the ImageView class to 
> display images either from a list of files in a directory or from a large 
> binary file consisting of multiple frames.
>
> Could we create a generator which yields the numpy arrays to display?
>
> Thanks.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/d1681786-8d9c-4a97-a3b5-78f32223e481%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to