An absolute grating ruler pollution area identification and anti-pollution decoding reading method
By performing boundary continuity analysis and Hamming distance matching error correction on the contaminated area of the grating ruler, the encoding error problem caused by grating ruler contamination was solved, and efficient decoding and encoding recovery were achieved in complex environments.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- XI AN JIAOTONG UNIV
- Filing Date
- 2026-03-20
- Publication Date
- 2026-06-05
AI Technical Summary
Existing technologies are inadequate to effectively address encoding errors caused by grating ruler contamination, especially when there is localized heavy contamination, boundary breaks, or missing stripe information, resulting in insufficient decoding accuracy and robustness.
By performing vertical continuity analysis on candidate boundaries, periodic virtual boundaries are inserted using grating theory, and combined with Hamming distance matching error correction mechanism, the coding region is restored and errors caused by contamination are corrected.
It improves the decoding accuracy and robustness of grating rulers in complex industrial environments, and can automatically handle contaminated areas, ensuring the reliability and accuracy of encoded recovery.
Smart Images

Figure CN122156789A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of optical precision measurement and displacement sensing technology, specifically to a method for identifying contaminated areas and anti-contamination decoding readings of an absolute grating ruler. Background Technology
[0002] The grating ruler is a key component in the position feedback system of precision equipment. Its measurement accuracy and reading stability directly affect the motion control performance and machining quality of the equipment. In practical applications, contaminants such as cutting fluid mist, lubricating grease, metal shavings, and dust particles can easily penetrate the interior of the grating ruler and adhere to the grating surface or reading area. This can cause decreased fringe contrast, abnormal local grayscale distribution, blurred boundaries, or even missing fringes, ultimately leading to absolute coding reading errors. These types of errors are often random, sudden, and localized, making them difficult to effectively address using traditional static compensation methods.
[0003] Currently, the main approaches to addressing grating ruler contamination fall into three categories: passive protection, hardware enhancement, and signal processing. Passive protection relies primarily on sealing, purging, and regular cleaning. While these methods can reduce the probability of contamination to some extent, they cannot fundamentally prevent it and are highly dependent on maintenance conditions and manual operation. Hardware enhancement methods primarily mitigate the impact of contamination by increasing light source intensity, optimizing optical paths, or improving detector sensitivity, but this usually leads to increased system complexity and cost. Signal processing methods often employ filtering, threshold comparison, and simple morphological operations to correct the acquired signal, but they often struggle to accurately recover the true encoded information in cases of localized heavy contamination, boundary breaks, or missing fringe information.
[0004] Existing image-based absolute grating ruler decoding methods (Guangdong University of Technology. A Single-Track Absolute Grating Ruler System: 201810844200.3 [P]. 2020-09-11.) typically involve first performing grayscale thresholding on the acquired grating stripe image, then dividing the coding region through boundary detection, and generating a binary coding sequence based on the grayscale characteristics of each region. However, this type of method is highly sensitive to contamination. When contamination causes local grayscale shifts, the binarization result is easily distorted. When contamination causes boundary breaks or false boundaries, the coding region division is prone to errors. When the stripes are partially occluded, traditional decoding methods that rely solely on local grayscale information of the image are difficult to obtain reliable results. Some methods (Guangdong University of Technology. Image processing method and its application based on magnified grating ruler with horizontal and vertical conversion: 201710149659.7 [P]. 2017-08-29; Yang Min. Research on grating stripe analysis algorithm based on deep learning [D]. Tianjin University of Science and Technology, 2022. DOI:10.27359 / d.cnki.gtqgu.2022.000831; Nazeri K, Ng E, Joseph T, et al. EdgeConnect: Generative Image Inpainting with Adversarial Edge Learning. [J]. CoRR, 2019, abs / 1901.00212) attempt to recover information of polluted areas through image inpainting or texture compensation, but they usually involve a large amount of computation and have limited ability to recover completely occluded areas, making it difficult to balance decoding accuracy and engineering application efficiency.
[0005] Therefore, there is an urgent need for an absolute grating ruler anti-pollution decoding method that can be applied to polluted working conditions and take into account boundary identification, structural repair and coding error correction, so as to improve the decoding robustness and measurement reliability of grating rulers in complex industrial environments. Summary of the Invention
[0006] To overcome the shortcomings of the prior art, the present invention aims to provide an absolute grating ruler contamination area identification and anti-contamination decoding reading method. By analyzing the continuity of the vertical boundary, the encoding error is traced back to the physical structure damage level. Virtual boundaries are inserted at equal intervals in the boundary missing areas caused by contamination using the theoretical period of the grating. A Hamming distance matching error correction mechanism is introduced, using the encoded fragment of the clean area as a consistency constraint. The matching sequence with the smallest Hamming distance is searched in the global reference code library to achieve encoding correction of the contamination area. The present invention corrects the bit errors caused by contamination from two dimensions: restoration of the integrity of the encoded boundary and verification of information redundancy.
[0007] To achieve the above objectives, the present invention adopts the following technical solution: A method for identifying contaminated areas and decoding readings using an absolute grating ruler includes the following steps: S1. Obtain the image to be decoded containing raster stripes, convert the image to be decoded into a grayscale image, and then perform filtering and noise reduction processing to obtain the enhanced image; S2. Perform vertical boundary detection on the enhanced image and extract candidate vertical boundaries; S3. Perform vertical continuity analysis on each candidate vertical boundary to obtain the integrity marker corresponding to each candidate vertical boundary, so as to characterize whether the candidate vertical boundary is a complete boundary or a broken boundary. S4. Based on the grating theory half-period and the spacing between adjacent boundaries, insert missing boundaries in regions where the spacing exceeds a preset threshold, and determine the integrity marker of the missing boundaries based on the integrity markers of the original boundaries on both sides of the insertion position to obtain the final boundary sequence. S5. Using the final boundary sequence as the coding region boundary, the image to be decoded is divided into coding regions, and an initial binary coding sequence is generated based on the grayscale features of each coding region. S6. Determine the contaminated and clean regions in the initial binary encoded sequence based on the integrity markers; S7. Extract the coded subsequence and its position index corresponding to the clean region from the initial binary coded sequence. Slide and cut candidate coded segments of the same length as the initial binary coded sequence from the pre-stored reference grating coded sequence. For each candidate coded segment, extract the code corresponding to the position index and compare its consistency with the coded subsequence. For candidate coded segments that meet the consistency condition, calculate the Hamming distance between them and the initial binary coded sequence, and select the candidate coded segment with the smallest Hamming distance as the final decoding result.
[0008] Step S2 involves detecting vertical boundaries in the enhanced image, including: convolving the enhanced image with the Sobel operator in the vertical direction to obtain a vertical boundary intensity map; binarizing the vertical boundary intensity map to obtain a binary boundary map; performing morphological closing and thinning operations on the binary boundary map; and then extracting lines close to the vertical direction through Hough transform and calculating the x-coordinates of the midpoints of each line as candidate vertical boundary positions.
[0009] The method of extracting near-vertical straight lines using Hough transform is to extract straight lines with an angle range of -5° to 5°.
[0010] In step S3, the vertical continuity analysis of each candidate vertical boundary is performed, including: for each candidate vertical boundary, a vertical strip window is selected with it as the center; the difference between the maximum and minimum gray values of each row of pixels in the vertical strip window is calculated to obtain the change intensity sequence; the proportion of rows with intensity values greater than the intensity threshold in the change intensity sequence is counted to the total number of rows; when the proportion is greater than the boundary threshold, the corresponding candidate vertical boundary is marked as a complete boundary, otherwise it is marked as a broken boundary.
[0011] The intensity threshold is used to characterize whether there is a significant grayscale change in a single row of pixels within the vertical strip window; the boundary threshold is used to characterize whether the proportion of rows with significant grayscale changes to the total number of rows meets the boundary continuity requirement.
[0012] Step S4, which inserts missing boundaries according to the half-cycle of grating theory, includes: adding the left and right boundaries of the image to the boundary sequence; traversing adjacent boundaries and calculating the boundary spacing; when the spacing between adjacent boundaries is greater than a preset multiple of the half-cycle of grating theory, determining the number of missing boundaries to be inserted according to the half-cycle of grating theory, and inserting missing boundaries at equal intervals in the corresponding interval; for the inserted missing boundary, if its left and right adjacent original boundaries are both complete boundaries, then the inserted boundary is marked as a complete boundary, otherwise it is marked as a broken boundary.
[0013] The step S5 of generating the initial binary encoding sequence includes: calculating the grayscale statistical value of each encoding region and comparing the grayscale statistical value with a preset threshold to determine the binary encoding value corresponding to each encoding region, thereby obtaining the initial binary encoding sequence.
[0014] In step S6, determining contaminated and clean areas based on integrity markers includes: for each coded area, detecting the integrity markers corresponding to its left and right boundaries; when at least one of the left and right boundaries has a broken boundary, the coded area is marked as a contaminated area; when both the left and right boundaries have intact boundaries, the coded area is marked as a clean area.
[0015] The method for identifying and anti-contamination decoding readings of an absolute grating ruler contamination area further includes: performing adaptive binarization processing on the grayscale image, and using a local threshold based on the column mean near the vertical boundary to improve the contrast of the boundary area and the accuracy of boundary extraction.
[0016] Compared with the prior art, the present invention has the following beneficial effects: This invention identifies boundary breaks or anomalous regions caused by contamination by performing vertical continuity analysis on candidate boundaries, thus providing a basis for subsequent contamination area determination and decoding error correction. This invention utilizes grating theory half-periods to constrain boundary spacing and inserts missing boundaries in areas of missing boundaries, enabling the recovery of more reasonable coding region boundaries and improving the accuracy of coding region division. This invention distinguishes between contaminated and clean regions based on boundary integrity markers and uses clean region coding as a matching constraint. Combined with reference grating coding sequence search and Hamming distance minimization strategies, it improves coding recovery capability and decoding reliability under contamination conditions. The method of this invention has a clear process and a high degree of automation, and can be used for reading analysis and anti-interference decoding under contamination conditions of absolute grating rulers. Attached Figure Description
[0017] Figure 1 This is an overall flowchart of the method in an embodiment of the present invention.
[0018] Figure 2 This is a schematic diagram of boundary integrity analysis according to an embodiment of the present invention.
[0019] Figure 3 This is a schematic diagram of the missing boundary insertion process in an embodiment of the present invention.
[0020] Figure 4 This is a schematic diagram illustrating the principle of Hamming distance matching error correction in an embodiment of the present invention.
[0021] Figure 5 This is a schematic diagram showing the result of processing a single-point contamination grating stripe image according to an embodiment of the present invention.
[0022] Figure 6 This is a schematic diagram showing the result of processing a multi-point contamination grating stripe image according to an embodiment of the present invention. Detailed Implementation
[0023] The technical solution of the present invention will be clearly and completely described below with reference to the embodiments and 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.
[0024] Example: Refer to Figure 1 An absolute grating ruler contamination area identification and anti-contamination decoding reading method is proposed. For black opaque contamination, the specific steps are as follows: Step 1: Image Acquisition; In this embodiment, a raster image is acquired using a CCD camera, with an image size of 900×500 pixels; If the image is in color, it is converted to grayscale; A 3×3 median filter is used to remove salt-and-pepper noise to obtain an enhanced image; Step 2: Extract candidate boundaries; In this embodiment, the Sobel vertical operator [-1 0 1; -2 0 2; -1 0 1] is used to convolve the enhanced image to obtain a vertical boundary intensity map; the boundary intensity map is binarized to obtain a binary boundary map; morphological closing operations are performed on the binary boundary map to connect the broken boundaries, and then it is thinned to obtain a single-pixel wide boundary; Hough transform is used to detect nearly vertical straight lines, and the x-coordinate of the midpoint of each straight line is extracted as the set of candidate boundary positions. ; Step 3: Generate integrity markers based on boundary continuity; this embodiment is for... Each boundary in Take a vertical strip window with 5 pixels on each side and calculate the maximum grayscale value of each row within the window. and minimum value The difference yields the change intensity sequence. Set threshold ,statistics Medium to large The percentage of rows ;like Then mark the boundary as complete. Otherwise, mark it as broken. ), Figure 2 This is a schematic diagram illustrating the generation of integrity markers based on boundary continuity in this embodiment. It can be seen that the boundary of marker 1 satisfies... The condition, marked as a complete boundary, is not satisfied by the boundary labeled 2. The conditions are marked as fracture boundaries.
[0025] Since the left and right boundaries of an image are not necessarily stripe boundaries, integrity checks are also necessary. The left boundary of the image is taken as a vertical stripe window 5 pixels to the right, and the right boundary is taken as a vertical stripe window 5 pixels to the left. The maximum grayscale value of each row within the window is calculated. and minimum value The difference is used to obtain the change intensity sequence V; a threshold is set. ,statistics Medium to large The percentage of rows ;like Then mark the boundary as complete. Otherwise, mark it as broken. ); Step 4: Insert missing boundaries according to the theoretical period; in this embodiment, the left boundary 1 and the right boundary width of the image are added. The extended boundary sequence is obtained. ; Traversal Calculate the spacing between adjacent boundaries. The theoretical period T of the grating is determined by the camera pixel size. Camera magnification and grating pitch Calculated in advance according to the formula: In this embodiment Pixel, half-cycle Pixels; if Then calculate the number of boundary values to be inserted. ; Figure 3 This is a schematic diagram illustrating the insertion of missing boundaries based on the theoretical period in this embodiment. It can be seen that within approximately two and a half periods of adjacent boundaries, insertion is required. A boundary line; inserting equidistant lines between the left and right boundaries. The insertion position is rounded down; the integrity flag of the inserted boundary is determined by the original left and right boundaries: if both sides are intact, the inserted boundary is marked as intact; otherwise, it is marked as broken; the inserted boundary is merged with the original boundary to obtain a new boundary sequence. ; Step 5: Divide the encoding region and generate the initial encoding; this embodiment uses... The image is divided into several coding regions, with adjacent boundaries defined as intervals. The average gray value of all columns within each region (which can be taken from the vertical projection intensity) is calculated and compared with the median gray value of the entire image. If the region's average gray value is greater than the median, the region is encoded as "1"; otherwise, it is encoded as "0", thus obtaining the initial coding sequence. ; Step 6: Determine contaminated areas based on boundary integrity markers; in this embodiment, for each coded area, check the integrity markers of its left and right boundaries; if either marker is broken, the area is marked as contaminated. Otherwise, mark as clean. ), to obtain the contamination mask area ; Taking advantage of the large field of view, the initial binary encoded sequence According to the raster coding sequence Encoding bits It is divided into three coding segments: front, middle, and back. Decode its corresponding absolute position , , Further testing will be conducted; if and If the difference does not exceed the preset position consistency threshold, then no encoding is used to indicate contamination or that the contamination does not affect the reading; otherwise, it is determined to be encoding contamination. Based on the decoded initial binary encoded sequence The contaminated area identified as 1 is redefined as a clean area; Step 7: Using the clean area encoding as a constraint, search for the best matching segment in the reference code; in this embodiment, a known reference grating encoding sequence is pre-stored. ;from Extract the coding subsequence corresponding to the clean area And record these cleaned areas in Position index in ; exist The sliding window has a length equal to... length For each starting position ( From 1 to ,Pick subsequence of ;Compare and If they are exactly the same, then calculate and Hamming distance ; Figure 4 This is a theoretical schematic diagram of the Hamming distance calculation in this embodiment. It can be seen that, taking two 23-bit code segments as an example, when three corresponding bits are different, the sum of the Hamming distances is... Record those that meet the conditions. middle smallest As the best matching sequence ; Step 8: Output the corresponding absolute position; in this embodiment, The corresponding absolute position is output as the final decoding result.
[0026] Through the above steps, even if the raster image is contaminated with oil, the correct encoded sequence can be recovered. Those skilled in the art can adjust and optimize the above parameters, such as the filter window size, binarization threshold, integrity judgment threshold, and spacing judgment multiple, based on factors such as the actual raster ruler model, camera resolution, and lighting conditions. All such adjustments fall within the scope of protection of this invention.
[0027] Figure 5 , Figure 6To compare the decoding performance of this embodiment under different levels of contamination, the following figures are presented: Figure (a) is a clean raster stripe image, Figure (b) is a raster stripe image contaminated by contaminants, Figure (c) is a contaminated binarized raster stripe image, and Figure (d) is a binarized raster stripe image processed by this embodiment. It can be seen that the code identified in Figure (a) is different from the code identified in Figure (b), indicating that the contamination has effectively contaminated the raster stripe code; the code identified in Figure (a) is the same as the code identified in Figure (d), indicating that this embodiment can effectively handle the contamination and restore the correct code, further demonstrating the inventiveness and practicality of the present invention.
Claims
1. A method for identifying contaminated areas and performing anti-contamination decoding readings using an absolute grating ruler, characterized in that... Includes the following steps: Step 1: Obtain the image to be decoded containing raster stripes and perform preprocessing to obtain the enhanced image; Step 2: Perform boundary detection on the enhanced image to obtain candidate boundaries and their integrity markers. The integrity markers are used to characterize whether the candidate boundaries are complete boundaries or broken boundaries. Step 3: Based on the theoretical period of the grating, insert missing boundaries between adjacent candidate boundaries with a spacing exceeding a preset threshold, and determine the integrity marker of the missing boundaries according to the integrity marker of the adjacent candidate boundaries to form the final boundary sequence; Step 4: Divide the coding region according to the final boundary sequence, and generate the initial binary coding sequence based on the grayscale features of each coding region; Step 5: Based on the integrity markers, the coded regions whose left and / or right boundaries are marked as broken boundaries are determined as contaminated regions, and the rest are clean regions; Step 6: Using the coded subsequence of the clean region and its position index as constraints, search for the candidate coded segment that best matches the initial binary coded sequence in the pre-stored reference grating coded sequence, and output it as the final decoding result.
2. The method according to claim 1, characterized in that, The preprocessing in step 1 includes converting the image to grayscale and performing median filtering.
3. The method according to claim 1 or 2, characterized in that, Step 2 boundary detection includes: performing convolution using the vertical Sobel operator, binarizing, morphologically processing and thinning the obtained boundary intensity map, and then using Hough transform to extract straight lines as candidate boundaries.
4. The method according to claim 1, characterized in that, Step 2, obtaining the integrity label, includes analyzing the continuity of grayscale changes in the vertical direction for each candidate boundary. If the continuity meets a preset threshold, it is marked as an intact boundary; otherwise, it is marked as a broken boundary.
5. The method according to claim 4, characterized in that, The analysis of the continuity of grayscale changes in the vertical direction includes: selecting a vertical strip window at the candidate boundary, and counting the proportion of rows in the window where the grayscale change intensity exceeds the intensity threshold. If the proportion is greater than the boundary threshold, it is determined to be a complete boundary.
6. The method according to claim 1, characterized in that, Step 3, inserting missing boundaries, includes inserting several boundaries at equal intervals according to the theoretical half-period when the distance between adjacent boundaries is greater than a preset multiple of the theoretical half-period of the grating; if the original boundaries adjacent to the inserted boundary on the left and right are both complete boundaries, then they are marked as complete, otherwise they are marked as broken.
7. The method according to claim 1, characterized in that, Step 4, generating the initial binary encoded sequence, involves calculating the average gray value of each encoded region and comparing it with a global or local threshold to obtain the corresponding binary encoded value.
8. The method according to claim 1, characterized in that, Step 5 determines the contaminated area. For a given coded area, if at least one of the integrity markers on its left and right boundaries is broken, then the area is a contaminated area.
9. The method according to claim 1, characterized in that, Step 6, searching for the best-matching candidate encoded segment, involves sliding and truncating a candidate segment of the same length as the initial binary encoded sequence from the reference raster encoded sequence; for each candidate segment, extracting the code corresponding to the clean region's location index and comparing it with the encoded subsequence of the clean region; when they match, calculating the Hamming distance between the candidate segment and the initial binary encoded sequence; and selecting the candidate segment with the smallest Hamming distance as the final decoding result.