A method for removing the background of wood images based on an adaptive threshold
By using adaptive threshold method and image filtering techniques in wood image processing, the problem of difficult interference and noise removal in the prior art is solved, and a more efficient and accurate background removal effect is achieved.
Patent Information
- Application Number
- CN202310056641.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-17
- Publication Date
- 2025-06-10
- Estimated Expiration
- 2043-01-17
AI Technical Summary
The prior art is difficult to effectively suppress interference and noise in the industrial environment when removing wood image background, and the processing time is long, reducing the efficiency of wood area extraction.
Adaptive threshold-based method is adopted to adaptively obtain the boundary coordinates of wood images through image scaling, filtering, binarization processing and mean vector extraction, and improve the accuracy of boundary coordinates through local image interception and repetition processing.
It improves the accuracy and reliability of wood image background removal, reduces processing time, and enhances the robustness of wood image detection in complex environments.
Smart Images

Figure CN116128915B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of image processing, and particularly relates to a method for removing the background of wood images based on an adaptive threshold. Background Art
[0002] In the process of detecting wood surface defects, in order to improve the defect detection performance, it is necessary to accurately extract the wood area from the collected images. At the same time, due to the high real-time requirements in industrial scenarios, it is necessary to efficiently remove the background of the original image.
[0003] In industry, the area of wood board materials used for processing is large, and linear array cameras are usually used to collect images of them. The collected images are characterized by high clarity and large aspect ratio. The industrial site environment is complex, and the collected images not only contain noise but also have large areas of light and shadow, which makes it more difficult to remove the wood background. Most traditional background removal methods are based on image processing technology. Although these methods have high accuracy, their processing time increases exponentially with the increase of the image size, which greatly reduces the extraction efficiency of the wood area.
[0004] Chinese Patent with application number CN201310549158.X provides a method for removing the background of an image. This method spreads based on a seed region composed of pixels of the non-target image part, and within a preset gray threshold or color threshold range, searches for eligible pixels among the adjacent pixels of the seed region, and takes the eligible pixels as a new seed region to spread again until there are no pixels as a new seed region. After removing all the seed regions, the target image after background removal can be obtained. This method spreads the boundary based on the color space, and various interferences generated in the complex wood processing environment in industry cannot be effectively suppressed by this method.
[0005] Chinese Patent with application number CN202110904704.1 provides a method for removing the background of an infrared thermal image. This method obtains a frozen infrared thermal image, frames the foreground target on the infrared thermal image, and obtains the effective maximum temperature and the effective minimum temperature within the target region. Taking the effective maximum temperature and the effective minimum temperature as judgment conditions, it determines the temperature array of the infrared thermal image to achieve image rendering. For the temperature data within the range of the effective maximum temperature and the effective minimum temperature, real rendering is performed, and for the temperature data outside the range of the effective maximum temperature and the effective minimum temperature, special rendering is performed, so that the foreground target and the background are clearly distinguishable and easier to identify. This method processes each pixel point of the image, and its detection time increases with the increase in the number of pixel points, and it cannot be effectively applied to the background removal of high-resolution wood images. Summary of the Invention
[0006] The purpose of the present invention is to provide a method for removing the background of wood images based on an adaptive threshold, which is beneficial to improving the accuracy and reliability of removing the background of wood images and reducing the time-consuming of removing the background of wood images.
[0007] To achieve the above object, the technical solution adopted by the present invention is: a method for removing the background of wood images based on an adaptive threshold, comprising the following steps:
[0008] S1. Scale the original wood image to obtain a low-magnification wood image;
[0009] S2. Generate a binary black-and-white wood image through image filtering and binarization processing;
[0010] S3. Extract the mean vectors in two directions of rows and columns respectively from the binary black-and-white wood image;
[0011] S4. Use the adaptive threshold method to obtain the boundary coordinates of the low-magnification wood image;
[0012] S5. Restore the boundary to the original wood image to intercept the local images at both ends of the boundary, and repeat steps S2 - S4 to obtain the final accurate boundary coordinate information.
[0013] Further, in step S1, after obtaining the original wood image with the length and width dimensions of H×W, set the scaling ratio to r, and scale the original wood image to obtain a low-magnification wood image with the length and width dimensions of of.
[0014] Further, in step S2, the implementation method of image filtering is: for the low-magnification wood image, use a Laplacian operator with a size of k×k to perform convolution filtering on it, and calculate the absolute value of each pixel point to obtain the filtered wood image;
[0015] The implementation method of binarization processing is: use the OTSU adaptive threshold segmentation algorithm to segment the foreground and background of the filtered wood image to obtain a binary black-and-white wood image.
[0016] Further, in step S3, the implementation method of extracting the mean vector by row from the binary black-and-white wood image is:
[0017] Calculate the average value by row for the binary black-and-white wood image to obtain an initial mean vector with a length of of where v i represents the average value of all pixel points in the i-th row of the image, and L dt represents the length of the vector;
[0018] Then, perform background value zeroing, including the following steps:
[0019] S301. Divide the initial mean vector V into n V sub-vectors and calculate the average value M of the sub-vectors i , where i = (1, 2, …, n V ); calculate the average value M of the initial mean vector V V ; take the maximum value of M i and M V as the average foreground value M fg ;
[0020] S302. Calculate the average values of the first d elements and the last d elements of the initial mean vector V respectively to obtain M head and M end , take the minimum value of M head , M end and M V as the average background value M bg ;
[0021] S303. Calculate the deduction value
[0022] S304. Calculate the mean vector where p i = v i - v reduce , i = (1, 2, …, L dt ).
[0023] Further, the implementation steps of step S4 are as follows:
[0024] S401. Obtain the adaptive threshold, including the following steps:
[0025] 1) Obtain the initial threshold T initial = k initial · (M bg - v reduce ), where 0 < k initial < 1;
[0026] 2) Obtain the continuous intervals in the initial mean vector V where the element values are greater than T initial , and retain the intervals with lengths greater than the threshold k allow L dt , where 0 < k allow < 1;
[0027] 3) Obtain the average value M allow of all elements in the retained intervals, and obtain the ratio p dt of the total length of the retained intervals to L allow ; obtain T 0 = (γ · p allow + η · (1 - p allow )) · MV ;
[0028] 4) Sort the starting and ending positions of the reserved interval, and record the minimum value as x min , and the maximum value as x max ; Obtain the average value M min of all elements of the initial mean vector V that are less than T max within the interval [x initial . less ;
[0029] 5) Obtain Obtain
[0030] 6) Obtain the adaptive threshold where α is a variable parameter;
[0031] S402. Obtain the middle position coordinate m of the wood foreground; Divide the mean vector P into n P sub-vectors equally; Randomly sample one element from each sub-vector. If the value of this element is greater than T, record its position information; Sort all the position information from smallest to largest, and the median of them is the middle coordinate m;
[0032] S403. Obtain the boundary position coordinates at both ends of the wood; Obtain the background length at the front end of the wood and the background length at the back end. Then the position coordinate Y 1 of the front boundary of the wood = L 1 , and the position coordinate Y 2 of the back boundary = M 0 - L 2 ;
[0033] S404. Obtain the position coordinates of the left and right boundaries of the wood; By calculating the average value of each column of the binary black-and-white wood image obtained in step S2, obtain the initial mean vector with a length of , and repeat steps S401 to S403 to obtain the position coordinates X 1 and X 2 of the left and right boundaries of the wood.
[0034] Further, the implementation steps of step S5 are as follows:
[0035] S501. Crop the original wood image with the coordinates (rX 1 , rY 1 ) and (rX 2 , rY 1 + l·(Y 2 - Y 1 )) to obtain the upper-end partial image, with the coordinates (rX2 , rY 2 -l·(Y 2 -Y 1 )) and (rX 1 , rY 2 ) are used to intercept the original wood image to obtain the lower-end partial image. Adjusting the parameter l can change the length size of the partial image;
[0036] S502. Repeat steps S2 to S4 to obtain the upper boundary ΔY of the upper-end partial image 1 and the lower boundary ΔY of the lower-end partial image 2 ;
[0037] S503. Obtain the final upper boundary coordinate rY of the wood 1 +ΔY 1 and the lower boundary coordinate rY 2 -(l·(Y 2 -Y 1 )-ΔY 1 ); The final left boundary coordinate of the wood is rX 1 , and the right boundary coordinate is rX 2 ;
[0038] Crop the original wood image according to the obtained coordinates of the upper, lower, left, and right boundaries to remove the background, and finally obtain the image after background removal.
[0039] Compared with the prior art, the present invention has the following beneficial effects:
[0040] 1) The present invention effectively improves the accuracy of background removal of wood images, enhances the robustness of wood image detection, and enables the wood images collected in a relatively complex environment to be effectively removed of the background.
[0041] 2) The present invention uses a calculation method of data analysis to obtain the boundary coordinate values of wood images, increases the flexibility of background removal processing, reduces the error of wood image boundary calculation, and improves the reliability of wood image background removal.
[0042] 3) The present invention adopts a positioning framework from the whole to the local, effectively reduces the time consumption of image background removal, and improves the efficiency of industrial production. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Figure 1 is a flowchart of the method implementation of an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0044] The present invention will be further described below with reference to the drawings and embodiments.
[0045] It should be noted that the following detailed description is exemplary and is intended to provide further explanation of the present application. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the technical field to which the present application belongs.
[0046] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present application. As used herein, unless the context clearly indicates otherwise, the singular forms are also intended to include the plural forms. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, they indicate the presence of features, steps, operations, devices, components, and / or combinations thereof.
[0047] As Figure 1 shown, this embodiment provides a method for removing the background of wood images based on an adaptive threshold, including the following steps:
[0048] S1. Scale the original wood image to obtain a low-magnification wood image.
[0049] S2. Generate a binary black-and-white wood image through image filtering and binarization processing.
[0050] S3. Extract the mean vectors in two directions of rows and columns for the binary black-and-white wood image respectively.
[0051] S4. Use the adaptive threshold method to obtain the boundary coordinates of the low-magnification wood image.
[0052] S5. Restore the boundary to the original wood image to intercept the local images at both ends of the boundary, and repeat steps S2 - S4 to obtain the final accurate boundary coordinate information.
[0053] In step S1, after obtaining the original wood image with length and width dimensions of H×W, set the scaling ratio as r, and scale the original wood image to obtain a low-magnification wood image with length and width dimensions of .
[0054] In step S2, the implementation method of image filtering is: for the low-magnification wood image, use a Laplacian operator with a size of k×k to perform convolution filtering on it, and obtain the absolute value of each pixel point to obtain the filtered wood image.
[0055] The implementation method of binarization processing is: use the OTSU adaptive threshold segmentation algorithm to segment the foreground and background of the filtered wood image to obtain a binary black-and-white wood image.
[0056] In step S3, the implementation method of extracting the mean vector by row for the binary black-and-white wood image is:
[0057] The average value of the binary black and white wood image is calculated row by row to obtain an initial mean vector with a length of where v represents the average value of all pixel points in the i-th row of the image, and L i represents the length of the vector. dt
[0058] Then, the background value is set to zero, including the following steps:
[0059] S301. Divide the initial mean vector V into n V sub-vectors and calculate the average value M i of the sub-vectors, where i = (1, 2,..., n V ); calculate the average value M V of the initial mean vector V; take the maximum value of M i and M V as the average foreground value M fg .
[0060] S302. Calculate the average values of the first d elements and the last d elements of the initial mean vector V respectively to obtain M head and M end , take the minimum value of M head , M end and M V as the average background value M bg .
[0061] S303. Calculate the deduction value
[0062] S304. Calculate the mean vector where p i = v i - v reduce , i = (1, 2,..., L dt ).
[0063] The implementation steps of step S4 are as follows:
[0064] S401. Obtain the adaptive threshold, including the following steps:
[0065] 1) Obtain the initial threshold T initial = k initial ·(M bg - v reduce ), where 0 < k initial < 1.
[0066] 2) Obtain the continuous intervals in the initial mean vector V where the element values are greater than T initial , and retain the intervals with lengths greater than the threshold k allow L dt , where 0 < kallow < 1.
[0067] 3) Calculate the average value M of all elements within the retained interval. allow , calculate the ratio p of the total length of the retained interval to L dt . allow ; Calculate T 0 = (γ · p allow + η · (1 - p allow )) · M V .
[0068] 4) Sort the starting position and ending position of the retained interval, and denote the minimum value as x min , and the maximum value as x max ; Calculate the average value M min of all elements in the initial mean vector V that are less than T max within the interval [x initial , x less .
[0069] 5) Calculate Calculate
[0070] 6) Calculate the adaptive threshold where α is a variable parameter.
[0071] S402. Calculate the intermediate position coordinate m of the wood foreground; divide the mean vector P into n P sub - vectors; randomly sample an element from each sub - vector. If the value of this element is greater than T, record its position information; sort all the position information in ascending order, and the median is the intermediate coordinate m.
[0072] S403. Calculate the boundary position coordinates at both ends of the wood; calculate the background length at the front end of the wood and the background length at the back end of the wood. 1 Then the position coordinate Y 1 of the front - end boundary of the wood = L 2 , and the position coordinate Y 0 of the back - end boundary of the wood = M 2 - L Figure 1 . The process is as
[0073] S404. Calculate the position coordinates of the left and right boundaries of the wood; by calculating the average value of each column of the binary black - and - white wood image obtained in step S2, obtain an initial mean vector with a length of , and repeat steps S401 to S403 to obtain the position coordinates X 1 and X 2 of the left and right boundaries of the wood.
[0074] The implementation steps of step S5 are as follows:
[0075] S501. Crop the original wood image with coordinates (rX 1 , rY 1 ) and (rX 2 , rY 1 + l·(Y 2 - Y 1 )) to obtain the upper partial image. Crop the original wood image with coordinates (rX 2 , rY 2 - l·(Y 2 - Y 1 )) and (rX 1 , rY 2 ) to obtain the lower partial image. Adjusting the parameter l can change the length size of the partial image.
[0076] S502. Repeat steps S2 to S4 to obtain the upper boundary ΔY 1 of the upper partial image and the lower boundary ΔY 2 of the lower partial image.
[0077] S503. Obtain the final upper boundary coordinate rY 1 + ΔY 1 and the final lower boundary coordinate rY 2 - (l·(Y 2 - Y 1 ) - ΔY 1 ). The final left boundary coordinate of the wood is rX 1 , and the right boundary coordinate is rX 2 .
[0078] Crop the original wood image according to the obtained coordinates of the upper, lower, left, and right boundaries to remove the background, and finally obtain the image with the background removed.
[0079] The following further illustrates the implementation process of the method of the present invention based on an embodiment with specific parameters.
[0080] The method for removing the background of a wood image based on an adaptive threshold provided by this embodiment is specifically implemented as follows:
[0081] (1) Image scaling; Obtain the original image of a wood image, and scale the original wood image with dimensions of 45000×3000, set the scaling ratio to 10, and a scaled image with dimensions of 4500×300 can be obtained.
[0082] (2) Image filtering; perform convolution filtering on it using a Laplacian operator with a size of 5×5 and obtain the absolute value of each pixel point.
[0083] (3) Binarization processing; use the OTSU adaptive threshold segmentation algorithm to segment the foreground and background of the filtered image and obtain a binary black and white wood image.
[0084] (4) Extract the initial mean vector; calculate the average value of each row of the binary black and white wood image to obtain an initial mean vector V = (v 1 , v 2 , …, v i , …, v 4500 ), where v i represents the average value of all pixel points in the i-th row of the image.
[0085] (5) Set the background value to zero; the specific steps are as follows:
[0086] I. Divide the initial mean vector V into 5 sub-vectors equally and calculate the average value M i , where i = (1, 2, …, 5); calculate the average value M V of the initial mean vector V; take the maximum value of M i and M V as the average foreground value M fg .
[0087] II. Calculate the average values of the first 20 elements and the last 20 elements of the initial mean vector V respectively to obtain M head and M end , take the minimum value of M head , M end and M V as the average background value M bg .
[0088] III. Calculate the deduction value
[0089] IV. Calculate the mean vector P = (p 1 , p 2 , p 3 …, p 4500 ); where p i = v i - v reduce , i = (1, 2, …, 4500).
[0090] (6) Obtain the adaptive threshold; the specific calculation steps are as follows:
[0091] I. Calculate the initial threshold T initial = 0.03(Mbg -v reduce )。
[0092] II. Find the continuous intervals in the initial mean vector V where the element values are greater than T initial , and retain the intervals with a length greater than the threshold of 900.
[0093] III. Calculate the average value M of all elements within the retained intervals allow , calculate the ratio p of the total length of the retained intervals to 4500 allow ; calculate T 0 =(0.2p allow +0.33(1 - p allow ))·M V 。
[0094] IV. Sort the starting and ending positions of the retained intervals, and denote the minimum value as x min , and the maximum value as x max 。Calculate the average value M of all elements in the initial mean vector V that are less than T within the interval [x min , x max . initial less 。
[0095] V. Calculate Obtain p; calculate
[0096] VI. Calculate the adaptive threshold
[0097] (7) Calculate the middle position coordinate m of the wood foreground; divide the mean vector P into 100 sub - vectors; randomly sample one element from each sub - vector. If the element value is greater than T, record its position information; sort all the position information in ascending order, and the median is the middle coordinate m.
[0098] (8) Calculate the boundary position coordinates at both ends of the wood; calculate the background length at the front end of the wood and the background length at the back end where then the position coordinate Y 1 of the front - end boundary of the wood is L 1 , and the position coordinate Y 2 of the back - end boundary is M 0 - L 2 ; the process is as Figure 1 shown.
[0099] (9) Obtain the position coordinates of the left and right boundaries of the wood; by calculating the average value column by column for the binary image obtained in step (3), an initial average value vector with a length of 300 is obtained, and steps (5) to (8) are repeated to obtain the coordinates X 1 and X 2 .
[0100] (10) Obtain the accurate boundary coordinates; the specific steps are as follows:
[0101] I. Crop the original wood image with the coordinates (10X 1 , 10Y 1 ) and (10X 2 , 10Y 1 + 0.07(Y 2 - Y 1 )) to obtain the upper partial image, and crop the original wood image with the coordinates (10X 2 , 10Y 2 - 0.07(Y 2 - Y 1 )) and (10X 1 , 10Y 2 ) to obtain the lower partial image.
[0102] II. Repeat steps (2) to (8) to obtain the upper boundary ΔY 1 of the upper partial image and the lower boundary ΔY 2 of the lower partial image.
[0103] III. Obtain the final upper boundary coordinate of the wood 10Y 1 + ΔY 1 and the lower boundary coordinate 10Y 2 - (0.07(Y 2 - Y 1 ) - ΔY 1 );
[0104] The final left boundary coordinate of the wood is 10X 1 , and the right boundary coordinate is 10X 2 .
[0105] (11) Complete the background removal operation; crop the original image according to the coordinates of the upper, lower, left, and right boundaries obtained above, and finally obtain the image with the background removed.
[0106] The above are only the preferred embodiments of the present invention, and are not intended to limit the present invention in any other form. Any person skilled in the art may use the technical content disclosed above to make changes or modifications into equivalent embodiments with equivalent changes. However, any simple modifications, equivalent changes and modifications made to the above embodiments based on the technical essence of the present invention without departing from the technical solution content of the present invention still fall within the protection scope of the technical solution of the present invention.
Claims
1. A method for removing the background of wood images based on an adaptive threshold, characterized in that, it includes the following steps: S1. Scale the original wood image to obtain a low-magnification wood image; S2. Generate a binary black-and-white wood image through image filtering and binarization processing; S3. Extract the mean vectors of the binary black-and-white wood image in two directions, row and column respectively; S4. Use the adaptive threshold method to obtain the boundary coordinates of the low-magnification wood image; S5. Restore the boundary to the original wood image to intercept the local images at both ends of the boundary, and repeat steps S2 - S4 to obtain the final accurate boundary coordinate information; In step S1, after obtaining the original wood image with length and width dimensions of H×W, set the scaling ratio to r, and scale the original wood image to obtain a low-magnification wood image with length and width dimensions of ; In step S3, the implementation method of extracting the mean vector of the binary black-and-white wood image by row is: The average value of the binary black and white wood image is calculated row by row to obtain an initial mean vector with a length of The initial mean vector where v i represents the average value of all pixel points in the i-th row of the image, and L dt represents the length of the vector; Then, zero the background value, including the following steps: S301. Divide the initial mean vector V into n V sub-vectors, and calculate the average value M of the sub-vectors i , where i = (1, 2,..., n V ); calculate the average value M of the initial mean vector V V ; take M i and M V 's maximum value as the average foreground value M fg ; S302. Calculate the average values of the first d elements and the last d elements of the initial mean vector V respectively to obtain M head and M end , take M head , M end and M V , and take the minimum value among M bg ; S303. Obtain the deduction value S304. Obtain the mean vector where p i = v i - v reduce , i = (1, 2, …, L dt ); The implementation steps of step S4 are as follows: S401. Obtain the adaptive threshold, including the following steps: 1) Obtain the initial threshold T initial = k initial ·(M bg - v reduce ), where 0 < k initial < 1; 2) Obtain consecutive intervals in the initial mean vector V where the element values are greater than T initial and retain intervals with a length greater than the threshold k allow L dt where 0 < k allow < 1; 3) Calculate the average value M of all elements within the retained interval allow , calculate the ratio p of the total length of the retained interval to L dt ; Calculate T allow ; Calculate T 0 = (γ·p allow + η·(1 - p allow ))·M V ; 4) Sort the start position and end position of the reserved interval, and denote the minimum value as x min , and the maximum value as x max ; Obtain the average value M min of all elements of the initial mean vector V that are less than T max in the interval [x initial , x less ; 5) Obtain Obtain 6) Obtain the adaptive threshold where α is a variable parameter; S402. Obtain the intermediate position coordinate m of the wood foreground; equally divide the mean vector P into n P sub-vectors; randomly sample an element in each sub-vector, if the value of this element is greater than T, record its position information; sort all the position information from small to large, and the median among them is the intermediate coordinate m; S403. Obtain the boundary position coordinates of both ends of the wood; obtain the background length of the front end of the wood and the background length of the rear end wherein then the position coordinate Y of the front-end boundary of the wood 1 = L 1 , and the position coordinate Y of the rear-end boundary 2 = M 0 - L 2 ; S404. Obtain the position coordinates of the left and right boundaries of the wood; by calculating the average value column by column for the binary black-and-white wood image obtained in step S2, an initial mean vector with a length of is obtained, and steps S401 to S403 are repeated to obtain the position coordinates X 1 and X 2 .
2. According to the method for removing the background of wood images based on an adaptive threshold described in claim 1, characterized in that, In step S2, the implementation method of image filtering is: for the low-magnification wood image, perform convolution filtering on it using a Laplacian operator with a size of k×k, and calculate the absolute value of each pixel point to obtain the filtered wood image; The implementation method of binarization processing is: use the OTSU adaptive threshold segmentation algorithm to segment the foreground and background of the filtered wood image to obtain a binary black-and-white wood image.
3. According to the method for removing the background of wood images based on an adaptive threshold described in claim 1, characterized in that, The implementation steps of step S5 are as follows: S501. Crop the original wood image with coordinates (rX 1 , rY 1 ) and (rX 2 , rY 1 + l·(Y 2 - Y 1 )) to obtain the upper partial image. Crop the original wood image with coordinates (rX 2 , rY 2 - l·(Y 2 - Y 1 )) and (rX 1 , rY 2 ) to obtain the lower partial image. Adjusting the parameter l can change the length size of the partial image; S502. Repeat steps S2 to S4 to obtain the upper boundary ΔY of the upper partial image 1 and the lower boundary ΔY of the lower partial image 2 ; S503. Obtain the final upper boundary coordinate rY of the wood 1 +ΔY 1 and the lower boundary coordinate rY 2 -(l·(Y 2 -Y 1 )-ΔY 1 ); The final left boundary coordinate of the wood is rX 1 , and the right boundary coordinate is rX 2 ; Crop the original wood image according to the obtained coordinates of the upper, lower, left, and right boundaries to remove the background, and finally obtain the image with the background removed.
Citation Information
Patent Citations
Method for removing image background
CN103578108A
Method for removing background of infrared thermal image
CN113670446A
KR20200086463A