ImageDev

CustomMeasurement

This class allows the creation of a new label analysis measurement, based on a user-defined formula.

A custom measurement is defined by a string formula that can invoke other measurements. It can be used by most of the individual analysis algorithms. It must have a unique name.

The formula defining a custom measurement must be written in accordance with the custom formula syntax. The validity of the formula can be verified with the checkMeasurementFormula method.

Notes
See also

AnalysisMsr::Ptr analysis = std::make_shared< AnalysisMsr >();
// Create a circularity factor between 0 and 1
std::string circularityFormula = "1.0/" + NativeMeasurements::inverseCircularity2d->name();
if ( checkMeasurementFormula( circularityFormula ) )
{
    const auto* customMeasurementInfo =
        AnalysisMsr::registerCustomMeasurement( "Circularity", circularityFormula, "This is my circularity factor." );
    auto circularity = analysis->select( customMeasurementInfo );
}
else
    std::cerr << "Invalid formula: " << circularityFormula << std::endl;
      
analysis = imagedev.AnalysisMsr()
# Create a circularity factor between 0 and 1
circularity_formula = "1.0/"+imagedev.native_measurements.InverseCircularity2d.name
if (imagedev.check_measurement_formula(circularity_formula)):
  custom_msr_info = imagedev.AnalysisMsr.register_custom_measurement("Circularity", circularity_formula, "This is my circularity factor.")
  circularity = analysis.select(custom_msr_info)
else:
  print(f"Invalid formula: {circularity_formula}")
      
AnalysisMsr analysis = new AnalysisMsr();
// Create a circularity factor between 0 and 1
String circularityFormula = "1.0/" + NativeMeasurements.InverseCircularity2d.name;
if (Processing.CheckMeasurementFormula(circularityFormula))
{
    var customMeasurementInfo =
        AnalysisMsr.RegisterCustomMeasurement("Circularity", circularityFormula, "This is my circularity factor.");
    var circularity = analysis.Select(customMeasurementInfo);
}
else
    Console.Error.WriteLine("Invalid formula: " + circularityFormula);