Set a threshold of the binary level by the average of the measurement result

Overview

This sample sets a threshold of the binary level by the average of the measurement result.

Specification of this example


Behavior
This sample sets a threshold of the binary level of [Labeling] by the average of the measurement result of [Color Data].

Screenshot


How to try this example
1.Click the link below, then the folder containing zip file automatically opens.
refFile

2.Right-click and hold on the zip file, and drop it on working window of FJ system. The images and scene data in zip file are loaded on the program automatically.

3.Re-measure the image. Then System automatically sets a threshold of the binary level of [Labeling] by the average of the last five times measurement results of [Color Data].
When re-measure the same image five times, the threshold of the binary level of [Labeling] is equal to the measurement result of [Color Data] of the image.

How to implement

Scene data
Unit No.
Processing Item
0.
Camera Image Input
1.
Color Data
2.
Macro
3.
Labeling
The Macro Program below segment is to be set in '2.Macro'.
Macro Program
*MCRINIT
    MAXCOUNT& = 5         '(1)
    Dim DENSITY#(4)
    COUNT& = 0
    LABELINGUNIT& = 4
    COLORDATAUNIT& = 2

Return

*MEASUREPROC

    AVERAGE# = 0         '(2)
    If COUNT& = (MAXCOUNT& - 1) Then
        For CNT& = (MAXCOUNT& - 1) To 1 Step -1
        DENSITY#(CNT&) = DENSITY#(CNT& - 1)
        AVERAGE# = AVERAGE# + DENSITY#(CNT&)
        Next
        GetUnitData COLORDATAUNIT&, 10, DENSITY#(0)
        AVERAGE# = (AVERAGE# + DENSITY#(0)) / MAXCOUNT&
    Else 
        For CNT& = 0 To (COUNT& - 1) Step 1
        AVERAGE# = AVERAGE# + DENSITY#(CNT&)
        Next
        COUNT& = COUNT& + 1
        GetUnitData COLORDATAUNIT&, 10, DENSITY#(COUNT&)
        AVERAGE# = (AVERAGE# + DENSITY#(COUNT&)) / COUNT&
    EndIf

    SetUnitData LABELINGUNIT&, 147, AVERAGE#    '(3)

Return

The macro program is in refthis link.
Explanation
(1)Initialize parameters(ex.times of repeating to calculate the average ) when initialize measurement.
(2)Get the measurement results of [Color Data] last five times, and calculate the average of density.
(3)Set the average of density to the minimum limit of binary level of [Labeling].