This section shows some examples on how to use arrays. For more
information about array functions, refer to the Matrox Design
Assistant Reference.
Initializing an array using the array operator can be useful,
for example, when quantizing (constraining) a set of results based
on a specific property. Consider the following expression, which
ranks a set of blobs by the size of their areas:
LOOKUP(SELECT(BlobAnalysis.BlobFound, Item.Area),
[0,25,50,75,100], LessOrEqual, [extra-small, small, medium, large,
extra-large])
In this example, the LOOKUP
function's parameters are the following:
-
SourceArray = SELECT(BlobAnalysis.BlobFound,
Item.Area)
-
PositionLookupArray = [0,25,50,75,100]
-
MatchType = LessOrEqual
-
ResultLookupArray = [extra-small, small, medium,
large, extra-large]
The SELECT
function returns an array with the areas of all the blobs found
(for example, [32.5, 50.2, 14.3, 100.3, 75, 30.4]). For each blob
area, the LOOKUP
function establishes the index of the last value in the
position-lookup array which is less than or equal to the blob area.
Considering the first area (32.5): the last value that is less than
or equal to 32.5 in the position-lookup array is 25. Since 25 is at
index 2, 2 is used for the first element of the source array. Going
through each area yields temporary array [2, 3, 1, 5, 4, 2].
Then, for each element of the temporary array, the LOOKUP
function maps the element's value to an index of the result-lookup
array, and returns the value at this index. The final result is
[small, medium, extra-small, extra-large, large, small].
As a comprehensive example, consider the following
expression:
ARRAYTOSTRING(FLATTEN(PatternMatching.Models,
Item.Occurrences,
CONCAT(Item.Name, " (", SubIndex, "/", SubItemCount, ")", " Score =
", TOSTRING(SubItem.Score, ":F1"))), "\r\n")
This expression has the following functions: ARRAYTOSTRING,
FLATTEN,
CONCAT,
and TOSTRING.
The FLATTEN
function's parameters are the following:
sourceArray = PatternMatching.Models
subArray = Item.Occurrences
expression = CONCAT(Item.Name, " (",
SubIndex, "/", SubItemCount, ")", " Score = ", SubItem.Score)
The FLATTEN
function references the results of a
PatternMatching step. The source array parameter points to
the collection of models, whereas the sub-array parameter uses the
expression Item.Occurrences to
point to the found occurrences for each model.
As such, the keywords SubIndex,
SubItem, and SubItemCount let you extract and print
information about the occurrences in the sub-array. For example,
each model occurrence has a Score property, so the
expression SubItem.Score accesses
the score of each occurrence of the model whose results are
currently being accessed.
The CONCAT
function acts as the expression parameter to the FLATTEN
function. Its parameters are the following:
value 1 = Item.Name
value 2 = " ("
value 3 = SubIndex
value 4 = "/"
value 5 = SubItemCount
value 6 = ")"
value 7 = " Score = "
value 8 = SubItem.Score
The CONCAT
function converts the following information for each model
occurrence into a single string: the model occurrence's name, its
index with respect to the total number of occurrences for that
model, and its score. The TOSTRING
function allows you to represent the score with one decimal
place.
The FLATTEN
function then finishes executing by returning an array of strings,
each string element of the array corresponding to an occurrence of
a model.
Finally, the ARRAYTOSTRING
function converts the entire array into one string, separating each
string element into rows by using "\r\n" (return and newline) as
separator characters.
Assuming the
PatternMatching step model searches for 2 models named
"Model_A" and "Model_B", if it found 6 occurrences and collected
them in decreasing score order per model, a possible output for
this expression would be:
|
Model_A (1/4) Score = 99.8
|
Model_A (2/4) Score = 80.2
|
Model_A (3/4) Score = 79.1
|
Model_A (4/4) Score = 75.2
|
Model_B (1/2) Score = 98.5
|
Model_B (2/2) Score = 78.3
|