Help understanding issue with ROI for an RGBA ImageView

167 views
Skip to first unread message

Lavinia B

unread,
May 19, 2020, 11:17:46 AM5/19/20
to pyqtgraph
Hi,
I have an ImageView in which I set data with mode=rgba. When I try to use the ROI , the plot  gives me warnings if the ROI is not perfectly square. 
"..\src\pyqtgraph\pyqtgraph\graphicsItems\PlotCurveItem.py", line 385, in updateData
    raise Exception("X and Y arrays must be the same shape--got %s and %s." % (self.xData.shape, self.yData.shape))

I don't understand why is this enforced. Can somebody explain?

Note: this does not happen for mono images, or if I keep my selection shape square. 


megan kratz

unread,
May 19, 2020, 11:26:24 AM5/19/20
to pyqt...@googlegroups.com
Hi,

That is an error that occurs when you attempt to plot data that has a different number of x and y values. I need more information in order to understand why you're getting that error though. What are the shapes in the error? Can you post the whole traceback?

Megan

--
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 pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/03453f45-80b6-4e4c-8589-0ca26e131205%40googlegroups.com.

Lavinia B

unread,
May 19, 2020, 11:38:03 AM5/19/20
to pyqtgraph
Also, I only have this issue when I am using this with row-major. :| Maybe I keep getting that wrong, although my image looks like it was intended. 

Lavinia B

unread,
May 19, 2020, 11:43:14 AM5/19/20
to pyqtgraph
Hi,
The numbers correspond to the dimensions of the ROI rectangle I drag. I am pretty sure it's that, as the exception modifies with my changes... and goes away when I create a perfect square. 
For example: 
          Exception: X and Y arrays must be the same shape--got (38,) and (22,).


On Tuesday, May 19, 2020 at 5:26:24 PM UTC+2, megan wrote:
Hi,

That is an error that occurs when you attempt to plot data that has a different number of x and y values. I need more information in order to understand why you're getting that error though. What are the shapes in the error? Can you post the whole traceback?

Megan

On Tue, May 19, 2020 at 9:17 AM Lavinia B <azpa...@gmail.com> wrote:
Hi,
I have an ImageView in which I set data with mode=rgba. When I try to use the ROI , the plot  gives me warnings if the ROI is not perfectly square. 
"..\src\pyqtgraph\pyqtgraph\graphicsItems\PlotCurveItem.py", line 385, in updateData
    raise Exception("X and Y arrays must be the same shape--got %s and %s." % (self.xData.shape, self.yData.shape))

I don't understand why is this enforced. Can somebody explain?

Note: this does not happen for mono images, or if I keep my selection shape square. 


--
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 pyqt...@googlegroups.com.

megan kratz

unread,
May 19, 2020, 11:57:41 AM5/19/20
to pyqt...@googlegroups.com
Okay, I've not been able to replicate this. Can you post some example code that produces this error?

On Tue, May 19, 2020 at 9:43 AM Lavinia B <azpa...@gmail.com> wrote:
Hi,
The numbers correspond to the dimensions of the ROI rectangle I drag. I am pretty sure it's that, as the exception modifies with my changes... and goes away when I create a perfect square. 
For example: 
          Exception: X and Y arrays must be the same shape--got (38,) and (22,).


On Tuesday, May 19, 2020 at 5:26:24 PM UTC+2, megan wrote:
Hi,

That is an error that occurs when you attempt to plot data that has a different number of x and y values. I need more information in order to understand why you're getting that error though. What are the shapes in the error? Can you post the whole traceback?

Megan

On Tue, May 19, 2020 at 9:17 AM Lavinia B <azpa...@gmail.com> wrote:
Hi,
I have an ImageView in which I set data with mode=rgba. When I try to use the ROI , the plot  gives me warnings if the ROI is not perfectly square. 
"..\src\pyqtgraph\pyqtgraph\graphicsItems\PlotCurveItem.py", line 385, in updateData
    raise Exception("X and Y arrays must be the same shape--got %s and %s." % (self.xData.shape, self.yData.shape))

