Incorrect coordinate system when viewing image using PyQtGraph

3

I have the following test image:

And the following Python script to be able to visualize it using the PyQtGraph package:

import sys
from PyQt4 import QtGui

from PIL import Image
import numpy as np
import pyqtgraph as pg

app = QtGui.QApplication(sys.argv)
img = Image.open('mickey.tif')
a = np.array(img)
pg.image(a)

sys.exit(app.exec_())

When running the script, the result is as follows:

Where it can be seen that the NumPy array containing the image matrix is interpreted by PyQtGraph according to an inverted coordinate system with respect to the one used by usual programs for image management: OS viewer, web navigation engines; even Matlab, where the NumPy matrix is interpreted correctly.

One solution is to visualize the transposed arrangement, using pg.image(a.T) , but this will only be useful if the image is of a single channel, since an image of more channels (RGB, for example) only passes one channel to the function pg.image() , resulting in:

What is the correct or most appropriate way to obtain the desired coordinate system? I have searched the documentation and can not find anything useful. I suppose that using the transpose can complicate the extraction of information from the image: as coordinates from an ROI, pixel values and their coordinates.

    
asked by OSjerick 02.02.2016 в 20:42
source

2 answers

2

In the creation of the ImageView you can pass an argument transform that indicates how to transform the coordinate system. This argument is of type Transform3D .

I have not tried to see if it works, but the code should be something like this:

# rotación de 90 grados alrededor del origen (0,0,0)
tr = pg.Transform3D()
tr.rotate(90, 0, 0, 0)

pg.image(a, transform=tr)

You'll tell me if it works.

CORRECTION : The transform method of the ImageView class requires the argument to be QTransform . The corrected previous code would be.

# rotación de 90 grados alrededor del origen (0,0,0)
tr = pg.QtGui.QTransform()
tr.rotate(90)

pg.image(a, transform=tr)
    
answered by 04.02.2016 / 10:49
source
0

And does not it serve you simply to rotate the image before converting it into a ndarray ?, that is:

a = np.array(img.rotate(90))
    
answered by 05.02.2016 в 20:33