Adding axes to ImageView

1,538 views
Skip to first unread message

Victoria Price

unread,
Aug 1, 2012, 8:27:56 AM8/1/12
to pyqt...@googlegroups.com
Is there a way to add axes to an ImageView?  I need the interactive histogram that the ImageView offers, but I also need to be able to perform ROI selection and display axes.  Can an ImageView be embedded into a larger GraphicsScene perhaps? 

Luke Campagnola

unread,
Aug 3, 2012, 12:57:50 AM8/3/12
to pyqt...@googlegroups.com
In the latest revision (182), you can specify a custom view object when creating an ImageView:

    imgView = pg.ImageView(view=pg.PlotItem())

This would put a PlotItem into the ImageView instead of a ViewBox, giving you axes around the image display area. Is this what you had in mind?

Luke

On Wed, Aug 1, 2012 at 8:27 AM, Victoria Price <victoria...@gmail.com> wrote:
Is there a way to add axes to an ImageView?  I need the interactive histogram that the ImageView offers, but I also need to be able to perform ROI selection and display axes.  Can an ImageView be embedded into a larger GraphicsScene perhaps? 

-- [ You are subscribed to pyqt...@googlegroups.com. To unsubscribe, send email to pyqtgraph+...@googlegroups.com ]

Victoria Price

unread,
Aug 3, 2012, 11:56:46 AM8/3/12
to pyqt...@googlegroups.com
This is perfect!  Thank you so very, very much.  

Message has been deleted

Victoria Price

unread,
Aug 8, 2012, 1:26:15 PM8/8/12
to pyqt...@googlegroups.com
One (or two) more questions regarding ROI's...

-How can I adjust the size of the ROI that is inherently present in the ImageView?  

-Can I attach cross-hairs to an ROI?  I'd like to slice and export data from the ROI, but also display real-time x,y coordinates with crosshairs. 

-How do I normalize the image/data, for the purposes of noise cancellation?  Is this possible?

Luke Campagnola

unread,
Aug 8, 2012, 1:36:34 PM8/8/12
to pyqt...@googlegroups.com
Sorry, I don't quite follow. What are you displaying in real-time? Where would you want to place a crosshair relative to that data?

On Wed, Aug 8, 2012 at 11:44 AM, Victoria Price <victoria...@gmail.com> wrote:
One more question-- is there a way to link cross-hairs and ROI's?  I'd like to be able to create an ROI around a target in the image and export that data, but also display it in real-time using crosshairs... 


Victoria Price

unread,
Aug 8, 2012, 1:38:59 PM8/8/12
to pyqt...@googlegroups.com
So my image is a still from a sonar "video" where a target is present.  I'd like to be able to mouse over the target and display the location (similar to the cross-hair example, only I can't seem to get that to work with this), but also save/export that location as data (I noticed that you can export data as a .csv, for example) using (I'm guessing) and ROI.  Does that help?

Luke Campagnola

unread,
Aug 8, 2012, 4:06:11 PM8/8/12
to pyqt...@googlegroups.com
On Wed, Aug 8, 2012 at 1:38 PM, Victoria Price <victoria...@gmail.com> wrote:
So my image is a still from a sonar "video" where a target is present.  I'd like to be able to mouse over the target and display the location (similar to the cross-hair example, only I can't seem to get that to work with this), but also save/export that location as data (I noticed that you can export data as a .csv, for example) using (I'm guessing) and ROI.  Does that help?
 
Crosshairs are very easy to build. I haven't really supplied any standard crosshair objects because it seems like most people want to use them in a very particular way, so they're usually better off writing their own anyway. See the attached example--this creates a very simple, draggable crosshair and adds it to an ImageView. You can get the position of the crosshair with c.pos(). I recommend reading the Qt docs on QGraphicsItem to see what the paint and boundingRect methods are doing. The dragEvent method is specific to pyqtgraph and documented here: http://luke.campagnola.me/code/pyqtgraph/documentation/graphicsscene/index.html

You could do a variety of other things with this--display text that updates whenever the crosshair moves, store the position to a file, etc. Exporting data is mostly up to you--pyqtgraph provides methods for exporting rendered graphics to image and such, but for exporting data you'll most likely want to write the code yourself. The exception you noted is that plots can be stored as CSV, but I don't think this will be much use to you..

Luke



crosshair.py

Luke Campagnola

unread,
Aug 8, 2012, 4:21:05 PM8/8/12
to pyqt...@googlegroups.com
On Wed, Aug 8, 2012 at 1:26 PM, Victoria Price <victoria...@gmail.com> wrote:
-How can I adjust the size of the ROI that is inherently present in the ImageView?  

You can drag the diamond-shaped handle on the ROI to resize it, or you can do it programatically:

The ROI can be accessed as imageView.roi
 
-Can I attach cross-hairs to an ROI?  I'd like to slice and export data from the ROI, but also display real-time x,y coordinates with crosshairs. 

If you create the Crosshair object from my previous response, you could just add this as a child of the ROI (setParentItem in QGraphicsItem docs). In that case, you would want to get position information from the ROI rather than the crosshair, since the latter position would be reported relative to the ROI and thus not very useful to you.
 
-How do I normalize the image/data, for the purposes of noise cancellation?  Is this possible?

That's a very broad question--there is no one way to do image normalization; this will depend entirely on the type of signal you have and the type of noise you are trying to remove. Numpy and scipy both have many tools that could be helpful to you (see in particular scipy.ndimage). ImageView does have some very basic normalization capabilities built in, but these are mostly intended for use with video (and to be honest, they're really just designed for the kind of data I work with).

Luke

Victoria Price

unread,
Aug 8, 2012, 4:22:42 PM8/8/12
to pyqt...@googlegroups.com
Thank you so much for putting up with my incessant questions, I really appreciate it.  


Reply all
Reply to author
Forward
0 new messages