【问题标题】:ImageJ: NameError when using selectionType() in Python scriptImageJ:在 Python 脚本中使用 selectionType() 时出现 NameError
【发布时间】:2016-10-26 00:03:54
【问题描述】:

我是 ImageJ 的新手,正在尝试使用 Python(在 ImageJ 宏编辑器中)重新创建以下宏。

s = selectionType();

if( s == -1 ) {
    exit("There was no selection.");
} else if( s != 10 ) {
    exit("The selection wasn't a point selection.");
} else {
    getSelectionCoordinates(xPoints,yPoints);
    x = xPoints[0];
    y = yPoints[0];
    showMessage("Got coordinates ("+x+","+y+")");
}

问题是,我不知道如何导入 selectionType() 和 getSelectionCoordinates() 内置函数。当我尝试在 Python 代码中使用它们时,我得到了 NameError。

有什么想法吗?

谢谢, 亚历克斯

【问题讨论】:

    标签: python jython imagej imagej-macro


    【解决方案1】:

    不幸的是,ImageJ 1.x 的内置宏函数不是一流的 Java 方法,因此不一定可用于其他脚本语言,例如 Python。

    您可以阅读 Java 源代码以了解宏函数的作用,但在某些情况下需要花费一些精力才能解读。例如,getSelectionCoordinates 函数可以是seen here

    简而言之:它调用ImagePlusgetRoi() 方法,然后根据Roi 的类型,以不同的方式填充坐标。对于Roi.LINE 类型,使用x1dy1dx2dy2d 字段。否则调用RoigetFloatPolygon()方法将ROI转换为多边形类型,然后遍历其坐标。

    对于selectionType 函数,只需在ImagePlus 上调用getRoi()

    【讨论】:

      猜你喜欢
      • 2015-11-21
      • 2022-06-14
      • 2015-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多