Basic knowledge
blob analysis
1. Significance
Blob analysis is to analyze the connected domain of the same pixel in the image, which is called Blob.
Blob analysis can provide the number, location, shape and direction of speckles in the image for machine vision applications, as well as the topological structure between the related speckles.
2. Scope of application
Only for two-dimensional target image and high contrast image, it is suitable for detection with or without defect.
Blob analysis is used in textile defect detection, glass defect detection, mechanical parts surface defect detection, cola bottle defect detection, drug capsule defect detection and many other occasions.
3. Main Process of Blob Analysis
Getting image - > Segmenting image (distinguishing foreground and background pixels) - > Feature extraction (such as area, center of gravity, rotation angle, etc.)
Halcon code implementation:
Read_image (Image,'particle')
Threshold (Image, BrightPixels, 120, 255)
Connection (Bright Pixels, Particles)
Area_center (Particles, Area, Row, Column)
4. Extension of Blob Analysis
In practical application, more steps need to be dealt with, because of many practical factors, target information is difficult to deal with. For example, there are many speckles in the image (it is difficult to extract the target location), and the illumination is uneven.
Blob analysis also needs post-processing. For example, the feature information is transformed into actual coordinate information, and the object is displayed.
Getting image - > Applying ROI - > Locating ROI - > Correcting image - > Image preprocessing - > Dynamic acquisition of segmentation parameters - > Segmented image - > Processing area - > Feature extraction - > Converting pixel coordinates to world coordinates - > Results display or output
Common operators for image preprocessing:
Mean_image: Mean Filtering
Gauss_image: Gauss filtering
Median_image: median filtering
Common operators for dynamically obtaining segmentation parameters:
Gray_histo_abs: Gray histogram
His_to_thresh: Histogram Binarization
5. Segmented image
Threshold operator, the simplest, fastest and most frequently used method, is suitable for scenes with certain gray difference between object and background.
Automatic global threshold segmentation method 1:
Compute histogram;
Find the gray value with the most frequency.
In thresholds, the value with a certain distance from the maximum value is used as the threshold value.
Halcon code implementation:
Gray_histo (Image, Image, Absolute Histo, Relative Histo)
PeakGray: = sort_index (Absolute Histo) [255]
Threshold (Image, Region, 0, PeakGray-25)
Automatic global threshold segmentation method II:
Multiple iteration smoothing;
Find two peaks.
Use thresholds to find the minimum between two peaks
Bin_threshold (Image, Region)
Common image segmentation operators:
Threshold: global threshold binarization
Bin_threshold: Automatic threshold binarization
Dyn_threshold: Local threshold binarization
Watersheds: watershed
6. Feature extraction
1) Regional characteristics
Area, moment Moments, minimum rectangular smallest_rectangle 1 parallel to the spindle, minimum rectangular smallest_rectangle 2 in any direction,
Minimumicircular smallest_circle, convexity: convex hull area, contlength: region boundary length
Roundness, circularity, compactness, rectangularity
2) Gray Level Characteristics
Simple Gray Value Characteristics: Average Gray Value of Region
Minimum and Maximum Gray Value of Region
7. Examples of c++ Application
Hobject rect;
Gen_rectangle1 (& rect, m_pStToolParam_BwArea-> rcROIRect.Row1, m_pStToolParam_BwArea-> rcROIRect.Col1,
M_pStToolParam_BwArea-> rcROIRect.Row2, m_pStToolParam_BwArea-> rcROIRect.Col2;
HTuple S1, S2;
Count_seconds(& S1);
Threshold (Image ROI, & Connected Regions);
Area_center (Connected Regions, & (m_pStToolParam_BwArea->tArea), & (m_pStToolParam_BwArea->tPosRow),
& (m_pStToolParam_BwArea->tPosCol);
Disp_obj (Region,* pWnd);
-------------------------------
Author: Heaven and Earth 555
Source: CSDN
Original: https://blog.csdn.net/surui_555/article/details/47837167
Copyright Statement: This article is the original article of the blogger. Please attach a link to the blog article for reprinting.