The exeRecipe function is used to execute a given recipe on a given image and return the binary mask data and their corresponding measurements.


image: file path to image as a raw string or image matrix. For companion images input a list of raw strings or image matrices. numpy.ndarray image support: numpy arrays must be converted to a list, see example below.
recipePath: file path to recipe as raw string
cal: calibration factor in units of micrometer per pixel as a float (optional as of 3.2.3)

recOutput: dictionary variable that contains the binary masks of segmentation and measurements. Binaries can be retrieved by calling the layer and 'binary' key and measurements are retrieved by calling the layer name and the measurement key.


X = mipar.exeRecipe(imagePath, recipePath) #to keep existing calibration factor saved with the recipe
X = mipar.exeRecipe(imagePath, recipePath, cal) #to override the existing calibration factor


# initialize engine and license manager
import miparAPI
import cv2
mipar = miparAPI.initialize()
mipar.startLicenseMan(nargout = 0)

# image and recipe paths
recipePath = r'C:\Users\USER\Documents\Python\ExampleRecipe.rcp'
imagePath = r'C:\Users\USER\Documents\Python\\ExampleImage.png'

# numpy image (alternative to using an image path)
img = cv2.imread(r'C:\Users\USER\Documents\Python\ExampleImage.png)
imagePath = img.tolist()

# setting up python list for passing in companion images (only if your recipe uses dynamic load companion steps)
originalImage = r'C:\Users\USER\Documents\Python\\ExampleImage.png'
companion1 = r'C:\Users\USER\Documents\Python\\Companion1.png'
companion2 = r'C:\Users\USER\Documents\Python\\Companion2.png'
imagePath  = [originalImage, companion1, companion2]

# execute Recipe
recOutput = mipar.exeRecipe(imagePath, recipePath, 0)

# retrieve dictionary keys
print(list(recOutput.keys())) #layer names
print(list(recOutput['LayerName'].keys())) #measurement names
print(list(recOutput['LayerName']['featMeas'].keys())) #retrieve feature measurement keys

# retrieve data
binaryOutput = recOutput['LayerName']['binary'] #retrieve binary segmentation
measurementOutput = recOutput['LayerName']['MeasName'] #retrieve global measurement
featureMeasurementOutput = recOutput['LayerName']['featMeas']['MeasName']._data #retrieve feature measurement raw data
calibrationOutput = recOutput['cal']['value'] #retrieve calibration value in units of micrometers per pixel
measurementUnits = recOutput['cal']['units'] #retrieve the measurement units
messages = recOutput['Messages'] #retrieve messages, warnings, and errors from recipe execution.  Present in v3.2.3 and later

# MeasNames can be Global Measurements such as: Area, Area Fraction and Number Density.
# It can also be Feature Measurements statistics such as: Mean Caliper Diameter, Min Roughness, Max Equivalent Diameter or StdDev Area Fraction. 
# The notation is concatenated, for example the key for Global Number Density is NumberDensity and the key for Mean Feature Caliper Diameter is MeanCaliperDiameter. 
# It is recommended to pull the keys of measurements to get a complete list of measurements in the recipe.

# terminate engine

Measurements Units

Image Measurement Examples Units
Counts, Intensities, Similarity Count, Estimate Count, Intensity, Mutual Information, Correlation Coefficient unitless
Areas Area pixels (px) or unit^2 (um^2, in^2, ft^2)
Lengths Perimeter, Intercepts, Image Dim pixels (px) or unit (um, in, ft)
Inverse Lengths Perimeter Fraction, Inverse Intercepts 1/px or 1/unit (um, in, ft)
Densities Number Density features/px or features/unit^2 (um^2, in^2, ft^2)
Fractions Area Fraction, Count Fraction percent (%)
Feature Measurement Examples Units
Counts, Intensities, Shape Companion ID, Companion Features Intensity, Roughness, Eccentricity, Aspect Ratio unitless
Areas Area, Companion Area pixels (px) or unit^2 (um^2, in^2, ft^2)
Lengths Diameters, Lengths, Neighbor Distance px or unit (um, in, ft)
Combination Perimeter/Area 1/px or 1/unit (um, in, ft)
Location Centroid pixels (px) or unit (um, in, ft)
Orientation Orientation, Tilt degrees (deg)
Local Measurement Examples Units
Counts, Intensities, Shape Count, Anisotropy unitless
Fractions Area Fraction percent (%)
Shape Curvature 1/px or 1/unit
Densities Number Density features/px or features/unit^2 (um^2, in^2, ft^2)
Lengths Thickness, Nearest Distance pixels (px) or unit (um, in, ft)

Need more help with this?
Chat with an expert now ››

Was this helpful?

Yes No
You indicated this topic was not helpful to you ...
Could you please leave a comment telling us why? Thank you!
Thanks for your feedback.