I don't understand why is this enforced. Can somebody explain?

Note: this does not happen for mono images, or if I keep my selection shape square. 


--
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 pyqt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/03453f45-80b6-4e4c-8589-0ca26e131205%40googlegroups.com.

--
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 pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/5c8c6bbd-3989-42d6-91e6-fa7dc729d527%40googlegroups.com.

Lavinia B

unread,
May 19, 2020, 1:16:45 PM5/19/20
to pyqtgraph
Hi, 
I managed to make an example of my issue .  For some reason I cannot get the range to adjust for each color, but I put a border around the image, to make it clear where it ends. 
I fill in  arrays representing rgba, and I stack that to form my data.

If you set the configuration to row major, rescale the roi to an uneven rectangle, then you should get my issue. You can also see in the pictures, because of the error the plots stop updating. 

I expected it to work the same as in column major. ( you can move around the roi, and when the roi overlaps an area outside the image, the plot data corresponding to it is 0)
Any thoughts?  

column major ok.png
rowmajor-roi.png
rgbView_for_question.py

megan kratz

unread,
May 19, 2020, 3:47:22 PM5/19/20
to pyqt...@googlegroups.com
Hi,

Thanks for the example! This is definitely a bug. In addition to the error you're getting about the axes being the wrong shape, there also seems to be a problem with the wrong data being pulled from the image when imageAxisOrder='row-major'. 

For now I'd recommend not using the 'row-major' option if that's at all possible. I'll try to look into it more and figure out a fix. 

Megan


To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/22b1cce2-a9da-45e2-849d-bd4271a240a3%40googlegroups.com.

megan kratz

unread,
May 19, 2020, 5:48:47 PM5/19/20
to pyqt...@googlegroups.com
Hi Lavinia,

I think I made a fix and am submitting a pull request to the official pyqtgraph repository. If you want the fix sooner, you can get it from my github:


The branch with the bugfix is called "imageAxisOrder_bugfix".

Megan

Lavinia B

unread,
May 20, 2020, 6:59:23 PM5/20/20
to pyqtgraph
Thank you! I used your fix and it worked ;) 

Lavinia B

unread,
Jun 4, 2020, 3:49:34 AM6/4/20
to pyqtgraph
Hi Megan, 
Sorry to revive this but I found some issues. While the fix works for the example case, in my application I am switching the imageview type within the same widget, by switching data passed. The current fix breaks the "timeline" version. So axes must be specified as a parameter. 
here is my current take: 

axes = (self.axes['x'], self.axes['y'])
is_row_major = pg.getConfigOption('imageAxisOrder') == 'row-major'
data = None
coords = None
if (is_row_major):
data, coords = self.roi.getArrayRegion(image.view(np.ndarray), self.imageItem,
(self.axes['y'], self.axes['x']), returnMappedCoords=True)
else:
data, coords = self.roi.getArrayRegion(image.view(np.ndarray), self.imageItem, axes,
returnMappedCoords=True)


Also the region of interest had a bug-  was sampling wrong for the row-major data ( it was sampling from a column major version of the data)- so my plots were wrong. In the comments of the getArrayRegion() it is mentioned axes have to be passed swapped, so that's what i did and it seems fine now. 
Not sure if i should have commented this on your pull request :D But i hope you see it!


On Tuesday, May 19, 2020 at 11:48:47 PM UTC+2, megan wrote:

Kenneth Lyons

unread,
Jul 5, 2020, 3:16:27 AM7/5/20
to pyqtgraph
Lavinia, I implemented your suggestion here: https://github.com/pyqtgraph/pyqtgraph/pull/1291

If you get a chance, could you see if that does what you expect and comment over there if you see any issues?
Reply all
Reply to author
Forward
0 new messages