interactively selecting an ROI (to e.g.: crop a frame)

582 views
Skip to first unread message

Virginia Rutten

unread,
Sep 11, 2018, 11:31:53 AM9/11/18
to Bonsai Users
Hi Bonsai Team,

Question: Could you tell me how I can interactively select an ROI in one frame and use the 'Rect' as an input to crop this frame?

or how I to access cursor values on an image (the one which appears at the bottom when I right click on it)?
I was hoping to use this to be able to select an ROI interactively to e.g.: crop the image.

So far I have something like this: I outsource the properties of crop and I was thinking that I could have a “keydown” condition, and upon this I would select a bounding box (or at worse an x,y cursor position to determine the origin of the box) and use this to set the `Rect` which is needed to crop.

Thanks for any help!

V
Capture.PNG

Gonçalo Lopes

unread,
Sep 11, 2018, 11:50:23 AM9/11/18
to Virginia Rutten, Bonsai Users
Hi Virginia,

In the next version of Bonsai this will be much easier. If you want to give it a try, feel free to download the 2.4-preview version. Using the new context menu "Create Property Source" you can automatically construct a data source that is based on the specified property of interest. This source will keep the visual editor but will also allow you to directly access the values modified in the editor as data in the workflow.

For the current version, the workaround for this limitation is to use the RoiActivity node. The output of this node happens to give you the bounding box of defined regions, which you can use as an input to Crop. Another option is to define a mask using MaskPolygon and then segment it interactively using FindContours, etc, and then use the Rect property to extract the bounding box, but this might be too creative for what you are after.

Hope this helps, and let me know if you would like me to elaborate on any of these options.

--
You received this message because you are subscribed to the Google Groups "Bonsai Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/bonsai-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/bonsai-users/3e545fb1-b973-4474-8984-ad4bbd970315%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Virginia Rutten

unread,
Sep 11, 2018, 1:46:01 PM9/11/18
to Bonsai Users
Hi,

Thanks for the rapid response.
I hadn't realised that by clicking on the right panel, where ROI-activity is, it allows you to select easily select an ROI (this was the first part I was missing).
I have the following pipeline (posted below):
But I get a run-time error: 
"Operation could destabilise the runtime"

I think this is because if there can be any number of ROI selected, and I am not indicating to the program which one to select(?).
I can't seem to be able to get hold of the individual Rects using RoiActivity output.

Thanks for any pointers - so close to get this part working :)


On Tuesday, September 11, 2018 at 11:50:23 AM UTC-4, goncaloclopes wrote:
Hi Virginia,

In the next version of Bonsai this will be much easier. If you want to give it a try, feel free to download the 2.4-preview version. Using the new context menu "Create Property Source" you can automatically construct a data source that is based on the specified property of interest. This source will keep the visual editor but will also allow you to directly access the values modified in the editor as data in the workflow.

For the current version, the workaround for this limitation is to use the RoiActivity node. The output of this node happens to give you the bounding box of defined regions, which you can use as an input to Crop. Another option is to define a mask using MaskPolygon and then segment it interactively using FindContours, etc, and then use the Rect property to extract the bounding box, but this might be too creative for what you are after.

Hope this helps, and let me know if you would like me to elaborate on any of these options.
On 11 September 2018 at 16:31, Virginia Rutten <gin.r...@gmail.com> wrote:
Hi Bonsai Team,

Question: Could you tell me how I can interactively select an ROI in one frame and use the 'Rect' as an input to crop this frame?

or how I to access cursor values on an image (the one which appears at the bottom when I right click on it)?
I was hoping to use this to be able to select an ROI interactively to e.g.: crop the image.

So far I have something like this: I outsource the properties of crop and I was thinking that I could have a “keydown” condition, and upon this I would select a bounding box (or at worse an x,y cursor position to determine the origin of the box) and use this to set the `Rect` which is needed to crop.

Thanks for any help!

V

--
You received this message because you are subscribed to the Google Groups "Bonsai Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users...@googlegroups.com.
Capture.PNG

Gonçalo Lopes

unread,
Sep 11, 2018, 6:06:15 PM9/11/18
to Virginia Rutten, Bonsai Users
Yeah, there is a bit of a trick to accessing them. After you select the Item property, you need to add an index to indicate which ROI you want to pick, something like: Item[0]. You need to type in the square brackets and the index by hand on top of the Selector property (after you have picked up the node).

This will all be much easier in the next version (including picking up elements in arrays).

To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users+unsubscribe@googlegroups.com.

Virginia Rutten

unread,
Sep 13, 2018, 11:32:18 AM9/13/18
to Bonsai Users
Fantastic! It works!
Thanks for the help

Aditya Asopa

unread,
Jul 12, 2019, 4:53:59 AM7/12/19
to Bonsai Users
Hi Goncalo,

Hope you are well. I am in a similar situation. I wanted data from multiple RoIs. I tried creating index using Index node but it showing me an error. I am posting an example code here:

I have two questions:
1. How do i create circular RoIs?
2. How should the index node be used with RoI activity?

Many thanks for your time

Aditya


On Wednesday, September 12, 2018 at 3:36:15 AM UTC+5:30, goncaloclopes wrote:
Yeah, there is a bit of a trick to accessing them. After you select the Item property, you need to add an index to indicate which ROI you want to pick, something like: Item[0]. You need to type in the square brackets and the index by hand on top of the Selector property (after you have picked up the node).

This will all be much easier in the next version (including picking up elements in arrays).
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai...@googlegroups.com.
multiple_roi_values.bonsai

Gonçalo Lopes

unread,
Aug 9, 2019, 5:14:03 AM8/9/19
to Aditya Asopa, Bonsai Users
Ah, yes, this is one of the most beloved error messages of all time in Bonsai :) especially when localized to languages other than english where they have translated "runtime" as "execution time", the result can only be catastrophically hilarious (by the way, this is an official C# error message).

Anyway, the reason for this is here:

Basically you have to insert the index in brackets to get specific values, like so: Source.Value.Item[0].Activity.Val0 (note the bracket with the index in bold).

In the next release, the Index operator will get rid of this issue.

Reply all
Reply to author
Forward
0 new messages