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

发布于 2025-02-12 07:14:53 字数 574 浏览 4 评论 0 原文

例如,在下面所示的图像中,左侧是(位蒙版)图像,我想创建一个封闭的ROI,其顶点连接虚拟光圈的轮廓,该轮廓在右侧(用手绘制,形状并不精确)。当然,ROI可以在现有图像或新图像上。

这在使用脚本的虚拟光圈到4D-STEM数据集的应用程序中有关需要将一个掩盖的图像(例如虚拟光圈,只有零和一个)转换为ROI,然后应用Si-Map功能,以加快计算和自动化(我在这里之前提出的另一个问题一个>,在这里得到部分答案)。

我想知道如何使用脚本进行操作?任何提示都对此表示赞赏!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一念一轮回 2025-02-19 07:14:53

没有将任意掩码转换为ROI的命令或简单方法。

这部分是如此,因为ROI定义为一组顶点。

为了进行转换,首先必须从二进制掩码中创建“大纲”掩码,然后获取所有轮廓点的XY坐标,然后具有算法来对这些点进行分类,以便它们形成A(闭环。
然后,可以创建ROI并将点添加为顶点。都是可行的,但不平凡。

但是我想知道为什么要竭尽全力?

如果主要用例是使用ROI限制SI中的某些数据,则必须将ROI转换回一个或另一个点的二进制掩码。那么,为什么不首先使用口罩呢?

如果这只是掩码可视化的问题,那么我建议使用用于任务的注释:覆盖注释。

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)

编辑:GMS的较旧版本不支持这种类型的注释。在这种情况下,可以创建一个RGB混合图像以显示。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文