Syntax Check
This section introduces how to check the syntax of command parameters.
Formulae can be composed of constants, operators, functions, and variables (native measurements and custom measurements).
Remarks:
Custom Formula syntax
A custom formula syntax is checked by several ImageDev algorithms:- The ImageFormula algorithm
- Individual analysis with custom measurements
- Object filtering algorithms like LabelFiltering
Formulae can be composed of constants, operators, functions, and variables (native measurements and custom measurements).
Remarks:
- The following (unless specified) constants, operators, functions, and variables are case-insensitive and can be used both with custom measurements and custom filters.
- The following (unless specified) operators and functions are insensitive to spaces. Constants and variables must not be directly attached to alpha numerical symbols.
Basic operators
- (): brackets allow you to group elements and to modify operator precedence
example: (2 + 3)*4 - +: unary arithmetic operator [plus]
example: + a - -: unary arithmetic operator [minus]
example: - b - +: binary arithmetic operator [plus]
example: a + b - -: binary arithmetic operator [minus]
example: a - b - *: binary arithmetic operator [multiply]
example: a * b - /: binary arithmetic operator [divide]
example: a / b
remark: a division by 0 returns the value 0 in order to avoid exceptions. - **: binary arithmetic operator [power]
example: a ** b - !: unary logical operator [not]
example: !(a> b) - && or And: binary logical operator [and]
example: (a > b) && (a < c)
example: (a > c) And (a < c)
remark: And operator must not be directly attached to alpha numerical symbols. - || or Or: binary logical operator [or]
example: (a > b) || (a < c)
example: (a > b) Or (a < c)
remark: Or operator must not be directly attached to alpha numerical symbols. - ==: comparison operator (logical and arithmetic) [equal]
example: a==b
example: true==true - !=: comparison operator (logical and arithmetic) [different]
example: a != b
example: true != false - <: arithmetic comparison operator [strictly inferior]
example: a < b - <=: arithmetic comparison operator [less]
example: a<= b - >: arithmetic comparison operator [strictly superior]
example: a > b - >=: arithmetic comparison operator [superior]
example: a >= b
Constant values
- Pi: $\pi$, the pi constant
example: 3 * Pi - E: the Euler's constant
example: 2 * E - True: the true boolean value
example: (3< Pi)==True - False: the false boolean value
example: (3> Pi)==False - NbFeret: distribution size for Feret measurements
example: 3*NbFeret - gx, gy and gz: image X, Y, and Z dimensions
example: 3*gx
remark: not available for custom filters - cx, cy and cz: pixel real size according to calibration
example: 3*cx
remark: not available for custom filters
Functions
- Abs: absolute value of a numerical value
example: Abs(a) - Sqrt: square root value of a numerical value
example: Sqrt(a)
remark: a must be positive or null - Exp: exponential value of a numerical value
example: Exp(a) - Log: natural logarithm value of a numerical value
example: Log(a)
remark: a must be strictly positive - Cos: cosine value of a numerical value
example: Cos(a) - Sin: sine value of a numerical value
example: Sin(a) - Tan: tangent value of a numerical value
example: Tan(a) - ACos: arccosine value of a numerical value
example: ACos(a)
remark: a must be within the range [-1, 1] - ASin: sine arcvalue of a numerical value
example: ASin(a)
remark: a must be within the range [-1, 1] - ATan: arctangent value of a numerical value
example: ATan(a) - ATan2: arctangent value of a 2d point
example: ATan2(y, x) - CosH: hyperbolic cosine value of a numerical value
example: CosH(a) - SinH: hyperbolic sine value of a numerical value
example: SinH(a) - TanH: hyperbolic tangent value of a numerical value
example: TanH(a) - Min: retrieve minimum value of a variable sized set of numerical values
example: Min(a, b, c, d) - Max: retrieve maximum value of a variable sized set of numerical values
example: Max(a, b, c, d, e) - Avg: retrieve mean value of a variable sized set of numerical values
example: Avg(a, b, c) - Median: retrieve median value of a variable sized set of numerical values
example: Median(a, b, c, d) - Sum: compute the sum of a variable sized set of numerical values
example: Sum(a, b, c) - Product: compute the product of a variable sized set of numerical values
example: Product(a, b, c, d, e) - If: conditional evaluation of an expression
example: If(predicat, value_true, value_false)
remark: Each member of a conditional expression is systematically evaluated even if it is not supposed to be reached by the condition. Thus, an instruction can raise an error even if the condition is supposed to prevent invalid evaluations.
example: If(I1< =0, 0, log(I1)) will raise an error if a voxel value is lower or equal to 0 since the log expression will be evaluated before the if statement.
Syntax
Method | Description |
---|---|
bool checkFilterFormula( const std::string& formula ) |
Checks if a filter selecting labels from analysis measurements criteria is valid.
Returns true if the formula is valid, returns false otherwise. |
bool checkImageFormula( const std::string& formula ) |
Checks if a formula to be used by the ImageFormula algorithm is valid.
Returns true if the formula is valid, returns false otherwise. |
bool checkMeasurementFormula( const std::string& formula ) |
Checks if the defining a new custom measurement is valid.
Returns true if the formula is valid, returns false otherwise. |
Method | Description |
---|---|
check_filter_formula(formula) |
Checks if a filter selecting labels from analysis measurements criteria is valid.
Returns true if the formula is valid, returns false otherwise. |
check_image_formula(formula) |
Checks if a formula to be used by the ImageFormula algorithm is valid.
Returns true if the formula is valid, returns false otherwise. |
check_measurement_formula(formula) |
Checks if the defining a new custom measurement is valid.
Returns true if the formula is valid, returns false otherwise. |
Method | Description |
---|---|
public bool CheckFilterFormula(string formula) |
Checks if a filter selecting labels from analysis measurements criteria is valid.
Returns true if the formula is valid, returns false otherwise. |
public bool CheckImageFormula(string formula) |
Checks if a formula to be used by the ImageFormula algorithm is valid.
Returns true if the formula is valid, returns false otherwise. |
public bool CheckMeasurementFormula(string formula) |
Checks if the defining a new custom measurement is valid.
Returns true if the formula is valid, returns false otherwise. |