【问题标题】:How to determine the amount of pixel of an given ROI?如何确定给定 ROI 的像素数量?
【发布时间】:2013-10-09 09:45:49
【问题描述】:

我编写了一个小程序,为我提供有关使用“分析粒子...”找到的 ROI 的某些信息。不幸的是,我需要有关每个 ROI 像素数量的信息。当我在此插件之前不使用“设置比例”时,我可能会通过区域输出获得像素数量。但是为了进一步计算之前的“设置比例”是需要的。使用“分析粒子...”后是否有可能提取每个 ROI 的像素数量。我只在 java 中发现了这种可能性(对于我作为 python 的初学者来说几乎不可读)http://imagej.nih.gov/ij/plugins/download/Calculate_Mean.java 并且它似乎是计算密集型的。提前谢谢你。

import math

row = 0

IJ.run("Set Measurements...", "area centroid perimeter shape feret's area_fraction   redirect=None decimal=6")
IJ.run("Analyze Particles...")
rt = ResultsTable.getResultsTable()

for roi in RoiManager.getInstance().getRoisAsArray():
  a = rt.getValue("Feret", row)
  b = rt.getValue("MinFeret", row)
  nu= 1
  L = 1
  p = 1
  sapf = (math.pi/4) * (1/(nu*L)) * math.pow(a, 3) * math.pow(b, 3) / (math.pow(a, 2) + math.pow(a, 2))*p
  rt.setValue("ROI no.", row, row + 1)
  rt.setValue("Sapflow", row, sapf)
  row = row + 1
rt.show("Results") 

【问题讨论】:

    标签: python jython imagej


    【解决方案1】:

    (一般来说,与 ImageJ 内部结构而非编程语言相关的问题应发送至 ImageJ mailing list。这将确保大多数 ImageJ 专家用户和开发人员都能阅读您的问题,而不仅仅是几个 stackoverflow.com 爱好者。)

    1. 您可以使用calibration 信息来计算该区域的像素数:

      像素数 = 总面积 / 像素面积

    2. 您可以使用ImageStatistics.getStatistics() 方法获取当前ROI 的pixelCount 值。

      添加几行代码后,您的代码如下所示:

      import math
      
      row = 0
      
      IJ.run("Set Measurements...", "area centroid perimeter shape feret's area_fraction   redirect=None decimal=6")
      IJ.run("Analyze Particles...")
      rt = ResultsTable.getResultsTable()
      
      imp = IJ.getImage()
      ip = imp.getProcessor()
      
      for roi in RoiManager.getInstance().getRoisAsArray():
        a = rt.getValue("Feret", row)
        b = rt.getValue("MinFeret", row)
        nu= 1
        L = 1
        p = 1
        sapf = (math.pi/4) * (1/(nu*L)) * math.pow(a, 3) * math.pow(b, 3) / (math.pow(a, 2) + math.pow(a, 2))*p
        rt.setValue("ROI no.", row, row + 1)
        rt.setValue("Sapflow", row, sapf)
      
        ip.setRoi(roi)
        stats = ImageStatistics.getStatistics(ip, Measurements.AREA, None)
        rt.setValue("Pixel count", row, stats.pixelCount)
      
        row = row + 1
      rt.show("Results")
      

    希望对您有所帮助。

    【讨论】:

    • 再次感谢您,对于有关 ImageJ 问题的更多问题,我将使用 ImageJ 邮件列表。
    猜你喜欢
    • 1970-01-01
    • 2012-02-21
    • 1970-01-01
    • 2021-09-14
    • 2015-06-10
    • 1970-01-01
    • 2021-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多