Pick data on table

I have the code of fraction area but I don’t know how can have the value of %area and area to do
Print("A=",area)
Print("B="%area) ???

Thank you

macro "Measure Percent Area [F9]" {
      getThreshold(lower, upper);
      if (lower!=-1)
          measureThresholdedImage(lower, upper);
       else {
           ok = measureBinaryImage();
           if (!ok)
               showMessage("Thresholded image or 8-bit binary image required");
       }      
  }


  function measureThresholdedImage(lower, upper) {
      if (bitDepth==32)
          exit("This macro does not work with 32-bit images");
      getRawStatistics(n, mean, min, max, std, histogram);
      sum = 0;
      total = 0;
      //print(min, max, lengthOf(histogram));
      for (i=min; i<=max; i++) {
          if (i>=lower && i<=upper)
              sum += histogram[i];
          total += histogram[i];
      }
      percent = sum*100/total;
      run("Measure");
      setResult("%Area", nResults-1, percent);
      updateResults();
  }

 function measureBinaryImage() {
      if (bitDepth!=8) return false;
      getStatistics(n, mean, min, max, std, histogram);
      if (n != histogram[0]+histogram[255])
          return false;
      percent = histogram[255]*100/n;
      run("Measure");
      setResult("%Area", nResults-1, percent);
      updateResults();
      return true;
  }

Hello Tom,

Welcome to the forum.

If I understand your question correctly, you could try adding the following lines to your macro functions:

print("A=" + getResult("Area"));
print("B=" + getResult("%Area"));

Best wishes,

Cam

1 Like

Thank you. Its works well for (%area) but if I change the scale It doesn t work for (area). That’s why I use getstatistics(area) to obtain the parameter.

Thank you for you help

1 Like