A machine vision-based track defect intelligent identification method
By establishing a unified pixel coordinate system and multi-angle projection in track defect detection, and combining quadratic trend fitting and adaptive segmentation, the adaptability and accuracy problems of track defect detection in existing technologies are solved, and efficient and accurate track defect identification is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG MAI XIN TECH CO LTD
- Filing Date
- 2025-08-13
- Publication Date
- 2026-04-24
AI Technical Summary
Existing machine vision methods for track defect detection suffer from poor adaptability to defect types, limited feature representation, weak interpretability, and strong parameter dependence. They are difficult to efficiently detect slender cracks, tiny notches, etc., and are easily affected by background interference, leading to prominent missed detections and false detections.
A unified pixel coordinate system is established in the original grayscale image. The center of the track is located by grayscale accumulation. The region of interest is extracted and discretely projected at equal intervals within a preset angle range. The residual signal is extracted by quadratic trend fitting. The segmentation threshold and connected component analysis are adaptively determined by combining statistical quantities to realize the location and feature extraction of track defects.
It improves the accuracy and efficiency of track defect detection, reduces computational resource consumption, enhances the adaptability and generalization ability of the algorithm, reduces the false negative rate and false positive rate, and can maintain a stable detection accuracy under different lighting and scenarios.
Smart Images

