Thank you for your previous post. Because of this, I have managed to get 
the following code working.  However, in function getPixel, in order to get 
the commented out code to work, I need to pass imv (ImageView) and 
pixelArray (the image)  into getPixel.  So when I change
 imv.getView().scene().sigMouseMoved.connect(self.getPixel), which works 
to
imv.getView().scene().sigMouseMoved.connect(lambda: self.getPixel(imv, 
pixelArray)

I get an error informing me that there is no positional argument for pos; 
thus,
Traceback (most recent call last):
  File "C:\Users\scsssh\source\repo1\Weasel\Weasel.py", line 736, in 
<lambda>
    lambda: self.getPixel(imv, pixelArray))
TypeError: getPixel() missing 1 required positional argument: 'pos'

So, I think the question is how do I pass imv and pixelArray into getPixel 
as function arguments.

    def getPixel(self, pos):
        try:
            print ("Image position: {}".format(pos))
           # container = imv.getView()
          #  if container.sceneBoundingRect().contains(pos): 
           #     mousePoint = container.getViewBox().mapSceneToView (pos) 
           #     x_i = round(mousePoint.x()) 
             #   y_i = round(mousePoint.y()) 
            #    if x_i > 0 and x_i < img.shape [ 0 ] \
            #        and y_i > 0 and y_i < img.shape [ 1 ]: 
             #      print( "({}, {}) = {:0.2f}" . format ( x_i , y_i , img 
[ x_i , y_i ])) 

On Monday, February 17, 2020 at 3:19:11 PM UTC, Stephen Shillitoe wrote:
>
>
> I have built a PyQt5, Python 3.7 windows application that uses PyQtGraph 
> to view monochrome (greyscale) Magnetic Resonance DICOM images. As I move 
> the mouse pointer over the image, I would like to display the value of the 
> pixel under the pointer on the window. There is no obvious (to me) 
> functionality in PyQtGraph to do this. I would be very grateful for any 
> suggestions by more experienced developers of how to do this. Here is an 
> edited code segment showing how I display the image (pixelArray) in an MDI 
> subwindow.
>
> layout = QVBoxLayout()
> widget = QWidget()
> widget.setLayout(layout)
> self.subWindow.setWidget(widget) 
>
> imageViewer = pg.GraphicsLayoutWidget()
> viewBox = imageViewer.addViewBox()
> image= pg.ImageItem(border='w')
> viewBox.addItem(image)
> imageView = pg.ImageView(view=viewBox, imageItem=image)
> layout.addWidget(imageView)
> imageView.setImage(pixelArray)
>
>

-- 
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/20d03bc7-f269-4ff5-aab9-e88b907dbbed%40googlegroups.com.

Reply via email to