image analysis app

278 views
Skip to first unread message

Jim Passmore

unread,
Jan 11, 2014, 1:31:42 PM1/11/14
to pyqt...@googlegroups.com
Luke et al,
I'm new to pygtgraph (and GUIs in general) so you may get a few questions from me.  ;-)  So far, I've had far better success with pyqtgraph than guiqwt at getting a simple image loaded and displayed in a window, so I'm trying this path first.

I'm putting together an image analysis program, and will want to take profiles across line selections (among other things), so I'm looking through the example scripts to find related code.  One of the first items I'm looking at is the Data Slicing example.  It won't be exactly the same, but certainly related.  When I run the example, I get a window with 2 images (imv1 and imv2), and the top has a line segment ROI already marked.  As I understand it, the bottom image should change when I move the line segment ROI.  However, that doesn't happen.  Am I missing something?

Other questions:
One of my early goals is to have a 2D image displayed, be able to click on the image, have vertical and horizontal line ROIs created (intersecting at the click point), and have 2 1D profiles drawn--one on the right (in place of the histogram) that shows the profile of the vertical ROI, and one at the bottom showing the profile of the horizontal ROI.
  • Doable, I assume?
  • Should I do this by subclassing the ViewBox, or will the histogram get in the way?
  • Better to start from scratch, using the ViewBox as a pattern?
  • Or maybe go higher level with an ImageView?
  • Any other hints?

Another aspect will be to have 2 images in the same location, and use toolbar buttons to toggle visibility between the two.  How best should I do this? 
  • Two ViewBox-type objects?
  • or one ViewBox with 2 GraphicsItems?
  • or again, is it better to subclass/use an ImageView?
Don't feel like you need to do it all for me, as struggling through the details will help me learn the API.  Thanks for getting me started!

Jim

Luke Campagnola

unread,
Jan 11, 2014, 6:28:22 PM1/11/14
to pyqt...@googlegroups.com
On Sat, Jan 11, 2014 at 1:31 PM, Jim Passmore <j...@passmore4.com> wrote:
I'm putting together an image analysis program, and will want to take profiles across line selections (among other things), so I'm looking through the example scripts to find related code.  One of the first items I'm looking at is the Data Slicing example.  It won't be exactly the same, but certainly related.  When I run the example, I get a window with 2 images (imv1 and imv2), and the top has a line segment ROI already marked.  As I understand it, the bottom image should change when I move the line segment ROI.  However, that doesn't happen.  Am I missing something?

You are correct--the bottom image should immediately update when the ROI is moved (it works as expected on my machine). Can you tell me what pyqtgraph version and OS you are using? How are you running the example? Do you see any error messages printed on the console?
 
Other questions:
One of my early goals is to have a 2D image displayed, be able to click on the image, have vertical and horizontal line ROIs created (intersecting at the click point), and have 2 1D profiles drawn--one on the right (in place of the histogram) that shows the profile of the vertical ROI, and one at the bottom showing the profile of the horizontal ROI.
  • Doable, I assume?
  • Should I do this by subclassing the ViewBox, or will the histogram get in the way?
  • Better to start from scratch, using the ViewBox as a pattern?
  • Or maybe go higher level with an ImageView?
  • Any other hints?
There are many different ways you could do this. I would avoid ImageView--it would probably be a lot of effort to modify it to fit your needs. All you really need to display an image is a ViewBox with an ImageItem inside. It sounds like you also want two PlotItems to display the cross-sections, so I recommend the following strategy:

1. Use GraphicsLayoutWidget to organize your GraphicsItems in a grid
2. Add a ViewBox and two PlotItems in the proper locations.
3. Link the ViewBox axes to the plot axes like `xPlot.setXLink(view); yPlot.setYLink(view)` to ensure the plots and image are aligned
4. Add an ImageItem and two orthogonal InfiniteLines to the ViewBox
5. Detect mouse clicks to set the line locations either by connecting to GraphicsScene.sigMouseClicked or by overriding ImageItem.mouseClickEvent.
6. Connect to InfiniteLine.sigPositionChanged or .sigPositionChangeFinished and update the cross-section plots accordingly.

For the situation you have described, I do not recommend using the ROI subclasses since you won't be using most of the features they provide, and InfiniteLine is easier to use.

Another aspect will be to have 2 images in the same location, and use toolbar buttons to toggle visibility between the two.  How best should I do this? 
  • Two ViewBox-type objects?
  • or one ViewBox with 2 GraphicsItems?
  • or again, is it better to subclass/use an ImageView?
I would just use two ImageItems inside the ViewBox and call ImageItem.setZValue  or .setVisible to switch between them. The purpose of ViewBox is to take care of zoom/panning, and I suspect it doesn't make much sense for your images to be displayed with different zoom/pan.
 

Luke

Jim Passmore

unread,
Jan 11, 2014, 11:50:05 PM1/11/14
to pyqt...@googlegroups.com


On Saturday, January 11, 2014 6:28:22 PM UTC-5, Luke Campagnola wrote:
On Sat, Jan 11, 2014 at 1:31 PM, Jim Passmore <j...@passmore4.com> wrote:
I'm putting together an image analysis program, and will want to take profiles across line selections (among other things), so I'm looking through the example scripts to find related code.  One of the first items I'm looking at is the Data Slicing example.  It won't be exactly the same, but certainly related.  When I run the example, I get a window with 2 images (imv1 and imv2), and the top has a line segment ROI already marked.  As I understand it, the bottom image should change when I move the line segment ROI.  However, that doesn't happen.  Am I missing something?

You are correct--the bottom image should immediately update when the ROI is moved (it works as expected on my machine). Can you tell me what pyqtgraph version and OS you are using? How are you running the example? Do you see any error messages printed on the console?

I'm using Python 3.3.3, so as suggested by a post on this list back a few months ago, I downloaded the latest code from github for Py3 compatibility.  Went back to look, and I see that I downloaded just a few days before commit 95dd56bdb6 on Jan 1.  The ImageView.setImage bug was the problem, and I now see the proper update.   Happy!
 
 
Other questions:

Thanks for the suggestions.  Lots of work ahead!

Jim

Reply all
Reply to author
Forward
0 new messages