Halcon-based plank defect detection algorithm code - Halcon-based region growth, Otsu segmentation algorithm, histogram equalization

Keywords: Halcon; image processing; visual inspection; board defect detection; feature extraction

For the detection of apparent defects of wooden products such as wooden strips and boards, it is a main application of machine vision detection in industry, and the extraction and detection of knots is an important quality control detection index. This paper uses knot holes , dead knots and live knots as examples, share the image preprocessing (grayscale, histogram equalization, smoothing, etc.) etc.), and finally realize the location of defects, and extract multi-dimensional features, which are used for subsequent SVM (support vector machine) or feature quantity input for neural network training. The reason why deep learning is not used is that for students, the interpretation of the final effect of directly using deep learning is not good, and it is not easy to reflect their own workload. After all, it does not need the previous preprocessing and feature extraction. Secondly, for the application perspective of certain scenarios, there may not always be a particularly large number of samples, and deployment time is also a problem. For the subsequent SVM, the classification codes of the three defects will be updated later when there is time. The following is the general operation process and general effect, and the complete code is attached at the end. The final program and pictures can go to the official account and go to the official account directly for free.

1. Image grayscale
(1) Component method (R, G, B random one)
(2) Maximum value method
(3) Average value method
(4) Weighted average method (R, G, B weight value Appropriate enough)
Use the above four methods to grayscale the collected color image (named as grayscale image).
2. Histogram equalization processing
Perform histogram equalization processing on the images of live joints, dead joints and knot holes respectively.
The corresponding image after equalization and the equalization histogram are obtained.
3. Image smoothing processing
Add noise (such as 0.02 salt and pepper noise) to the original image (the image sent to you named grayscale image), and use the following filtering methods to denoise.
(1) Neighborhood average method
(2) Median filtering method
(3) Adaptive weighted median filtering method
Obtain image smoothing result image.
4. Image sharpening:
Laplace sharpening and Sobel sharpening are performed on the above-mentioned images of living joints, dead joints and knot holes.
Get the sharpened image.

5. Image segmentation
The following two algorithms are used for image segmentation for the above-mentioned living joints, dead joints and knot hole defects respectively
(1) Otsu threshold segmentation algorithm
(2) segmentation algorithm based on region growth

Obtain defect segmentation images.

6. Morphological post-processing

Dilation, erosion, and opening and closing operations are performed on the segmented image.

7. Feature extraction
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
Code:
insert image description here
insert image description here
The source code of the program can be downloaded from the WeChat public account [Dongguan Scientific Research] to obtain the network disk link.

Guess you like

Origin blog.csdn.net/u014751362/article/details/129030725