Cropping an arbitrary shaped ROI in Bonsai

920 views
Skip to first unread message

Sachin

unread,
Mar 3, 2015, 5:45:19 PM3/3/15
to bonsai...@googlegroups.com
Hi,
Can anyone tell me how to crop an arbitrary shaped ROI instead of the rectangular shape.

Thanks!

goncaloclopes

unread,
Mar 3, 2015, 6:26:22 PM3/3/15
to bonsai...@googlegroups.com
Hi Sachin,

There are essentially two ways to "crop" a non-rectangular shape:

1) Using just standard nodes, a non-rectangular crop can be seen as a combination of a normal Crop with a Mask that sets all non-shape pixels to zero. The mask you can draw in a paint program and load into Bonsai, but this is a bit tedious... however, you have the advantage that you can do whatever you want with the masked image afterwards.

2) You can use the RoiActivity node, which sums all the pixels inside a set of ROIs (which can be non-rectangular). RoiActivity has a property grid editor that allows you to visually edit these ROIs. Some hints for using the editor:
  * create ROIs by drawing a rectangle (like normal crop)
  * you can translate the ROI by dragging the inside of the rectangle
  * you can move the control points by holding the right mouse button (which allows you to do the non-rectangular)
  * create new control points by double-clicking with the left mouse button on a line inside the ROI
  * erase control points by double-clicking with the right mouse button on a control point inside the ROI
  * you can erase an entire ROI by pressing Delete
  * you can cycle through ROIs with Tab (useful when by mistake you draw ROIs so small that you cannot select them visually)

Although RoiActivity has a nice editor, it suffers from the fact that it only does one thing: sum the value of all the pixels inside the region of interest. This is usually what is needed most of the time, but occasionally we just want to be able to draw a non-rectangular mask in order to do other things.

Another thing that may be confusing: RoiActivity returns a list of ROIs, with as many ROIs as you have created in the editor. If you want to select a specific ROI (in order to save data to a file) you can use MemberSelector with the following Selector expression: Source.Item[0].Activity.Val0

This will probably be made easier in the next version of Bonsai (coming soon) but for now, these are the options.

Cheers,
Gonçalo
Reply all
Reply to author
Forward
0 new messages