Hi guys:

Thank you so much for your helpful discussion! I'm also a new guy to 
pyqtgraph and trying to find a way to get binary ROI, but when I ran the 
attached testROI.py, an error occurs:
'''
Traceback (most recent call last):
  File "testROI.py", line 37, in <module>
    mpossx = roi.getArrayRegion(possx,imgview).astype(int)
  File 
"D:\Program\Miniconda3\envs\bs\lib\site-packages\pyqtgraph\graphicsItems\ROI.py",
 
line 2027, in getArrayRegion
    sliced = ROI.getArrayRegion(self, data, img, axes=axes, 
fromBoundingRect=True, **kwds)
  File 
"D:\Program\Miniconda3\envs\bs\lib\site-packages\pyqtgraph\graphicsItems\ROI.py",
 
line 1104, in getArrayRegion
    shape, vectors, origin = self.getAffineSliceParams(data, img, axes, 
fromBoundingRect=fromBR)
  File 
"D:\Program\Miniconda3\envs\bs\lib\site-packages\pyqtgraph\graphicsItems\ROI.py",
 
line 1129, in getAffineSliceParams
    raise Exception("ROI and target item must be members of the same 
scene.")
Exception: ROI and target item must be members of the same scene.
'''
I guess it is because the function 'ROI.getArrayRegion' has been 
changed/updated over the years. But as a newbie, I don't quite understand 
how to fix it ... Could you please give me some suggestions? Thank you very 
much!!

Best,
Xingyu 

在 2015年5月18日星期一 UTC+8下午11:50:20,Julien Lhermitte写道:
>
> Great I'm glad to hear this! Thanks for the information by the way, I 
> didn't know you could do this but it's a great feature to have (add a 
> function to a class after the fact just like you can do with attributes).
>
> I'm not sure which way is more pythonic but I would still rather create a 
> new class with this new method that inherits all methods members of the ROI 
> class used in the long run. This might make things easier to keep track of. 
> If you're not familiar, look up inheritance (like here 
> <http://www.jesshamrick.com/2011/05/18/an-introduction-to-classes-and-inheritance-in-python/>),
>  
> it's pretty simple to implement. But this is a nice quick fix.
>
> On Monday, May 18, 2015 at 3:32:31 AM UTC-4, L. Smash wrote:
>>
>> Hi,
>>
>> thanks for the nice example! I think I've got it now :)
>>
>> What I actually was trying to do is to put your code into a 
>> function/method (like getArrayRegion) and dynamically add it to ROI classes 
>> of pyqtgraph (PolyLineROI, Ellipse.ROI etc.). The problem I stumbled across 
>> was an issue with bound\unbound methods (see here 
>> <http://www.ianlewis.org/en/dynamically-adding-method-classes-or-class-instanc>),
>>  
>> that's why I got confused with the self variable. Thanks again for your 
>> explanation and the example, it helped me very much!
>>
>> Best, 
>> Lars
>>
>> Am Freitag, 15. Mai 2015 16:45:27 UTC+2 schrieb Julien Lhermitte:
>>>
>>> oops the dimensions were wrong (ROI went out of bounds of data array), I 
>>> have reattached the correct example.
>>>
>>> Also, the *self* variable in my previous example would be the 
>>> *theObjectCallingIt* in my current example. It can have whatever name 
>>> you want.
>>>
>>> (doing this on my spare time here and there :-( but hope it helps)
>>>
>>>
>>> On Friday, May 15, 2015 at 9:40:12 AM UTC-4, Julien Lhermitte wrote:
>>>>
>>>> Hi,
>>>>
>>>>      I am not completely sure I understand your question but I think 
>>>> your concern is the self variable. Yes, this was just a quick snippet I 
>>>> copied and pasted.
>>>> First, I believe whenever you call a function in an object, the first 
>>>> parameter given is always a reference to the object itself.
>>>>
>>>> So if tiger is part of class Cat, and has member function getColor(), 
>>>> this function:
>>>> tiger.getColor() is actually a shortcut for Cat.getColor(tiger), so 
>>>> when declaring a function in a class, the function should be declared as:
>>>>
>>>> def getColor(theObjectCallingIt, otherparameters...):
>>>>
>>>> But let's ignore that for now and just create some self contained code. 
>>>> I have attached it in this message. It generates random data but it's 
>>>> always a good idea to use some sort of image with features to test (just 
>>>> uncomment the relevant lines for that and install PIL image lib for 
>>>> example)
>>>>
>>>> I hope this helps!
>>>>
>>>> julien
>>>>
>>>>

-- 
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/1af967f8-98d0-459a-ad7c-482a8ced88cb%40googlegroups.com.

Reply via email to