Figure CN121095148B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of machine vision inspection and intelligent image processing technology, specifically to a machine vision-based intelligent identification method for track defects. Background Technology
[0002] With the rapid development of railway transportation and the rail transit industry, the safety and stability of track lines have become key factors in ensuring transportation efficiency and personnel safety. During long-term operation, track surfaces are susceptible to various factors such as environment, load, and temperature differences, resulting in structural defects such as cracks, peeling, spalling, and gaps. If these defects are not detected and repaired in a timely manner, they can easily lead to the expansion of track damage, thereby threatening operational safety and equipment lifespan.
[0003] Traditional track defect detection primarily relies on manual inspection and simple mechanical flaw detection equipment. Manual inspection is limited by the working environment, subjective experience, and inspection frequency, resulting in significant problems such as high workload, low efficiency, and high missed detection rates. While mechanical flaw detectors improve detection efficiency, they have limited resolution, insufficient sensitivity to specific types of defects (such as slender cracks and tiny notches), and difficulty in achieving large-scale real-time monitoring and automated data processing. In recent years, the rapid development of machine vision and intelligent image processing technologies has provided new possibilities for efficient detection and intelligent identification of track defects. By acquiring track surface images through high-resolution cameras and combining image analysis, feature extraction, and intelligent discrimination algorithms, automatic detection and classification of track surface defects can be achieved, improving detection efficiency and accuracy while reducing human intervention and subjective interference. However, existing machine vision methods mostly rely on edge detection, template matching, or deep learning-based black box models. These methods have shortcomings such as poor adaptability to defect types, limited feature representation, weak interpretability, and strong parameter dependence. In particular, when faced with strip-shaped, thin, low-contrast cracks and notches, they are easily affected by background interference, and the phenomena of missed detection and false detection are still prominent.
[0004] Therefore, this study proposes a machine vision-based intelligent method for track defect recognition. First, a unified pixel coordinate benchmark is constructed on the original grayscale image. The center region of the track is quickly located by accumulating grayscale values line by line, thereby extracting a narrow longitudinal region of interest to reduce irrelevant background. Then, this region is discretized at equal intervals within a preset angle range. By accumulating two-dimensional pixels into a one-dimensional projection sequence and using a quadratic trend fitting method to extract residual signals, the main trend of the track is removed, and the defect response is highlighted. Next, the maximum value of the residuals in each direction is calculated to construct a comprehensive residual image. A segmentation threshold is adaptively determined using statistical measures, and noise regions are removed by combining connected component analysis. Finally, features such as location, length, and intensity are extracted while preserving the candidate defect contour. Summary of the Invention
[0005] This invention provides a machine vision-based intelligent identification method for track defects, which helps to solve the problems mentioned in the background art.
[0006] This invention provides the following technical solution: a machine vision-based intelligent identification method for track defects, comprising:
[0007] In the original grayscale image, a pixel coordinate system with the upper left corner as the origin is established, and a horizontal projection curve is generated by row grayscale accumulation. The center row of the track is located by the row corresponding to the maximum projection value, and the region of interest of the track is extracted by using one-tenth of the image height as half bandwidth.
[0008] Within a preset angle range, the projection direction is discretized at equal intervals. For each discretized angle, pixels within the region of interest are projected onto that direction and mapped to the discretized projection coordinate index.
[0009] For each discrete angle, initialize a gray-level accumulation sequence, and for each pixel in the region of interest, accumulate the corresponding gray-level value to the corresponding sequence position according to its projection index to obtain the projection sequence;
[0010] Based on the necessary statistics calculated for each projection sequence, a quadratic polynomial normal equation is constructed, and the least squares method is used to solve for the fitting coefficients to obtain the fitting curves in each direction.
[0011] Calculate the residual between the original projection value and the fitted curve, generate residual maps in each direction, and construct the maximum residual image by taking the maximum residual value of each pixel in all directions;
[0012] Calculate the mean and standard deviation of the maximum residual image, adaptively determine the binarization threshold based on the statistics, binarize the residual image to generate a defect candidate mask, and if the threshold or mask does not meet the predetermined conditions, it is judged as defect-free and the detection is terminated.
[0013] Initial connected components are extracted from the binary mask based on the four-neighbor rule. The area of each connected component is calculated and the small-area connected components are removed using the average area as a threshold. The remaining connected components are re-labeled. If there are no remaining connected components, the system is judged to be defect-free and the detection is terminated.
[0014] For each final connected region, defect localization and feature extraction are performed sequentially, including bounding box calculation, determining the main direction based on the maximum residual direction and measuring the defect length, calculating the average residual intensity to characterize the defect severity, and mapping the pixel coordinates of the defect region back to the original image coordinate system.
[0015] Optionally, the step of establishing a pixel coordinate system with the upper left corner as the origin in the original grayscale image, generating a horizontal projection curve by accumulating row grayscale values, locating the center row of the track with the row corresponding to the maximum projection value, and using one-tenth of the image height as half-bandwidth to extract the region of interest for the track, specifically includes:
[0016] Set the pixel coordinate system at the top left corner of the original grayscale image, and set the top left corner as the origin. , The horizontal direction of the axis is positive to the right. The vertical axis pointing downwards is positive, and the pixel spacing is uniformly 1.
[0017] Obtain the original grayscale image in pixel coordinates The grayscale value at that location is denoted as ;in, The x-axis of the image, The vertical axis of the image; This represents the number of pixel columns in the original image; The number of pixel rows in the original image;
[0018] Calculate the first The horizontal projection curve is obtained by summing the grayscale values of all pixels in the row.
[0019] ;
[0020] The center row of the track is determined by finding the row containing the maximum value of the horizontal projection:
[0021] ;
[0022] Calculate the crop half-bandwidth, taking one-tenth of the image height: ;
[0023] Determine the vertical extent of the region of interest on the original image based on the orbit center and bandwidth, and denot the region of interest as... : , , ;in, for The starting row index in the original image; for The index of the last row in the original image; for number of rows;
[0024] Within the above range, cropping from the original image Defined as:
[0025] ;in, for The horizontal pixel index within; for Vertical pixel index within; for Area in pixels The grayscale value at that location.
[0026] Optionally, the step of discretizing the projection direction at equal intervals within a preset angle range, projecting pixels within the region of interest onto that direction for each discrete angle, and mapping them to a discretized projection coordinate index, specifically includes:
[0027] Constructing an equally spaced discrete angle set, specifically:
[0028] Set the total number of discretized angles. Calculate the radian interval between two adjacent angles. Then the first Each discrete angle is ;in, For projection direction index;
[0029] For each discrete angle, calculate Projected coordinates of each pixel within:
[0030] ;in, for Pixels Along direction The projected coordinates; Rounded to the nearest integer;
[0031] For each angle Determine the minimum and maximum values of the projected coordinates, and calculate the total number of projected coordinates for each direction: , , ;in, For direction Minimum value of all projected coordinates; For direction Maximum value of all projected coordinates; For direction Total number of upward projection coordinates;
[0032] Re-index and recalibrate the projected coordinates in each direction:
[0033] ;in, For projection sequence index; To map consecutive integers to the first integer within the projected coordinate range Each actual coordinate value.
[0034] Optionally, the step of initializing a grayscale accumulation sequence for each discrete angle and accumulating the corresponding grayscale value of each pixel in the region of interest to the corresponding sequence position according to its projection index to obtain a projection sequence specifically includes:
[0035] For each direction, initialize the projection accumulation sequence: ;in, For direction Lower projection coordinates The sum of grayscale values on the screen is initialized to 0.
[0036] right For each pixel and each angle of the region, steps S301 to S302 are executed sequentially:
[0037] S301, Calculate the index of the pixel in the projection direction: ;in, For pixels Along direction The index of the cumulative sequence corresponding to the projection;
[0038] S302, Perform projection accumulation: .
[0039] Optionally, the step of calculating necessary statistics based on each projection sequence, constructing a quadratic polynomial normal equation, and solving for the fitting coefficients using the least squares method to obtain fitting curves in each direction specifically includes:
[0040] For each projection direction, the following statistical moments are calculated:
[0041] , , , , ; , , ;in, For direction Total number of projection points; For direction The sum of all projected coordinate values; For direction Sum of squares of projected coordinates; For direction Sum of the cubes of the projected coordinates; For direction Fourth power sum of projected coordinates; For direction The cumulative grayscale value of all projected points; For direction Projected coordinates and grayscale product sum; For direction Sum of squared projected coordinates and grayscale product;
[0042] For each direction, define the master determinant and the Cramer substitution determinant:
[0043] , , , ;in, For direction The principal determinant of the normal equation for second-order polynomial fitting; For direction The first Column replacement The resulting determinant, Replace the column number;
[0044] Set branch indicator variable :
[0045] like or Then let And for all Assignment ;in, A value of 1 indicates that the fitting is skipped, and a value of 1 indicates normal fitting. For direction Projected coordinates The residual;
[0046] Otherwise, let ;
[0047] when Then, Cramer's rule is used to solve for the fitting coefficients, and a second-order fitting curve is constructed: , ;in, , and To fit the polynomial coefficients, corresponding to constants, first-order and second-order terms; For direction No. The second-order fitted values for each projection position.
[0048] Optionally, the step of calculating the residual between the original projection value and the fitted curve, generating residual maps in each direction, and constructing a maximum residual image by taking the maximum residual value of each pixel in all directions, specifically includes:
[0049] Construct the residual sequence for each direction: ;
[0050] Calculate the residual function for each pixel in each direction:
[0051] ;in, for Pixels Along direction The residual value;
[0052] Construct the maximum residual image for each pixel: ;in, for Pixels Maximum residual value in all directions.
[0053] Optionally, the step of calculating the mean and standard deviation of the maximum residual image, adaptively determining a binarization threshold based on statistics, binarizing the residual image to generate a defect candidate mask, and determining that there is no defect and terminating the detection if the threshold or mask does not meet a predetermined condition, specifically includes:
[0054] Calculate the mean of the residual plot. and standard deviation :
[0055] , ;
[0056] like and If no defect is found, the output "No defects found" is displayed, and the detection process ends.
[0057] Calculate the segmentation threshold This generates a binary mask:
[0058] ;in, for Pixels Binarization mask, Indicates possible defect areas;
[0059] If all If the result is negative, the output will be "No defects found" and the detection process will end.
[0060] Optionally, the step of extracting initial connected components based on the four-neighbor rule on the binary mask, calculating the area of each connected component and using the average area as a threshold to remove small-area connected components, re-labeling the remaining connected components, and determining that there are no defects and terminating the detection if there are no remaining connected components, specifically includes:
[0061] right The region is used to extract the initial connected component based on the four-neighbor rule. ;in, For connected component indexes; For the first The set of pixels contained in a connected component; Total number of connected components;
[0062] The four-neighbor region specifically refers to any pixel. Its four neighboring regions are ,and Only retain those that meet the requirements. , point;
[0063] If there are no connected components, that is If no defect is found, the output "No defects found" is displayed, and the detection process ends.
[0064] Calculate the area of each connected component, and then calculate the mean area and the area threshold:
[0065] , , ;in, For the first The number of pixels in each connected component; This is the average area of all connected components; Area threshold;
[0066] Remove all areas smaller than The connected components, and the corresponding pixels in Centered at 0;
[0067] For the remainder The background region is then further extracted using the four-neighbor rule. If its area is smaller than [the specified area], the connected components are considered. If the value is 1, then the corresponding area is set as the foreground pixel.
[0068] Extract the final connected component set again from the four-neighbors on the updated binary graph. ;in, For the final connected component index; This represents the final number of connected components; For the first One final connected component;
[0069] like If the result is negative, the output will be "No defects found" and the detection process will end.
[0070] Optionally, the defect localization and feature extraction are performed sequentially for each final connected component, including bounding box calculation, determining the principal direction based on the maximum residual direction and measuring the defect length, calculating the average residual intensity to characterize the defect severity, and mapping the pixel coordinates of the defect region back to the original image coordinate system, specifically including:
[0071] For each final connected component Steps S801 to S806 are executed sequentially:
[0072] S801. Calculate the bounding box of the connected components:
[0073] , ;in, For connected components The minimum horizontal pixel index; For connected components Maximum horizontal pixel index;
[0074] , ; For connected components The minimum vertical pixel index; For connected components Maximum vertical pixel index;
[0075] S802, for each pixel Calculate the index of the maximum residual direction and count the frequency of the principal direction: ; , ;in, Index of the main residual direction; For connected components Inward direction The frequency of pixel occurrence; The index of the most frequent main direction;
[0076] S803. Calculate the defect's main direction angle from the main direction index: ;in, For the first The radian of the domain principal direction;
[0077] S804. Calculate the defect length:
[0078] ;in, For connected components The projection length along the main direction is a combination of the horizontal and vertical projection lengths and the main direction component.
[0079] S805. Calculate the average residual intensity within the connected domain as an indicator of defect severity:
[0080] ;in, For connected components Internal mean maximum residual; For connected components Total number of pixels;
[0081] S806. Map the pixel coordinates of the connected components back to the original image coordinate system:
[0082] , ;in, For connected components Each pixel within the image is restored to the original image's coordinate system.
[0083] The present invention has the following beneficial effects:
[0084] 1. By defining the top-left corner of the image as the origin and establishing a pixel coordinate system using unified horizontal and vertical units, a unified spatial reference is provided for all subsequent pixel-level calculations, avoiding the cumulative errors caused by multiple coordinate transformations. Compared to traditional algorithms that directly slide a window across the entire image or perform a global search, this method generates a horizontal projection curve by accumulating grayscale values row by row, quickly locating the center position of the track. It then dynamically crops an adaptive narrowband region according to the image height, effectively eliminating irrelevant background and reducing redundant pixel processing. This approach not only reduces computational resource consumption and improves processing speed but also avoids false detections in non-track areas, ensuring stable detection accuracy under different lighting conditions and scenarios. Furthermore, dynamic half-bandwidth cropping can accommodate both the track itself and potential abnormal areas on both sides, resolving the contradiction between completeness and accuracy that is difficult to achieve with a fixed window size, thus improving the algorithm's adaptability and generalization ability.
[0085] 2. Within a preset angle range, projection directions are divided at equal intervals. For each discrete angle, pixels within the region of interest are mapped to their corresponding one-dimensional coordinate indices, thus establishing the foundation for multi-directional projection. This expands the traditional approach of focusing only on horizontal or vertical projection to multi-angle discrete processing, enabling comprehensive capture of projection features from oblique, tilted, and slender defects. During the mapping process, index recalibration ensures that projection values do not exceed limits, enhancing the algorithm's robustness. Compared to existing methods that only use two fixed directions or are based on filter templates for detection, this strategy improves the response capability to defects of various shapes and effectively reduces the false negative rate. Furthermore, multi-angle mapping can reveal richer anomalous signals in subsequent residual analysis, laying a solid foundation for accurate segmentation and feature extraction. This multi-directional projection mapping approach leverages the advantages of multi-directional information from light field imaging while avoiding the complexity of high-dimensional data processing, balancing accuracy and efficiency.
[0086] 3. For each projection direction, this scheme initializes a one-dimensional gray-level accumulation sequence and sequentially accumulates gray-level values for all pixels within the region of interest according to their projection indices, obtaining a projection sequence. This orderly aggregation of scattered two-dimensional pixel information into a one-dimensional sequence achieves efficient spatial information compression. Compared to traditional region accumulation based on local sliding windows or convolution kernels, this method simplifies the data structure and computational process while ensuring information integrity, reducing computational complexity. Furthermore, since all pixels participate in the accumulation, this method can completely preserve the gray-level distribution characteristics of the orbital body and anomalous signals, providing high-quality input for subsequent residual extraction based on trend fitting. Compared to existing coarse pixel sampling or random sampling strategies, this scheme's voxel-wide coverage accumulation ensures sensitivity to small or locally subtle defects, effectively improving detection accuracy and reliability.
[0087] 4. For each projection sequence, necessary statistics are calculated, a second-order polynomial normal equation is constructed, and the least squares method is used to solve for the fitting coefficients, thereby obtaining a smooth trend curve for each direction. Quadratic trend fitting removes the main trend of the track structure, replacing traditional simple averaging or median filtering with a stable curve, which more accurately describes the continuous curve changes on the track surface. Furthermore, when the fitting conditions do not meet stability requirements, the direction is adaptively skipped, ensuring numerical stability and robustness. Compared with common defect detection methods based on linear fitting or moving averages, quadratic fitting better matches the true shape of the track surface, improving the significance of the difference between anomalies and the background. This reduces sensitivity to high-frequency noise and enhances the response to defects at curvature changes, providing a more accurate baseline for subsequent residual highlighting.
[0088] 5. After removing the main trend curve, this scheme calculates the residual in each direction and retains the maximum residual value for each pixel in all directions, synthesizing a comprehensive residual image. The "residual maximization" approach can centrally present the strongest response of the projection of defects in each direction in a unified image, comprehensively capturing abnormal signals of various shapes such as thinness and tilt. Compared with the traditional method of only retaining the residual in a single direction or the average residual, the maximum residual image is more representative, avoiding missed detections due to insufficient response in a certain direction, and is not weakened by noise directions. At the same time, this method does not require complex fusion calculations of residuals in all directions, and only requires a single pixel-level comparison to achieve fusion, resulting in high computational efficiency. The introduction of the comprehensive residual image provides a strong signal source for subsequent adaptive segmentation, improving the sensitivity and accuracy of defect detection.
[0089] 6. Based on the comprehensive residual image, this scheme autonomously determines the binarization segmentation threshold by calculating the mean and standard deviation of the entire image, thereby generating candidate masks for abnormal regions. This avoids empirical thresholds or manual parameter tuning, and adaptively sets the segmentation threshold through statistical measures, automatically correcting segmentation sensitivity for different acquisition conditions and illumination changes. Compared with existing fixed threshold or predefined multi-threshold strategies, this adaptive segmentation method reduces human intervention and improves the algorithm's portability and generalization ability. Simultaneously, when all residual responses are zero or the candidate regions are too few, it can quickly determine the absence of defects and terminate the process, saving subsequent computation time. The introduction of this method effectively solves the problem of difficulty in uniformly selecting thresholds under different scenarios, enabling the system to maintain high recall and low false alarms under various operating conditions.
[0090] 7. In binary masking, this scheme uses the four-neighborhood rule to extract connected components and calculate their respective areas. Small-area noise is eliminated using the average area of the connected components as a filtering threshold, and the remaining regions are then relabeled to ensure that only potential real defect candidates are retained. Introducing a dynamic average area threshold instead of a fixed area threshold adapts to different image sizes and defect scales, effectively filtering out random noise and isolated pixels. Compared to common noise removal methods based on morphological dilation and erosion, connected component analysis is more sensitive to shape and structure, preserving the complete morphology of real defects, and its processing flow is simple and intuitive. Furthermore, multiple extraction and relabeling operations eliminate noise islands, ensuring the spatial integrity of the final connected components and laying a reliable foundation for subsequent accurate localization and feature extraction.
[0091] 8. For each final connected component, this scheme calculates its minimum bounding rectangle and statistically analyzes the principal direction indices to obtain the defect principal axis angle. Based on this, the physical dimensions are estimated through the projected length of the principal direction, enabling quantitative measurement of the defect length. Combining connected component analysis with residual direction information allows for localization beyond simple bounding boxes, identifying the true direction and length of the defect. Unlike methods using only the minimum bounding rectangle or the maximum inscribed circle, this scheme relies on multi-directional residual signal statistics to ensure a high degree of consistency between the measurement direction and the defect morphology. Furthermore, by restoring the pixel coordinates to the original image coordinate system, the detection results can be seamlessly overlaid onto the original image, enabling on-site visual annotation and facilitating subsequent maintenance, localization, and result interaction. Attached Figure Description
[0092] Figure 1 This is a schematic diagram of the process of the present invention. Detailed Implementation
[0093] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0094] Example, refer to Figure 1 A machine vision-based intelligent identification method for track defects includes:
[0095] In the original grayscale image, a pixel coordinate system with the upper left corner as the origin is established, and a horizontal projection curve is generated by row grayscale accumulation. The center row of the track is located by the row corresponding to the maximum projection value, and the region of interest of the track is extracted by using one-tenth of the image height as half bandwidth.
[0096] Within a preset angle range, the projection direction is discretized at equal intervals. For each discretized angle, pixels within the region of interest are projected onto that direction and mapped to the discretized projection coordinate index.
[0097] For each discrete angle, initialize a gray-level accumulation sequence, and for each pixel in the region of interest, accumulate the corresponding gray-level value to the corresponding sequence position according to its projection index to obtain the projection sequence;
[0098] Based on the necessary statistics calculated for each projection sequence, a quadratic polynomial normal equation is constructed, and the least squares method is used to solve for the fitting coefficients to obtain the fitting curves in each direction.
[0099] Calculate the residual between the original projection value and the fitted curve, generate residual maps in each direction, and construct the maximum residual image by taking the maximum residual value of each pixel in all directions;
[0100] Calculate the mean and standard deviation of the maximum residual image, adaptively determine the binarization threshold based on the statistics, binarize the residual image to generate a defect candidate mask, and if the threshold or mask does not meet the predetermined conditions, it is judged as defect-free and the detection is terminated.
[0101] Initial connected components are extracted from the binary mask based on the four-neighbor rule. The area of each connected component is calculated and the small-area connected components are removed using the average area as a threshold. The remaining connected components are re-labeled. If there are no remaining connected components, the system is judged to be defect-free and the detection is terminated.
[0102] For each final connected region, defect localization and feature extraction are performed sequentially, including bounding box calculation, determining the main direction based on the maximum residual direction and measuring the defect length, calculating the average residual intensity to characterize the defect severity, and mapping the pixel coordinates of the defect region back to the original image coordinate system.
[0103] Intelligent identification of track defects is achieved through a multi-stage pipeline workflow from image preprocessing to defect feature extraction. First, a unified spatial reference with the top-left corner as the origin is established in the original grayscale image. Then, the track center is quickly located based on row grayscale accumulation, and a narrow region of interest is dynamically extracted. This solves the problems of severe background noise and large redundant computational load caused by traditional full-image processing, reducing subsequent computational overhead and improving positioning accuracy. Next, by projecting the region at equal intervals within a preset angle range and mapping all pixels to the corresponding one-dimensional projection sequence, defects such as tilting and slender defects are missed by single horizontal or vertical projections, providing a more comprehensive response signal for various types of track damage. Subsequently, a secondary trend fitting is performed on each projection sequence, and the residual between the original projection and the fitted curve is calculated. Finally, the maximum residual value is taken in all directions to construct a comprehensive residual image, solving the problem of difficulty in separating the main trend of the background surface from the defect texture, enhancing the contrast between the defect signal and the background, and suppressing high-frequency noise. Adaptive generation of binary thresholds based on global statistics of residual images to segment candidate masks. Early termination occurs if no valid response is found, avoiding the instability of fixed thresholds under different lighting and acquisition conditions, thus improving the algorithm's robustness and portability. Four-neighbor connected component extraction is applied to the binary mask, and noise mini-domains are eliminated using the average area as a dynamic threshold. This solves the problem of isolated noise islands being easily mistaken for defects, preserving the complete shape of the true connected regions and further reducing false alarms. Finally, bounding box calculation, main direction identification, length measurement, severity quantification, and coordinate recovery are performed on each remaining connected component. This addresses the limitation of traditional methods that rely solely on rectangular boundaries to express defect direction and severity, providing accurate quantitative and visual indicators for subsequent risk assessment and maintenance decisions.
[0104] The process of establishing a pixel coordinate system with the top left corner as the origin in the original grayscale image, generating a horizontal projection curve through row grayscale accumulation, locating the center row of the track with the row corresponding to the maximum projection value, and using one-tenth of the image height as half bandwidth to extract the region of interest for the track, specifically includes:
[0105] Set the pixel coordinate system at the top left corner of the original grayscale image, and set the top left corner as the origin. , The horizontal direction of the axis is positive to the right. The vertical axis is positive when it points downwards, and the pixel spacing is uniformly 1; a unified spatial reference is established for all pixel-related calculations, which facilitates subsequent pixel positioning, region extraction and full-process coordinate mapping;
[0106] Obtain the original grayscale image in pixel coordinates The grayscale value at that location is denoted as ;in, The x-axis of the image, The vertical axis of the image; This represents the number of pixel columns in the original image; This represents the number of pixel rows in the original image; it provides the original data source required for all subsequent calculations, ensuring the traceability and accuracy of the entire image processing process.
[0107] Calculate the first The horizontal projection curve is obtained by summing the grayscale values of all pixels in the row.
[0108] By summing the pixel grayscale values of each row, the brightness characteristics of the track are highlighted on a one-dimensional curve, which helps to quickly determine the longitudinal center position of the track.
[0109] The center row of the track is determined by finding the row containing the maximum value of the horizontal projection:
[0110] Determine the center of the track's most prominent vertical position in the image to provide a benchmark for subsequent ROI region cropping, thereby improving the targeting and accuracy of subsequent steps;
[0111] Calculate the crop half-bandwidth, taking one-tenth of the image height: Dynamically determine the vertical expansion range of the region of interest, balancing the relationship between including all orbits and surrounding information and removing irrelevant regions;
[0112] Determine the vertical extent of the region of interest on the original image based on the orbit center and bandwidth, and denot the region of interest as... : , , ;in, for The starting row index in the original image; for The index of the last row in the original image; for The number of rows; ensure The area does not cross the boundary and fully covers the main body of the track and any potential defects on both sides, improving the accuracy of subsequent identification;
[0113] Within the above range, cropping from the original image Defined as:
[0114] ;in, for The horizontal pixel index within; for Vertical pixel index within; for Area in pixels The grayscale value at the location is used to retain only the data of the key track area in all subsequent projection, segmentation and other processing steps, thereby improving the algorithm's running efficiency and detection accuracy.
[0115] Focusing on the establishment of the pixel coordinate system and the dynamic cropping of the region of interest, this method achieves efficient and accurate preprocessing through the following steps: First, a coordinate origin is set at the top left corner of the original grayscale image, unifying the horizontal rightward and vertical downward coordinate directions and using pixels as the basic unit. This provides a traceable benchmark for all subsequent spatial positioning and mapping operations, solving the problems of multiple transformation errors and cumulative drift caused by inconsistent coordinate definitions in traditional algorithms. Second, based on this coordinate system, the grayscale values of each row are accumulated to generate a horizontal projection curve. The peak value of the curve is used to quickly determine the vertical center position of the track in the image, avoiding the drawbacks of sliding window or template matching, which are sensitive to background noise and have a large computational load, thus improving the speed and accuracy of center row positioning. Subsequently, the half-bandwidth is dynamically calculated based on the image height, and a narrow-band region of interest is cropped. This ensures complete coverage of the main track and its surrounding potentially defective areas while eliminating irrelevant pixels far from the main track. This solves the problem of fixed window cropping, which struggles to balance completeness and efficiency, reduces redundant calculations, and lowers the risk of false detections. The entire preprocessing process is completed under the same coordinate reference, which improves the traceability and consistency of the data source, provides high-quality input data for subsequent multi-angle projection and residual analysis, and improves the system's adaptability and stability in different scenarios and different orbital states.
[0116] The step of discretizing the projection direction at equal intervals within a preset angle range, projecting pixels within the region of interest onto that direction for each discrete angle, and mapping them to a discretized projection coordinate index, specifically includes:
[0117] Constructing an equally spaced discrete angle set, specifically:
[0118] Set the total number of discretized angles. Calculate the radian interval between two adjacent angles. Then the first Each discrete angle is ;in, It provides an index for projection direction and a high-precision multi-angle detection basis, ensuring that slender defects in different orientations can be effectively mapped and highlighted.
[0119] For each discrete angle, calculate Projected coordinates of each pixel within:
[0120] ;in, for Pixels Along direction The projected coordinates; Rounding to the nearest integer; accurately mapping two-dimensional pixels to a one-dimensional projection space, establishing a basic index relationship for subsequent projection accumulation and sequence processing;
[0121] For each angle Determine the minimum and maximum values of the projected coordinates, and calculate the total number of projected coordinates for each direction: , , ;in, For direction Minimum value of all projected coordinates; For direction Maximum value of all projected coordinates; For direction The total number of projection coordinates; determine how much projection accumulation storage space needs to be allocated in each direction to ensure that all projection indices do not go out of bounds during subsequent accumulation;
[0122] Re-index and recalibrate the projected coordinates in each direction:
[0123] ;in, For projection sequence index; To map consecutive integers to the first integer within the projected coordinate range Each actual coordinate value is used to establish a one-to-one correspondence between the projected coordinates and the accumulated sequence, which facilitates efficient grayscale accumulation and array access in the future.
[0124] An innovative solution for discrete angular projection and coordinate mapping is proposed, achieving comprehensive coverage of various defect directions through the following steps: First, multiple projection directions are selected at equal intervals within a preset angular range, balancing angular accuracy and computational complexity. Then, for each discrete angle, the minimum and maximum values of the projected coordinates of all pixels within the region of interest in that direction are statistically analyzed, and the storage space for the accumulation sequence is dynamically allocated, avoiding index out-of-bounds errors and memory waste, and ensuring the integrity of the projection data in each direction during subsequent accumulation and residual calculation. Next, the projected coordinates of each pixel are recalibrated to a continuous index range, achieving a one-to-one correspondence in the mapping relationship, avoiding interference caused by data gaps or overlaps, and completely preserving the grayscale distribution information of slender and tilted defects in all directions. This solves the problem of missed detection or insufficient response when dealing with complex-shaped defects using only horizontal or vertical projection, improves the detection coverage of damage in any orientation, and provides reliable basic data for subsequent multi-directional residual fusion. This mapping process relies only on simple index operations, without additional geometric transformations or high-dimensional filtering, ensuring the efficiency and real-time performance of the algorithm.
[0125] The process of initializing a gray-level accumulation sequence for each discrete angle and accumulating the corresponding gray-level value of each pixel within the region of interest to the corresponding sequence position based on its projection index to obtain a projection sequence specifically includes:
[0126] For each direction, initialize the projection accumulation sequence: ;in, For direction Lower projection coordinates The grayscale values are accumulated and summed, with an initial value of 0; storage space for the accumulated sum is reserved for each projection direction to avoid undefined variables in subsequent operations and improve the robustness of the algorithm;
[0127] right For each pixel and each angle of the region, steps S301 to S302 are executed sequentially:
[0128] S301, Calculate the index of the pixel in the projection direction: ;in, For pixels Along direction The index of the cumulative sequence corresponding to the projection;
[0129] S302, Perform projection accumulation: ;
[0130] Will Pixels are grouped and accumulated according to their projection positions in each direction, realizing two-dimensional to one-dimensional mapping and aggregation, which facilitates subsequent curve analysis.
[0131] In the projection sequence construction stage, efficient compression from 2D pixels to a 1D sequence is achieved. The following steps ensure both information integrity and computational efficiency: First, a zero-value accumulation array precisely corresponding to the projection coordinates is initialized for each discrete direction, with pre-allocated storage space to resolve performance fluctuations and memory fragmentation issues caused by dynamic expansion. Next, all pixels in the region of interest are traversed, and accumulation is performed based on their mapping index in each direction, completely converging grayscale values into a 1D sequence. This avoids signal loss that may occur with window-based or sampling strategies, and provides high sensitivity for detecting minute cracks and low-contrast details. The entire accumulation process relies only on array indexing and addition operations, resulting in low computational complexity and easy parallelization, meeting the requirements of real-time detection and improving system throughput and scalability. Compared to traditional sliding window, convolutional filtering, or random sampling techniques, this scheme simplifies the data structure and computational process while ensuring information integrity, providing high-quality 1D input data for subsequent trend fitting and residual analysis.
[0132] The process involves calculating necessary statistics based on each projection sequence, constructing a quadratic polynomial normal equation, and using the least squares method to solve for the fitting coefficients to obtain fitting curves in each direction. Specifically, this includes:
[0133] For each projection direction, the following statistical moments are calculated:
[0134] , , , , ; , , ;in, For direction Total number of projection points; For direction The sum of all projected coordinate values; For direction Sum of squares of projected coordinates; For direction Sum of the cubes of the projected coordinates; For direction Fourth power sum of projected coordinates; For direction The cumulative grayscale value of all projected points; For direction Projected coordinates and grayscale product sum; For direction The sum of the squared projected coordinates and the gray product provides the coefficients of matrices of each order and the target vector for the normal equation of the least squares method, thus providing a theoretical basis for efficient fitting.
[0135] For each direction, define the master determinant and the Cramer substitution determinant:
[0136] , , , ;in, For direction The principal determinant of the normal equation for second-order polynomial fitting; For direction The first Column replacement The resulting determinant, Replace column numbers; determine whether the fitting problem is solvable, and provide the necessary determinant denominator for subsequent coefficient calculation;
[0137] Set branch indicator variable :
[0138] like or Then let And for all Assignment ;in, A value of 1 indicates that the fitting is skipped, and a value of 1 indicates normal fitting. For direction Projected coordinates The residuals; automatically skipping unfit data segments to ensure numerical stability and prevent the introduction of meaningless noise;
[0139] Otherwise, let ;
[0140] when Then, Cramer's rule is used to solve for the fitting coefficients, and a second-order fitting curve is constructed: , ;in, , and To fit the polynomial coefficients, corresponding to constants, first-order and second-order terms; For direction No. The second-order fitted values of each projection position are obtained; a smooth curve model is performed for each projection sequence to effectively separate the main trend of the track structure from defects and anomalies, providing a baseline for subsequent residual analysis.
[0141] A trend modeling method based on quadratic polynomial least squares fitting is proposed, achieving accurate removal of the main trend of the track through the following steps: First, higher-order moments are calculated based on the projected coordinates and accumulated gray values to construct an accurate coefficient matrix for the normal equation; then, the least squares method is used to solve the quadratic fitting curve, which approximates the main trend of the track with a smooth surface; subsequently, point-by-point residual calculation is performed on the original projection and the fitting result, retaining only the anomalous response portion. This step solves the problem of insufficient fitting accuracy of traditional average filtering or linear approximation under complex surface morphology, improves the accuracy of background trend removal, and ensures that the residual signal mainly reflects defect information while suppressing high-frequency noise. The scheme also incorporates numerical stability detection during the fitting process, automatically skipping anomalous data directions to avoid fitting failure or outlier contamination, maintaining the robustness and stability of the algorithm. Compared with existing simple difference or multi-level filtering methods, the quadratic fitting of this scheme better fits the true surface characteristics of the track, providing a high-quality baseline for subsequent multi-directional residual maximization fusion and improving detection accuracy.
[0142] The calculation of the residual between the original projection value and the fitted curve, generating residual maps in each direction, and constructing a maximum residual image by taking the maximum residual value of each pixel in all directions, specifically includes:
[0143] Construct the residual sequence for each direction: Extract the portion of the projected signal that could not be fitted by the quadratic trend, highlighting the abnormal energy caused by the defect;
[0144] Calculate the residual function for each pixel in each direction:
[0145] ;in, for Pixels Along direction The residual value; each pixel retains only the positive abnormal response, effectively suppressing the negative fluctuations caused by noise and shadows, ensuring that subsequent identification focuses on suspected defects;
[0146] Construct the maximum residual image for each pixel: ;in, for Pixels Maximum residual value in all directions; each pixel uses the outlier with the strongest response in all directions as a feature to preserve defect information to the greatest extent and improve the response capability of strip-shaped and tilted defects.
[0147] A maximum residual reconstruction strategy is introduced in the residual fusion stage. This strategy highlights the most significant defect response through the following steps: First, the residual sequence is calculated in each discrete direction, retaining only positive anomalous responses to suppress negative fluctuations. Then, the residual values at corresponding pixel positions in all directions are compared at the pixel level, and the maximum value is retained to construct a comprehensive residual image. This step solves the problem of weakened defect signals caused by traditional methods that only retain a single direction or average fusion, focusing on reflecting the strongest defect responses in each direction and achieving comprehensive capture of tilted, elongated, and nonlinear energy defects. Simultaneously, this fusion requires only simple comparison operations, has low computational cost, and is easily parallelized, meeting real-time requirements. Compared with existing average residual or multi-channel weighted fusion methods, this scheme avoids background noise interference in the responses of a few directions, simplifies parameter setting, and improves the signal-to-noise ratio, providing clear and high-contrast input for subsequent adaptive segmentation.
[0148] The process involves calculating the mean and standard deviation of the maximum residual image, adaptively determining a binarization threshold based on statistics, binarizing the residual image to generate a defect candidate mask, and determining that there is no defect and terminating the detection if the threshold or mask does not meet predetermined conditions. Specifically, this includes:
[0149] Calculate the mean of the residual plot. and standard deviation :
[0150] , ; Calculate the overall distribution level of the residual response to adaptively adjust the segmentation threshold and automatically adapt to changes in different images and acquisition conditions;
[0151] like and If the result is zero, the output will be "no defects" and the detection will end; this efficiently removes invalid images where all pixel responses are zero, avoiding unnecessary computation and false alarms.
[0152] Calculate the segmentation threshold This generates a binary mask:
[0153] ;in, for Pixels Binarization mask, It indicates possible defect areas; it automatically selects abnormal areas above the average level based on the response distribution to capture potential defect signals to the maximum extent and generate candidate masks;
[0154] If all If no defects are detected, the output is "no defects" and the detection ends; this further eliminates the possibility of not detecting any abnormal areas, preventing false detections and wasted processes.
[0155] A statistically driven adaptive thresholding strategy is proposed for the binarization segmentation stage. The robustness of segmentation is ensured through the following steps: First, the global mean and standard deviation of the composite residual image are statistically analyzed, and the segmentation threshold is automatically calculated using their ratio or a fixed coefficient. Then, the residual image is compared with this threshold to generate candidate masks. When all residuals in the image are zero or there are no valid regions in the mask, a defect-free condition is immediately determined, and detection is terminated. This step solves the problem of fixed thresholds being inapplicable under different lighting, noise levels, and track surface conditions. The algorithm can automatically adjust the detection sensitivity according to the actual residual distribution, capturing most potential defects while eliminating most noise interference. This strategy requires no manual parameter fine-tuning and can run stably in multiple scenarios, achieving truly unattended and rapid segmentation. Compared with existing methods that rely on empirical thresholds or scene presets, this solution improves portability, reduces the false alarm rate, and eliminates invalid images in the early stages, saving subsequent computational resources.
[0156] The process of extracting initial connected components based on the four-neighbor rule on a binary mask, calculating the area of each connected component, using the average area as a threshold to remove small-area connected components, re-labeling the remaining connected components, and determining that there are no defects and terminating the detection if no remaining connected components remain, specifically includes:
[0157] right The region is used to extract the initial connected component based on the four-neighbor rule. ;in, For connected component indexes; For the first The set of pixels contained in a connected component; Total number of connected components; group the segmentation results according to spatial relationships to prepare for subsequent area statistics and noise removal;
[0158] The four-neighbor region specifically refers to any pixel. Its four neighboring regions are ,and Only retain those that meet the requirements. , Points; spatial connectivity criteria that limit candidate regions, facilitating structured analysis and suppressing noisy isolated points;
[0159] If there are no connected components, that is If no defect is found, the output "No defects found" is displayed, and the detection process ends; this avoids invalid data from entering subsequent calculations and saves resources.
[0160] Calculate the area of each connected component, and then calculate the mean area and the area threshold:
[0161] , , ;in, For the first The number of pixels in each connected component; This is the average area of all connected components; The area threshold is used to filter out noise domains that are extremely small and randomly occurring based on statistical laws, thereby improving detection robustness.
[0162] Remove all areas smaller than The connected components, and the corresponding pixels in Centered at 0; further purify the candidate area to ensure that only potentially real defect areas are retained;
[0163] For the remainder The background region is then further extracted using the four-neighbor rule. If its area is smaller than [the specified area], the connected components are considered. If the corresponding area is set as a foreground pixel, that is, assigned a value of 1; this eliminates small background islands that may appear after noise removal, ensuring the integrity of connected components and physical interpretability.
[0164] Extract the final connected component set again from the four-neighbors on the updated binary graph. ;in, For the final connected component index; This represents the final number of connected components; For the first One final connected region; obtain the final defect candidate region to be discriminated and for feature extraction;
[0165] like If no defects are found, the test will end; exit the test promptly when there are no abnormal areas after purification to prevent false detections.
[0166] In the post-processing stage, a dynamic noise removal process based on connected component analysis is introduced. This process ensures the spatial integrity of candidate regions through the following steps: First, all initial connected components are extracted from the binary mask according to the four-neighbor rule, and the pixel area of each connected component is calculated. Then, the average area of all connected components is used as a dynamic threshold to remove isolated noise smaller than this threshold, and the corresponding mask is reset. Next, secondary connected component extraction and relabeling are performed on the remaining regions to eliminate potential small background islands, resulting in a final cleaned connected component set. This step solves the problem of inconsistent performance of traditional morphological opening and closing operations under multi-scale defects and images of different resolutions. It adaptively removes random noise points while preserving the complete shape of real defects, reducing the probability of false detection. The dynamic threshold and multi-round relabeling method can be executed automatically without manual intervention, improving the robustness and versatility of the algorithm. Compared with relying solely on fixed area filtering or single morphological processing, this scheme better balances noise removal and region integrity, providing a more reliable regional basis for subsequent localization and feature quantization.
[0167] The process of sequentially performing defect localization and feature extraction for each final connected component includes bounding box calculation, determining the principal direction based on the maximum residual direction and measuring the defect length, calculating the average residual intensity to characterize the defect severity, and mapping the pixel coordinates of the defect region back to the original image coordinate system. Specifically, this includes:
[0168] For each final connected component Steps S801 to S806 are executed sequentially:
[0169] S801. Calculate the bounding box of the connected components:
[0170] , ;in, For connected components The minimum horizontal pixel index; For connected components Maximum horizontal pixel index;
[0171] , ; For connected components The minimum vertical pixel index; For connected components Maximum vertical pixel index;
[0172] Determine each defect area in The coverage area is used for subsequent quantitative analysis and visualization.
[0173] S802, for each pixel Calculate the index of the maximum residual direction and count the frequency of the principal direction: ; , ;in, Index of the main residual direction; For connected components Inward direction The frequency of pixel occurrence; The index of the most frequent main direction;
[0174] The most prominent main direction in each region is statistically analyzed to provide a basis for defect trajectory identification and nature analysis.
[0175] S803. Calculate the defect's main direction angle from the main direction index: ;in, For the first The radian of the principal direction of the domain; obtaining the principal axis angle of the defect, which facilitates the physical interpretation of the defect properties in practical engineering applications;
[0176] S804. Calculate the defect length:
[0177] ;in, For connected components The projected length along the main direction is combined with the horizontal and vertical projected lengths and the main direction component; the physical length of the defect along the main direction is quantified, providing an intuitive indicator for risk assessment and maintenance decisions;
[0178] S805. Calculate the average residual intensity within the connected domain as an indicator of defect severity:
[0179] ;in, For connected components Internal mean maximum residual; For connected components Total number of pixels; the average maximum residual reflects the intensity of the defect prominence, providing data support for defect prioritization and maintenance strategy classification;
[0180] S806. Map the pixel coordinates of the connected components back to the original image coordinate system:
[0181] , ;in, For connected components Each pixel within the image is restored to the original image coordinate system; achieving the goal of... Accurate mapping from coordinates to original map coordinates facilitates subsequent result annotation, on-site positioning, and data interaction.
[0182] This paper proposes a method for quantifying and extracting multi-dimensional defect information from the final connected components. The method provides precise visualization metrics through the following steps: First, the minimum bounding rectangle is calculated for each connected component to obtain its horizontal and vertical boundary ranges. Then, based on the comprehensive residual image, the maximum response direction of each pixel is statistically analyzed, and the direction frequency is summarized to determine the defect's principal axis orientation. Next, the connected component point set is projected along the principal axis direction, and the longest projected view length is measured to obtain the defect length. Simultaneously, the average of all maximum residual values within the region is calculated and used as a defect severity indicator. Finally, the local coordinates of each pixel within the connected component are mapped back to the original image coordinate system, achieving seamless fusion of the detection results and the original image. This method solves the problem that traditional methods using only bounding boxes or areas cannot reflect defect direction and severity. It provides track maintenance with length data with directional attributes and quantified severity based on residual intensity, and achieves visual annotation through coordinate mapping, facilitating rapid location and decision-making by maintenance personnel. Compared with existing methods that only provide contour or area indicators, this solution achieves comprehensive quantification in three dimensions: direction, size, and intensity, providing a more intuitive and comparable digital reference for risk ranking and subsequent processing strategy formulation.
[0183] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.
[0184] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the technical principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A machine vision-based intelligent identification method for track defects, characterized in that, include: In the original grayscale image, a pixel coordinate system with the upper left corner as the origin is established, and a horizontal projection curve is generated by row grayscale accumulation. The center row of the track is located by the row corresponding to the maximum projection value, and the region of interest of the track is extracted by using one-tenth of the image height as half bandwidth. Within a preset angle range, the projection direction is discretized at equal intervals. For each discretized angle, pixels within the region of interest are projected onto that direction and mapped to the discretized projection coordinate index. For each discrete angle, initialize a gray-level accumulation sequence, and for each pixel in the region of interest, accumulate the corresponding gray-level value to the corresponding sequence position according to its projection index to obtain the projection sequence; Based on the statistical measures of each projection sequence, a quadratic polynomial normal equation is constructed, and the least squares method is used to solve the fitting coefficients to obtain the fitting curves in each direction. Calculate the residual between the original projection value and the fitted curve, generate residual maps in each direction, and construct the maximum residual image by taking the maximum residual value of each pixel in all directions; Calculate the mean and standard deviation of the maximum residual image, adaptively determine the binarization threshold based on the statistics, binarize the residual image to generate a defect candidate mask, and if the threshold or mask does not meet the predetermined conditions, it is judged as defect-free and the detection is terminated. Initial connected components are extracted from the binary mask based on the four-neighbor rule. The area of each connected component is calculated and the small-area connected components are removed using the average area as a threshold. The remaining connected components are re-labeled. If there are no remaining connected components, the system is judged to be defect-free and the detection is terminated. For each final connected region, defect localization and feature extraction are performed sequentially, including bounding box calculation, determining the main direction based on the maximum residual direction and measuring the defect length, calculating the average residual intensity to characterize the defect severity, and mapping the pixel coordinates of the defect region back to the original image coordinate system.
2. The intelligent identification method for track defects based on machine vision according to claim 1, characterized in that, The process of establishing a pixel coordinate system with the top left corner as the origin in the original grayscale image, generating a horizontal projection curve through row grayscale accumulation, locating the center row of the track with the row corresponding to the maximum projection value, and using one-tenth of the image height as half bandwidth to extract the region of interest for the track, specifically includes: Set the pixel coordinate system at the top left corner of the original grayscale image, and set the top left corner as the origin. , The horizontal direction of the axis is positive to the right. The vertical axis pointing downwards is positive, and the pixel spacing is uniformly 1. Obtain the original grayscale image in pixel coordinates The grayscale value at that location is denoted as ;in, The x-axis of the image, The vertical axis of the image; This represents the number of pixel columns in the original image; The number of pixel rows in the original image; Calculate the first The horizontal projection curve is obtained by summing the grayscale values of all pixels in the row. ; The center row of the track is determined by finding the row containing the maximum value of the horizontal projection: ; Calculate the crop half-bandwidth, taking one-tenth of the image height: ; Determine the vertical extent of the region of interest on the original image based on the orbit center and bandwidth, and denot the region of interest as... : , , ;in, for The starting row index in the original image; for The index of the last row in the original image; for number of rows; Within the above range, cropping from the original image Defined as: ;in, for The horizontal pixel index within; for Vertical pixel index within; for Area in pixels The grayscale value at that location.
3. The intelligent identification method for track defects based on machine vision according to claim 2, characterized in that, The step of discretizing the projection direction at equal intervals within a preset angle range, projecting pixels within the region of interest onto that direction for each discrete angle, and mapping them to a discretized projection coordinate index, specifically includes: Constructing an equally spaced discrete angle set, specifically: Set the total number of discretized angles. Calculate the radian interval between two adjacent angles. Then the first Each discrete angle is ;in, For projection direction index; For each discrete angle, calculate Projected coordinates of each pixel within: ;in, for Pixels Along direction The projected coordinates; Rounded to the nearest integer; For each angle Determine the minimum and maximum values of the projected coordinates, and calculate the total number of projected coordinates for each direction: , , ;in, For direction Minimum value of all projected coordinates; For direction Maximum value of all projected coordinates; For direction Total number of upward projection coordinates; Re-index and recalibrate the projected coordinates in each direction: ;in, For projection sequence index; To map consecutive integers to the first integer within the projected coordinate range Each actual coordinate value.
4. The intelligent identification method for track defects based on machine vision according to claim 3, characterized in that, The process of initializing a gray-level accumulation sequence for each discrete angle and accumulating the corresponding gray-level value of each pixel within the region of interest to the corresponding sequence position based on its projection index to obtain a projection sequence specifically includes: For each direction, initialize the projection accumulation sequence: ;in, For direction Lower projection coordinates The sum of grayscale values on the screen is initialized to 0. right For each pixel and each angle of the region, steps S301 to S302 are executed sequentially: S301, Calculate the index of the pixel in the projection direction: ;in, For pixels Along direction The index of the cumulative sequence corresponding to the projection; S302, Perform projection accumulation: .
5. The intelligent identification method for track defects based on machine vision according to claim 4, characterized in that, The process involves calculating statistics based on each projection sequence, constructing a quadratic polynomial normal equation, and using the least squares method to solve for the fitting coefficients to obtain fitting curves in each direction. Specifically, this includes: For each projection direction, the following statistical moments are calculated: , , , , ; , , ;in, For direction Total number of projection points; For direction The sum of all projected coordinate values; For direction Sum of squares of projected coordinates; For direction Sum of the cubes of the projected coordinates; For direction Fourth power sum of projected coordinates; For direction The cumulative grayscale value of all projected points; For direction Projected coordinates and grayscale product sum; For direction Sum of squared projected coordinates and grayscale product; For each direction, define the master determinant and the Cramer substitution determinant: , , , ;in, For direction The principal determinant of the normal equation for second-order polynomial fitting; For direction The first Column replacement The resulting determinant, Replace the column number; Set branch indicator variable : like or Then let And for all Assignment ;in, A value of 1 indicates that the fitting process is skipped, and a value of 0 indicates that the fitting process is normal. For direction Projected coordinates The residual; Otherwise, let ; when Then, Cramer's rule is used to solve for the fitting coefficients, and a second-order fitting curve is constructed: , ;in, , and To fit the polynomial coefficients, corresponding to constants, first-order and second-order terms; For direction No. The second-order fitted values for each projection position.
6. The intelligent identification method for track defects based on machine vision according to claim 5, characterized in that, The calculation of the residual between the original projection value and the fitted curve, generating residual maps in each direction, and constructing a maximum residual image by taking the maximum residual value of each pixel in all directions, specifically includes: Construct the residual sequence for each direction: ; Calculate the residual function for each pixel in each direction: ;in, for Pixels Along direction The residual value; Construct the maximum residual image for each pixel: ;in, for Pixels Maximum residual value in all directions.
7. The intelligent identification method for track defects based on machine vision according to claim 6, characterized in that, The process involves calculating the mean and standard deviation of the maximum residual image, adaptively determining a binarization threshold based on statistics, binarizing the residual image to generate a defect candidate mask, and determining that there is no defect and terminating the detection if the threshold or mask does not meet predetermined conditions. Specifically, this includes: Calculate the mean of the residual plot. and standard deviation : , ; like and If no defect is found, the output "No defects found" is displayed, and the detection process ends. Calculate the segmentation threshold This generates a binary mask: ;in, for Pixels Binarization mask, Indicates possible defect areas; If all If the result is negative, the output will be "No defects found" and the detection process will end.
8. The intelligent identification method for track defects based on machine vision according to claim 7, characterized in that, The process of extracting initial connected components based on the four-neighbor rule on a binary mask, calculating the area of each connected component, and using the average area as a threshold to remove small-area connected components, re-labeling the remaining connected components, and determining that there are no defects and terminating the detection if no remaining connected components remain, specifically includes: right The region is used to extract the initial connected component based on the four-neighbor rule. ;in, For connected component indexes; For the first The set of pixels contained in a connected component; Total number of connected components; The four-neighbor region specifically refers to any pixel. Its four neighboring regions are ,and Only retain those that meet the requirements. , point; If there are no connected components, that is If no defect is found, the output "No defects found" is displayed, and the detection process ends. Calculate the area of each connected component, and then calculate the mean area and the area threshold: , , ;in, For the first The number of pixels in each connected component; This is the average area of all connected components; Area threshold; Remove all areas smaller than The connected components, and the corresponding pixels in Centered at 0; For the remainder The background region is then further extracted using the four-neighbor rule. If its area is smaller than [the specified area], the connected components are considered. If the value is 1, then the corresponding area is set as the foreground pixel. Extract the final connected component set again from the four-neighbors on the updated binary graph. ;in, For the final connected component index; This represents the final number of connected components; For the first One final connected component; like If the result is negative, the output will be "No defects found" and the detection process will end.
9. The intelligent identification method for track defects based on machine vision according to claim 8, characterized in that, The process of sequentially performing defect localization and feature extraction for each final connected component includes bounding box calculation, determining the principal direction based on the maximum residual direction and measuring the defect length, calculating the average residual intensity to characterize the defect severity, and mapping the pixel coordinates of the defect region back to the original image coordinate system. Specifically, this includes: For each final connected component Steps S801 to S806 are executed sequentially: S801. Calculate the bounding box of the connected components: , ;in, For connected components The minimum horizontal pixel index; For connected components Maximum horizontal pixel index; , ; For connected components The minimum vertical pixel index; For connected components Maximum vertical pixel index; S802, for each pixel Calculate the index of the maximum residual direction and count the frequency of the principal direction: ; , ;in, Index of the main residual direction; For connected components Inward direction The frequency of pixel occurrence; The index of the most frequent main direction; S803. Calculate the defect's main direction angle from the main direction index: ;in, For the first The radian of the domain principal direction; S804. Calculate the defect length: ;in, For connected components The projection length along the main direction is a combination of the horizontal and vertical projection lengths and the main direction component. S805. Calculate the average residual intensity within the connected domain as an indicator of defect severity: ;in, For connected components Internal mean maximum residual; For connected components Total number of pixels; S806. Map the pixel coordinates of the connected components back to the original image coordinate system: , ;in, For connected components Each pixel within the image is restored to its original coordinate system.
Citation Information
Patent Citations
High speed railway track surface defect coupling method based on machine visual inspection
CN103913464A
Steel rail surface defect image adaptive segmentation method
CN106251361A