# FindSegment

Locates a pair of Edge within an image region and computes the arc distance between them. FindSegment forms a one-dimensional projection of the image region by summing pixel values in the x-direction of the region. Edge transitions are extracted from the projected image data. The arc segment over which the edge-to-edge distance is computed is derived from the region used to extract the edges.

## FindSegment Inputs

Parameter | Description
Image | This parameter must reference a spreadsheet cell that contains an Image data structure; by default, this parameter references A0, the cell containing the AcquireImage data structure. This parameter can also reference other Image data structures, such as those returned by the Image Vision Data Access Functions or Coordinate Transforms Functions.
Fixture | Defines the Region of Interest (ROI) relative to a Fixture input or the output of a Vision Tools function's image coordinate system. Setting the ROI relative to a Fixture ensures that if the Fixture is rotated or translated, the ROI will be rotated or translated in relation to the Fixture. The default setting is (0,0,0), the top leftmost corner of the image.
X | The X offset, in image coordinates.
Y | The Y offset, in image coordinates.
Theta | The rotation from the image X axis, in the image coordinate system. (+/-360 degrees clockwise)
Region | Also known as the Region of Interest (ROI), specifies the region of the image that undergoes analysis; creates an Interactive Graphics Mode that can be transformed and rotated. With this parameter selected, by pressing the Maximize Region button on the property sheet's Job Edit toolbar, the region will automatically be stretched to cover the entire image.
X | The x-offset of the origin, in fixture coordinates.
Y | The y-offset of the origin, in fixture coordinates.
Height | The dimension along the region's x-axis.
Width | The dimension along the region's y-axis.
Angle | The orientation, in fixture coordinates.
Curve | The angular deviation between the region's x-axis and the opposing boundary line.
Note: The Fixture and Region parameters must be defined within the bounds of the image; otherwise, the function will return #ERR.
Segment Color | Specifies the color of the segment to be located. FindSegment will only report only edge pairs of the specified polarity.
0 = black (default) | Specifies black or white-to-black followed by black-to-white polarity.
1 = white | Specifies white or black-to-white followed by white-to-black polarity.
Find By | Specifies the edge selection technique.
0 = widest segment (default) | Finds the two edges farthest apart from which a segment of the specified Segment Color can be identified.
1 = strongest edges | Finds the two edges with the strongest response scores from which a segment of the specified Segment Color can be identified.
2 = widest contiguous segment | Finds the two edges from which a segment of the specified Segment Color can be identified without any other edges in between them.
3 = narrowest segment | Finds the two edges nearest each other from which a segment of the specified Segment Color can be identified.
Accept Thresh | Specifies the minimum acceptable edge contrast (0 to 100; default = 25); the contrast value is normalized from the greyscale histogram within the Region to a scale of 0 to 100. The function will reject any edge whose contrast score falls below this value.
Normalize Score | Specifies whether the edge scores will be normalized by the greyscale histogram of the Region. When Normalize Score is enabled, raw edge scores are normalized by the maximum contrast found within the image region using the following formula: Score = (Raw Edge Score) x (100/Max Contrast) Where Raw Edge Score is the grey level difference across the edge and Max Contrast is the difference between the maximum and minimum grey level (0 to 255) within the image region. When Normalize Score is disabled, low contrast edges will score lower than high contrast edges. The following formula is used: Score = (Raw Edge Score) x (100/255)
0 = OFF | Do not normalize the score.
1 = ON (default) | Normalize the score.
Tip: This parameter is useful for finding edges in a low contrast region. If the edges to be detected are expected to be only high contrast, disable this parameter.
Angle Range | Specifies the function's tolerance to edge rotation (0 to 10; default = 0). The function will still find edges that are outside of the specified range, but the accuracy may not be as high. Note: Setting this parameter to a value greater than 0 will reduce the speed of the function.
Edge Width | Specifies the pixel distance (1 to 50; default = 3) over which an edge transition takes place. Edge Width is used to filter the image before edges are extracted.
Show | Specifies the display mode for FindSegment graphical overlays on top of the image.
0 = hide all (default) | All graphics will be hidden, except when the cell containing the FindSegment function is the active cell in the spreadsheet.
1 = result graphics only | The two edges that define the edge segment will be displayed at all times.
2 = input and result graphics | Both the input image region and the two edges will be displayed at all times.
3 = show all: input, result, and chart | The input image region, the two edges, and the edges' response chart will be displayed at all times. Note: The edge response chart is a dockable window. For more information, see the Spreadsheet Editor – Charts topic.

## FindSegment Outputs

Returns | An Edges data structure containing a matched pair of straight-line edges, or #ERR if any of the input parameters are invalid.
Results | When FindSegment is initially inserted into a cell, a result table is created in the spreadsheet. Two Edges Vision Data Access Functions are automatically inserted into the spreadsheet to create the result table:
Label | Function | Description
Distance | PairDistance(Edges, 0, 1) | The segment distance.
Score | GetScore(Edges, 0) | The contrast score of the segment.
Additional data elements can be accessed using Edges Vision Data Access Functions