introduction
Case study of ball.hdev
1, Results
1.1 reading the original drawing
1.2 welding ball inspection
2, Halcon code
* ball.hdev: Inspection of Ball Bonding * //Turns on or off the automatic output of icon output objects to the graphics window during program execution. dev_update_window ('off') //Close the active graphics window. dev_close_window () //Open a new graphics window. dev_open_window (0, 0, 728, 512, 'black', WindowID) //Read an image with different file formats. read_image (Bond, 'die/die_03') //Displays image objects in the current graphics window. dev_display (Bond) set_display_font (WindowID, 14, 'mono', 'true', 'false') disp_continue_message (WindowID, 'black', 'true') stop () //Stop program execution. //Threshold -- uses the global threshold to segment the image threshold (Bond, Bright, 100, 255) //Transform the shape of the region shape_trans (Bright, Die, 'rectangle2') //Set one or more output colors. dev_set_color ('green') //Defines the lineweight of the area contour output dev_set_line_width (3) //Define the region fill mode dev_set_draw ('margin') //Displays image objects in the current graphics window. dev_display (Die) disp_continue_message (WindowID, 'black', 'true') stop () //Reduce the domain of an image. reduce_domain (Bond, Die, DieGrey) //Threshold -- uses the global threshold to segment the image threshold (DieGrey, Wires, 0, 50) //Fills a hole in an area with a given shape feature. fill_up_shape (Wires, WiresFilled, 'area', 1, 100) //Displays image objects in the current graphics window. dev_display (Bond) Define the region fill mode dev_set_draw ('fill') // Set one or more output colors. dev_set_color ('red') //Displays image objects in the current graphics window. dev_display (WiresFilled) disp_continue_message (WindowID, 'black', 'true') stop () //Open an area with circular structural elements opening_circle (WiresFilled, Balls, 15.5) dev_set_color ('green') dev_display (Balls) disp_continue_message (WindowID, 'black', 'true') stop () // Compute connected components of a region. connection (Balls, SingleBalls) //Choose regions with the aid of shape features select_shape (SingleBalls, IntermediateBalls, 'circularity', 'and', 0.85, 1.0) //Sort regions according to their relative positions sort_region (IntermediateBalls, FinalBalls, 'first_point', 'true', 'column') dev_display (Bond) dev_set_colored (12) dev_display (FinalBalls) disp_continue_message (WindowID, 'black', 'true') stop () //Minimum bounding circle of a region smallest_circle (FinalBalls, Row, Column, Radius) NumBalls := |Radius| Diameter := 2 * Radius meanDiameter := sum(Diameter) / NumBalls mimDiameter := min(Diameter) dev_display (Bond) disp_circle (WindowID, Row, Column, Radius) dev_set_color ('white') for i := 1 to NumBalls by 1 if (fmod(i,2) == 1) disp_message (WindowID, 'D: ' + Diameter[i - 1], 'image', Row[i - 1] - 2.7 * Radius[i - 1], max([Column[i - 1] - 60,0]), 'white', 'false') else disp_message (WindowID, 'D: ' + Diameter[i - 1], 'image', Row[i - 1] + 1.2 * Radius[i - 1], max([Column[i - 1] - 60,0]), 'white', 'false') endif endfor * dump_window (WindowID, 'tiff_rgb', './ball') dev_set_color ('green') dev_update_window ('on') disp_continue_message (WindowID, 'black', 'true') stop () dev_close_window ()
3, Main function analysis
1.threshold (Operator)
threshold — Segment an image using global threshold.
result
... threshold (Bond, Bright, 100, 255) ...
... threshold (DieGrey, Wires, 0, 50) ...
function
threshold(Image : Region : MinGray, MaxGray : ) //parameter Image (input_object) //Input image. Region (output_object) //Segmented region. MinGray/MaxGray (input_control) //Lower / lower limit of gray value Default value: 128.0/255.0 Suggested values: 0.0, 10.0, 30.0, 64.0, 128.0, 200.0, 220.0, 255.0 Restriction: MaxGray >= MinGray
Threshold selects pixels from the input image whose gray value g meets the following conditions:
All points of the image that meet the conditions are returned as a region. If multiple gray value intervals (tuples of MinGray and MaxGray) are passed, a separate area is returned for each interval.
correlation function
auto_threshold (Operator)
//auto_threshold - segment the image using the threshold determined from the histogram. auto_threshold(Image : Regions : Sigma : )
binary_threshold (Operator)
//binary_threshold -- segment the image using a binary threshold binary_threshold(Image : Region : Method, LightDark : UsedThreshold)
char_threshold (Operator)
//char_threshold - performs threshold segmentation to extract characters. char_threshold(Image, HistoRegion : Characters : Sigma, Percent : Threshold)
dual_threshold (Operator)
//dual_threshold — Threshold operator for signed images dual_threshold(Image : RegionCrossings : MinSize, MinGray, Threshold : )
dyn_threshold (Operator)
//dyn_threshold - segment the image using a local threshold dyn_threshold(OrigImage, ThresholdImage : RegionDynThresh : Offset, LightDark : )
fast_threshold (Operator)
//fast_threshold - fast thresholding of images using global thresholds fast_threshold(Image : Region : MinGray, MaxGray, MinSize : )
hysteresis_threshold (Operator)
//hysteresis_threshold - performs a hysteresis threshold operation on the image. hysteresis_threshold(Image : RegionHysteresis : Low, High, MaxLength : )
local_threshold (Operator)
//local_threshold - segment the image using a local threshold. local_threshold(Image : Region : Method, LightDark, GenParamName, GenParamValue : )
threshold_sub_pix (Operator)
//threshold_sub_pix - extract horizontal intersections from images with sub-pixel accuracy. threshold_sub_pix(Image : Border : Threshold : )
var_threshold (Operator)
//var_threshold - threshold the image through local mean and standard deviation analysis. var_threshold(Image : Region : MaskWidth, MaskHeight, StdDevScale, AbsThreshold, LightDark : )
watersheds_threshold (Operator)
//watersheds_threshold — Extract watershed basins from an image using a threshold watersheds_threshold(Image : Basins : Threshold : )
The above threshold function operators will be analyzed in detail later, and this paper will only understand
2.shape_trans (Operator)
shape_trans -- transform the shape of the region
result
... threshold (Bond, Bright, 100, 255) shape_trans (Bright, Die, 'rectangle2') ...
function
shape_trans(Region : RegionTrans : Type : ) //parameter Region (input_object) //Regions to be transformed. RegionTrans (output_object) //Transformed regions. Type (input_control) Type of transformation. Default value: 'convex' List of values: 'convex', 'ellipse', 'inner_center', 'inner_circle', 'inner_rectangle1', 'outer_circle', 'rectangle1', 'rectangle2'
shape_trans converts the shape of the input area according to the parameter type:
- 'convex' -Convex hull.
- 'ellipse' - an ellipse with the same moment and area as the input area
- ‘outer_circle '- smallest closed circle
- ‘inner_circle '- the largest circle suitable for this area.
- 'rectangle 1 '- the smallest closed rectangle parallel to the coordinate axis
- 'rectangle 2 '- smallest closed rectangle
- ‘inner_ Rectangle 1 '- the largest axis parallel rectangle suitable for this area
- ‘inner_center '- the point on the skeleton of the input area with the smallest distance from the center of gravity of the input area
3.reduce_domain (Operator)
reduce_domain — Reduce the domain of an image
result
It is equivalent to intercepting the main part to be studied
... reduce_domain (Bond, Die, DieGrey) threshold (DieGrey, Wires, 0, 50) ...
function
reduce_domain(Image, Region : ImageReduced : : ) //parameter Image (input_object) //Input image. Region (input_object) //New definition domain. ImageReduced (output_object) //Image with reduced definition domain.
operator reduce_domain Reduces the domain of a given image to a specified area. The new domain is evaluated as the intersection of the old domain and the region. Therefore, the new domain can be a subset of the region. The size of the matrix has not changed.
4.fill_up_shape (Operator)
fill_up_shape - fills a hole in an area with a given shape feature.
result
... fill_up_shape (Wires, WiresFilled, 'area', 1, 100) dev_display (Bond) dev_set_draw ('fill') dev_set_color ('red') dev_display (WiresFilled) ...
function
fill_up_shape(Region : RegionFillUp : Feature, Min, Max : ) //parameter Region (input_object) //Input region(s). RegionFillUp (output_object) //Output region(s) with filled holes. Feature (input_control) //Shape features used. Default value: 'area' List of values: 'anisometry', 'area', 'compactness', 'convexity', 'inner_circle', 'outer_circle', 'phi', 'ra', 'rb' Min (input_control) //Minimum eigenvalue Default value: 1.0 Suggested values: 0.0, 1.0, 10.0, 50.0, 100.0, 500.0, 1000.0, 10000.0 Typical range of values: 0.0 ≤ Min Max (input_control) //Maximum eigenvalue Default value: 100.0 Suggested values: 10.0, 50.0, 100.0, 500.0, 1000.0, 10000.0, 100000.0 Typical range of values: 0.0 ≤ Max
fill_up_shape fills those holes in the input area with a given shape Feature. The parameter Feature determines the shape Feature to use, while Min and Max determine the extent to which the shape Feature must be located in order to fill the hole
5.opening_circle (Operator)
opens_circle - opens an area with circular structural elements.
result
... opening_circle (WiresFilled, Balls, 15.5) dev_set_color ('green') dev_display (Balls) ...
function
opening_circle(Region : RegionOpening : Radius : ) //parameter Region (input_object) //Regions to be opened. RegionOpening (output_object) //Opened regions Radius (input_control) //Radius of circular structural elements Default value: 3.5 Suggested values: 1.5, 2.5, 3.5, 4.5, 5.5, 7.5, 9.5, 12.5, 15.5, 19.5, 25.5, 33.5, 45.5, 60.5, 110.5 Typical range of values: 0.5 ≤ Radius ≤ 511.5 (lin) Minimum increment: 1.0 Recommended increment: 1.0
opens_circle is defined as an erosion, followed by a Minkowsi addition with circular structural elements (see example). The opening is used to eliminate small areas (smaller than circular structural elements) and smooth the boundary of the area.
6.connection (Operator)
connection — Compute connected components of a region.
function
connection(Region : ConnectedRegions : : ) //parameter Region (input_object) //Input region. ConnectedRegions (output_object) //Connected components
Connection determines the connected component of a given input Region in the Region. The neighborhood used for this can be set_system('neighborhood ', < 4 / 8 >) setting. The default is 8-neighborhood, which is useful for determining the connected component of the foreground. The maximum number of connected components returned by connection can be set_system('max_connection ',) setting. The default value of 0 causes all connected components to be returned. The inverse operator of the connection is union1.
7.select_shape
select_shape - select a region with shape features
result
connection (Balls, SingleBalls) select_shape (SingleBalls, IntermediateBalls, 'circularity', 'and', 0.85, 1.0)
function
select_shape(Regions : SelectedRegions : Features, Operation, Min, Max : ) //parameter Regions (input_object) //Regions to be examined. SelectedRegions (output_object) //Qualified area Features (input_control) //Shape features to check Default value: 'area' List of values: 'anisometry', 'area', 'area_holes', 'bulkiness', 'circularity', 'column', 'column1', 'column2', 'compactness', 'connect_num', 'contlength', 'convexity', 'dist_deviation', 'dist_mean', 'euler_number', 'height', 'holes_num', 'inner_height', 'inner_radius', 'inner_width', 'max_diameter', 'moments_i1', 'moments_i2', 'moments_i3', 'moments_i4', 'moments_ia', 'moments_ib', 'moments_m02', 'moments_m02_invar', 'moments_m03', 'moments_m03_invar', 'moments_m11', 'moments_m11_invar', 'moments_m12', 'moments_m12_invar', 'moments_m20', 'moments_m20_invar', 'moments_m21', 'moments_m21_invar', 'moments_m30', 'moments_m30_invar', 'moments_phi1', 'moments_phi2', 'moments_psi1', 'moments_psi2', 'moments_psi3', 'moments_psi4', 'num_sides', 'orientation', 'outer_radius', 'phi', 'ra', 'rb', 'rect2_len1', 'rect2_len2', 'rect2_phi', 'rectangularity', 'roundness', 'row', 'row1', 'row2', 'struct_factor', 'width' Operation (input_control) //Linkage type of the individual features. Default value: 'and' List of values: 'and', 'or' Min (input_control) //Lower limits of the features or 'min'. Default value: 150.0 Typical range of values: 0.0 ≤ Min ≤ 99999.0 Minimum increment: 0.001 Recommended increment: 1.0 Max (input_control) //Upper limits of the features or 'max'. Default value: 99999.0 Typical range of values: 0.0 ≤ Max ≤ 99999.0 Minimum increment: 0.001 Recommended increment: 1.0 Restriction: Max >= Min
Operator select_shape selects an area based on the shape. For each input region from Regions, the indicated Features are calculated. If each (Operation = 'and') or at least one (Operation = 'or') calculated feature is within the default limit (Min,Max), the area will adapt to the output (repeat)