HEY! I GOT IT! Thank you so much! 
This may seem like I'm really needy, but I have one more thing - do you 
know how I might have just the image and remove the default ROI and 
Histogram capabilities? I'm trying to follow the design of the pyqtgraph 
example file "imageAnalysis.py" that I've attached because I like the 
format of that better. Could you help me out one more time?

On Tuesday, August 15, 2017 at 3:01:03 PM UTC-7, Christopher Mullins wrote:
>
> No, sorry that's just my badly named object.  I'll explain a little more.
>
> QGraphicsView is a Qt class.  I created the .ui file within qtdesigner, 
> which should ship with your qt distribution.  Try opening up that file with 
> qtdesigner and you should get a better idea -- and there are multiple good 
> youtube tutorials on that particular tool.  Look for "Graphics View" under 
> the display items on the left, that's all that is.
>
> After that's been dragged into my main window, I right-clicked and 
> promoted that widget to an ImageView, as per these instructions on 
> embedding pyqtgraph widgets in PyQt [2].
>
> From there, you can see I used the "uic" tool from within the run.py 
> script to access the UI elements.  (Another option is to use uic on the 
> command line to generate a python file from the UI file and use that.)
>
> [2] 
> http://www.pyqtgraph.org/documentation/how_to_use.html#embedding-widgets-inside-pyqt-applications
>
> On Tue, Aug 15, 2017 at 5:17 PM, Arun Shriram <[email protected] 
> <javascript:>> wrote:
>
>> Hey Christopher,
>> This is great! Yes, embedding in PyQt was exactly what I wanted. Thank 
>> you for helping out! However, I'm not quite exactly how to go about this. 
>> Sorry, I'm kind of a newbie with PyQt and pyqtgraph, so I have a few 
>> questions. Should I redefine QGraphicsView as a class? Is that what you're 
>> doing in line 43 of the UI code you attached?
>> Thanks again,
>> Arun
>>
>> On Tuesday, August 15, 2017 at 2:09:34 PM UTC-7, Christopher Mullins 
>> wrote:
>>>
>>> Sounds like what you want is to embed this window into PyQt.  All you 
>>> need to do is define a QGraphicsView in your main window somewhere, and 
>>> promote it to an ImageView (header file should just read: pyqtgraph).  
>>>
>>> Then simply call the setImage function on it.  Here's a modified gist 
>>> with a simple example that might do what you want [1].
>>>
>>> [1] 
>>> https://gist.github.com/chrismullins/e5ce27ace4f3aa11fb564611e37698bd
>>>
>>>
>>> On Tue, Aug 15, 2017 at 4:26 PM, Arun Shriram <[email protected]> 
>>> wrote:
>>>
>>>> Hello,
>>>>
>>>> I'm trying to do some image analysis with a .tif file (that I've 
>>>> converted into a numpy.ndarray), and I'm trying to incorporate pyqtgraph 
>>>> with my current PyQt GUI. It seems that the best way to get the image 
>>>> analysis controls I need (ROI and histogramLUT) is to call 
>>>> pyqtgraph.image() on my data, as such:
>>>>
>>>> import pyqtgraph as pg
>>>>
>>>> data = tif_file.array() # assume this gives me numpy.ndarray 
>>>>
>>>> pg.image(data)
>>>>
>>>> This automatically creates an ImageWindow with all the stuff I want. 
>>>> Great! However, I'm wondering how I can make all the items in this 
>>>> ImageWindow fit in my preexisting GUI. I would like the users to have the 
>>>> image and controls display in the same window they're operating on, rather 
>>>> than display in a new window. Is this possible at all? I would really 
>>>> appreciate it if someone could help me out. Please let me know if you need 
>>>> me to explain anything more clearly.
>>>>
>>>> Thanks,
>>>> Arun Shriram
>>>>
>>>> -- 
>>>> 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/0ef2e976-939f-4224-9693-e69955c7c779%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/pyqtgraph/0ef2e976-939f-4224-9693-e69955c7c779%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>> -- 
>> 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] <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/pyqtgraph/867d6aeb-3002-491c-89c4-2253b96ee719%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/pyqtgraph/867d6aeb-3002-491c-89c4-2253b96ee719%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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/7d1311fa-a34d-4199-8dc6-2ac91bd7cad6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
# -*- coding: utf-8 -*-
"""
Demonstrates common image analysis tools.

Many of the features demonstrated here are already provided by the ImageView
widget, but here we present a lower-level approach that provides finer control
over the user interface.
"""
import initExample ## Add path to library (just for examples; you do not need this)

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


# Interpret image data as row-major instead of col-major
pg.setConfigOptions(imageAxisOrder='row-major')

pg.mkQApp()
win = pg.GraphicsLayoutWidget()
win.setWindowTitle('pyqtgraph example: Image Analysis')

# A plot area (ViewBox + axes) for displaying the image
p1 = win.addPlot()

# Item for displaying image data
img = pg.ImageItem()
p1.addItem(img)

# Custom ROI for selecting an image region
roi = pg.ROI([-8, 14], [6, 5])
roi.addScaleHandle([0.5, 1], [0.5, 0.5])
roi.addScaleHandle([0, 0.5], [0.5, 0.5])
p1.addItem(roi)
roi.setZValue(10)  # make sure ROI is drawn above image

# Isocurve drawing
iso = pg.IsocurveItem(level=0.8, pen='g')
iso.setParentItem(img)
iso.setZValue(5)

# Contrast/color control
hist = pg.HistogramLUTItem()
hist.setImageItem(img)
win.addItem(hist)

# Draggable line for setting isocurve level
isoLine = pg.InfiniteLine(angle=0, movable=True, pen='g')
hist.vb.addItem(isoLine)
hist.vb.setMouseEnabled(y=False) # makes user interaction a little easier
isoLine.setValue(0.8)
isoLine.setZValue(1000) # bring iso line above contrast controls

# Another plot area for displaying ROI data
win.nextRow()
p2 = win.addPlot(colspan=2)
p2.setMaximumHeight(250)
win.resize(800, 800)
win.show()


# Generate image data
data = np.random.normal(size=(200, 100))
data[20:80, 20:80] += 2.
data = pg.gaussianFilter(data, (3, 3))
data += np.random.normal(size=(200, 100)) * 0.1
img.setImage(data)
hist.setLevels(data.min(), data.max())

# build isocurves from smoothed data
iso.setData(pg.gaussianFilter(data, (2, 2)))

# set position and scale of image
img.scale(0.2, 0.2)
img.translate(-50, 0)

# zoom to fit imageo
p1.autoRange()  


# Callbacks for handling user interaction
def updatePlot():
    global img, roi, data, p2
    selected = roi.getArrayRegion(data, img)
    p2.plot(selected.mean(axis=0), clear=True)

roi.sigRegionChanged.connect(updatePlot)
updatePlot()

def updateIsocurve():
    global isoLine, iso
    iso.setLevel(isoLine.value())

isoLine.sigDragged.connect(updateIsocurve)


## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()

Reply via email to