1

I want to export Numpy ndarray to png files as image using pyqtgraph.

import pyqtgraph as pg
import pyqtgraph.exporters
import h5py

h5file = h5py.File('hoge.h5',"r")
images = h5file['image'].value

for i in xrange(images.shape[0]):
    img = pg.image(images[i])
    exporter = pg.exporters.ImageExporter(img.view)
    exporter.export('image_'+str(i)+'.png')

images is (N,128,128,3) shaped numpy ndarray. (N is the number of images I require)

When the code run, the image window is displayed N-times because of pg.image. I want these image windows NOT displayed.

Please give me some ideas about this.

T.Mot
  • 11
  • 1
  • 2

1 Answers1

0

This might not be a pretty solution but you could plot all your images in the same ImageWindow instead of one separate per plot.

import pyqtgraph as pg
import pyqtgraph.exporters
import numpy as np

images = np.random.random((3,128,128))

imagewindow = pg.image()

for i in xrange(images.shape[0]):
    img = pg.ImageItem(images[i])
    imagewindow.clear()
    imagewindow.addItem(img)
    exporter = pg.exporters.ImageExporter(imagewindow.view)
    exporter.export('image_'+str(i)+'.png')

Edit: I also suggest not going via pyqtgraph, and instead saving directly, see Saving a Numpy array as an image

Community
  • 1
  • 1
luddek
  • 869
  • 5
  • 7