Bug in LineSegmentRoi ?

26 views
Skip to first unread message

jpmor...@gmail.com

unread,
Aug 24, 2020, 5:02:14 AM8/24/20
to pyqtgraph
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
Reply all
Reply to author
Forward
0 new messages