Hi All,

I have made this test program so as to check how LineSegmentRoi works and 
it seems that there is a bug.
Since getArrayRegion seems to do some smart processing so as to deal with 
non vertical or horizontal lines, I have added a horizontal line and asked 
for a profile.

Values should be (254 0 0) for all the pixels but I get some wrong values 
like (255, 13, 14), (255, 228, 23) among good values.

Below is my code
import sys
from itertools import cycle

from pyqtgraph.Qt import QtCore, QtGui, QtWidgets
import pyqtgraph as pg
import cv2
import numpy as np

pg.setConfigOptions(imageAxisOrder='row-major')


class MainWindow(QtWidgets.QMainWindow):

    sigKeyPress = QtCore.pyqtSignal(object)

    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)

        self.line = None

        self.sigKeyPress.connect(self.key_pressed)
        self.setWindowTitle('My Image Viewer')
        self.graphWidget = pg.GraphicsLayoutWidget()
        self.setCentralWidget(self.graphWidget)
        self.view_box = self.graphWidget.addViewBox(lockAspect=True)
        self.view_box.invertY(True)

        self.img_item = pg.ImageItem(border='w')
        self.view_box.addItem(self.img_item)
        self.img_item.setZValue(10)

        # image taken from https://www.hisour.com/rgb-color-model-24867/
        self.image = cv2.imread('RGB-color-model.jpg')
        print(self.image.shape)
        self.image = cv2.cvtColor(self.image, cv2.COLOR_BGR2RGB)
        self.img_item.setImage(self.image)
        #

    def _update(self):
        


*"""        :return:        """        *pass

    def update_profile_analyzer(self):
        

*"""        Update statistics measures on selected areas.        *



*If no selected area, update statistics on the whole image.        
Returns:        """        *# LINE PLOT
        if not self.line:
            return
        #
        plot, l_coords = self.line.getArrayRegion(self.image, self.img_item,
 returnMappedCoords=True)
        print(l_coords)
        print(plot)
        plot = plot.astype(self.image.dtype)
        print(plot)
        #
        print(self.image[164, 246:296])

    def add_line(self):
        





*"""        Add a line that will give us the pixel values along that 
line        Returns:        """        *if self.line:
            # cannot add more than 1 profile line
            return
        # define a line length long enough but not larger than the 
reference image
        self.line = pg.LineSegmentROI([(246, 164), (296, 164)], removable=
True)
        self.view_box.addItem(self.line)
        self.line.sigRegionChangeFinished.connect(self
.update_profile_analyzer)
        #
        self.update_profile_analyzer()

    def keyPressEvent(self, ev):
        super().keyPressEvent(ev)
        self.sigKeyPress.emit(ev)

    def key_pressed(self, l_ev):
        if l_ev.key() == QtCore.Qt.Key_Escape:
            self.close()
        elif l_ev.key() == QtCore.Qt.Key_Right:
            self._update()

app = QtWidgets.QApplication(sys.argv)

my_win = MainWindow()

my_win.show()
my_win.add_line()

app.exec_()

I do not see what is wrong in my code so I tend to think that it is a bug.
Do you confirm ?

Jean-Pierre

-- 
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/c62ba4ff-f165-4bc3-85d9-912865f814c2n%40googlegroups.com.

Reply via email to