Вопрос

I wrote a small program to give me certain information about ROIs I found by using "Analyze Particles...". Unfortunatly I need information about the amount of pixel per ROI. When I am not using "Set Scale" prior to this plugin I will maybe get the amount of pixels by the area output. But for further calculating prior "Set Scale" is needed. Is there a possibility to extract the amount of pixels per ROI after using "Analyze Particles...". I only found this possibility in java (nearly not readable for me as a beginner in python) http://imagej.nih.gov/ij/plugins/download/Calculate_Mean.java and its seems to be very computationally intensive. Thanking you in advance.

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") 
Это было полезно?

Решение

(In general, questions that are more related to ImageJ internals rather than programming languages should be addressed to the ImageJ mailing list. This will make sure your question will be read by most expert users and developers of ImageJ, not only by a couple of stackoverflow.com enthusiasts.)

  1. You can use the calibration information to calculate back the pixel count from the area:

    Pixel count = Total Area / Pixel area

  2. You can use the ImageStatistics.getStatistics() method to get its pixelCount value for the current ROI.

    Here's how your code looks after the addition of a few lines:

    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")
    

Hope that helps.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top