1

For example in the image shown below, the left side is the (bit masked) image, and I want to create a closed ROI with their vertex connecting the contour of the virtual aperture, shown on the right side (which is drawn by hand, not precise to the shape). Of course the ROI can be on the existing image or on a new image. enter image description here

This is related in an application to virtual aperture to 4D-STEM datasets using scripts, I need to convert a bit masked image (like a virtual aperture, having only zeros and ones) to an ROI, and then apply the SI-Map function so to speed up the calculation and automation (the other question I raised here some time ago, and a partial answer here).

I'm wondering how to do this with a script? Any hints are appreciated!

BmyGuest
  • 6,331
  • 1
  • 21
  • 35
w4m
  • 301
  • 1
  • 10

1 Answers1

1

There is no command or simple way to convert an arbitrary mask into a ROI.

This is partly so, because a ROI is defined as a set of vertices.

In order to do the conversion, one would first have to create the "outline" mask from the binary mask, then get the XY coordinates of all of the outline points, and then have an algorithm to sort these points so that they form a (closed) loop. Then, one could create a ROI and add the points as vertices. All doable, but non-trivial.

But I'm wondering why one would even go to that length?

If the primary use-case is to use the ROI to limit some data in the SI, then one will have to convert the ROI back into a binary mask at one or another point. So why not just use the mask in the first place?

If it is just a question of visualization of the mask, then I would recommend using the annotation that is meant for the task: the overlay annotation. enter image description here

image front := GetFrontImage().ImageClone()
number sx, sy
front.ImageGetDimensionSizes(sx,sy)
image mask = front > mean(front) ? 1 : 0
front.ShowImage()
mask.Showimage()
component maskComp = NewOverlayAnnotation(0,0,sy,sx)
maskComp.ComponentSetForegroundColor(0,0,1)
maskComp.ComponentSetMask(mask)
maskComp.ComponentSetTransparency(0.5)
front.ImageGetImageDisplay(0).ComponentAddChildAtEnd(maskComp)

Edit: Older versions of GMS do not support this type of annotation. In this case, one could instead create a RGB mix image for display.

BmyGuest
  • 6,331
  • 1
  • 21
  • 35