简体   繁体   English

如何使用脚本将(位掩码)图像转换为图像中的 ROI

[英]How to convert a (bit masked) image to ROI in the image with script

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).例如在下面显示的图像中,左侧是(位掩码)图像,我想创建一个封闭的 ROI,其顶点连接虚拟光圈的轮廓,如右侧所示(手工绘制,形状不精确)。 Of course the ROI can be on the existing image or on a new image.当然,ROI 可以在现有图像上或新图像上。 在此处输入图像描述

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).这与使用脚本将虚拟孔径应用于 4D-STEM 数据集的应用程序相关,我需要将位掩码图像(如虚拟孔径,只有零和一)转换为 ROI,然后应用 SI-Map function 所以加快计算和自动化( 我前段时间在这里提出的另一个问题,以及这里的部分答案)。

I'm wondering how to do this with a script?我想知道如何用脚本来做到这一点? Any hints are appreciated任何提示表示赞赏

There is no command or simple way to convert an arbitrary mask into a ROI.没有命令或简单的方法可以将任意掩码转换为 ROI。

This is partly so, because a ROI is defined as a set of vertices.部分是这样,因为 ROI 被定义为一组顶点。

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.为了进行转换,首先必须从二进制掩码创建“轮廓”掩码,然后获取所有轮廓点的 XY 坐标,然后使用算法对这些点进行排序,使它们形成 (闭环。 Then, one could create a ROI and add the points as vertices.然后,可以创建一个 ROI 并将这些点添加为顶点。 All doable, but non-trivial.都是可行的,但并非微不足道。

But I'm wondering why one would even go to that length?但我想知道为什么有人甚至会 go 到那个长度?

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.如果主要用例是使用 ROI 来限制 SI 中的某些数据,则必须在一个或另一个点将 ROI 转换回二进制掩码。 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.如果这只是蒙版可视化的问题,那么我建议使用适用于该任务的注释:叠加注释。 在此处输入图像描述

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.编辑:旧版本的 GMS 不支持这种类型的注释。 In this case, one could instead create a RGB mix image for display.在这种情况下,可以改为创建用于显示的 RGB 混合图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM