# Custom Display Filters

You can specify custom filters by using specific keywords, logical operators, variables, methods, operators, and conditions. You can also construct custom filters with regular expressions.

Construct your custom filter in a way that it evaluates to a Boolean result.

## Display Filter Keywords

When creating custom filters, you can start with the keywords in the in the Display drop-down menu, and then add logical operators and variables.

In addition to the Display drop-down menu keywords, you can use the following keywords by typing them in the Display field:

- positive: Used with the Red Analyze tool, returns Views that have defects.
- negative: Used with the Red Analyze tool, returns Views that do not have defects.
- 'filename_word': Returns Views that have filenames, which contain a word. For example, if you have curated images in your Training Set that are named "bad_head_001.png", "bad_head_002.png", and so on,. to return only the Views that contain the word "bad_head" in the filename, enter 'bad_head' into the Display field.

## Display Filter Logical Operators

You can use keywords (and conditions) together with logical operators to build custom selection filters. The three basic logical operators, not, and, or, are available to construct custom filters.

Example | Description
--- | ---
not trained | Returns Views that are not used for training Training is the process that your tool, which is a neural network, is learning about the features (pixels) based on the labels you made. For example, a tool will learn the defect/normal pixels in each image based on the defect/normal labels you drew. The goal of the tool Training is learning enough to give the correct inspection results of whether an unseen image is defective or not. The key to training is to ensure that you include all possible variations within your training set, and that your images are accurately labeled. Training times vary by the application, tool setup and the GPU in the PC being used to train the network..
good and not 'good' | Returns Views labeled as good and whose image filename does not contain the word 'good'.
labeled or not manual | Returns Views that are labeled and/or whose training flag is set to Auto.

## Display Filter Variables

You can use variables, methods, and basic mathematical comparison operators (=, >, <,...) to construct special conditions to select a particular set of Views. The available variables for each of the tools are summarized in the following tables:

- All Tools

  Variable | Description
  --- | ---
  random | Generates a random variable in the interval [0,1] for each View.

- Red Analyze Tool

  Variable | Description
  --- | ---
  score | Returns the overall score of the Views (highest region score).
  th | Returns the threshold (displayed in the Scores graph and the Threshold parameter). If you have multiple defect classes, use the th[CLASSNAME] syntax to filter for a specific class.
  region/score | Returns the scores of the defective regions found by the system. This variable potentially returns a list of values (see the Notes section below for more information).
  region/area | Returns the area of the defective regions.
  region/x | Returns the horizontal position of the defective regions.
  region/y | Returns the vertical position of the defective regions.
  region!/(score│area│x│y) | Returns the score, area, horizontal or vertical values of labeled regions.
  background/score | Returns the background scores, in other words, scores that are outside of the defective regions.

- Green Classify Tool

  Variable | Description
  --- | ---
  tag/score | Returns the probability scores of each tag/class. This variable returns a list of values (see the Notes section below for more information).
  tag[Tag_Name]/score | Returns the predicted probability score pertaining to the class "Tag_Name".
  tag![Tag_Name] | Returns True for Views labeled with the tag/class "Tag_Name". This variable can also be used to select Views labeled with the tag "Tag_Name".
  tag!/score | Returns the probability score of the correct (labeled) class.
  tag![Tag_Name]/score | Returns the probability score of the correct class, selecting only Views labeled with the tag/class "Tag_Name".
  outlier_score | Returns the outlier score.

- Blue Locate and Blue Read Tools

  Variable | Description
  --- | ---
  feature A feature is a visually distinguishable area in an image. Features typically represent something of interest for the application (a defect, an object, a particular component of an object). | Returns one or more found features in the View, and displays a thumbnail of the feature(s).
  feature[0] or feature[0,1] | Returns Views where the specified feature (0) is found (if used as a single statement, otherwise the list of found features; see the Notes section below for more information).
  feature![0] or feature![0,1,2] | Returns the same as above, except only for the specified feature that was labeled.
  feature[0]/score | Returns the probability scores for features marked (predicted) as 0.
  feature[0]/x | Returns the horizontal position of the feature 0.
  feature[0]/y | Returns the vertical position of the feature 0.
  feature![0]/(score│x│y) | Returns the score, horizontal or vertical position for the labeled feature 0.
  match | Returns True if a model A specific spatial arrangement of a set of features (Blue Locate and Blue Read tools only.) During a post-processing step, the Blue Locate and Blue Read tools can fit all of the features detected in an image to the models defined for the tool. The overall pose and identity of the model is then returned. was found, or a list of found models (see the Notes section below for more information).
  match[Model1] | Returns the same as above, but only if Model1 was found.
  match![Model1] | Returns the same as above, but for a model found among the labeled features.
  match[Model1]/score | Returns the scores of the found model (Model1). This variable can potentially return a list of values; see the Notes section below for more information.
  match[Model1]/angle | Returns the angles of the found models.
  match[Model1]/scale | Returns the scales of the found models.
  match[Model1]/shear | Returns the shearing of the found models.
  match[Model1]/x | Returns the horizontal positions of the found models.
  match[Model1]/y | Returns the vertical positions of the found models.
  match![Model1]/(score│angle│scale│shear│x│y) | Returns the same as above, but for a model with labeled features.
  match/features | Returns the number of marked features in any model matched by the system (potentially returns a list of values; see the Notes section below for more information).
  match[Model1]/features | Same as above, but for specific model Model1.
  match!/features | Number of features of any model matched among labeled features.
  match![Model1]/features | Same as above, but for specific model Model1.

Note:

Some variables might return a list of values (whenever there are many possible values as an output). Some properties (the number of elements, the maximum or the minimum) of such returned lists can be extracted with the methods described below.

Tool | Example | Comment
--- | --- | ---
Red Analyze | region/(score│area│x│y) | Returns a list of scores, with each value corresponding to one found region. A probability score always lies in the interval of [0,1]. The Red Analyze tool returns a probability score only when used in Legacy mode (for example the probability of a region to be defective).
Green Classify | tag/score | Returns the list of probabilities for each class. A probability score always lies in the interval of [0,1]. In addition, the list of values returned by tag/score add up to 1.
Blue Locate Blue Read | feature, match | Returns true as a single statement, otherwise will return a list of found features or models.
feature![0]/(score│x│y) | Returns the scores, horizontal or vertical positions of the labeled feature 0.
match[Model1]/(score│angle│scale│shear│x│y) | Returns the list of scores, angles, scale, shear, horizontal or vertical positions of any found model (Model1).

## Display Filter Methods

A few methods are available to access some properties of lists of values, as returned by some variables.

Method | Description
--- | ---
count() | Returns the number of items in a list.
filtered() | Removes the score of filtered regions. By default, the region filter removes only the regions, not the scores. This can be confusing because scores can still appear even if the filter removes the regions. To avoid this, use the filtered() syntax. This sets the score of filtered regions to zero, ensuring that only the relevant scores appear.
max() | Returns the maximum in a list.
min() | Returns the minimum in a list.

## Display Filter Operators and Conditions

Basic mathematical comparison operators can be used in conjunction with variables to construct filtering conditions.

Symbol | Example | Description
--- | --- | ---
= | count(feature![h])=3 | Returns Views with exactly 3 features with a label ID of "h".
!= | count(match)!=0 | Returns Views where the number of found models is not equal to 0.
< > | feature[t]/score>0.9 | Returns Views where the feature "t" is found, and has a probability score greater than 90%.
<= | min(region/x)<=50 | Returns Views whose leftmost defective region is located, at most, 50 pixels away from the left image border.
>= | random>=0.8 | Returns approximately 80% of the Views.
in | not score in [0.28,0.43] | Returns Views whose score lies outside the [0.28,0.43] interval (where 0.28 = threshold 1, and 0.43 = threshold 2).