Adaptive enhancement method and system for 16-bit grayscale images of casting X-ray flaw detection
By partitioning and sub-image processing of 16-bit grayscale images of casting X-ray flaw detection, combined with edge enhancement and parameter optimization, the problems of detail loss and false detection during image display are solved, and the image quality and film evaluation accuracy are improved.
Patent Information
- Application Number
- CN202510277487.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-10
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2045-03-10
AI Technical Summary
In the prior art, when 16-bit grayscale images of casting X-ray flaw detection are displayed on ordinary monitors, details are lost and visual effects are deteriorated, resulting in problems of missed detection and false detection during manual film evaluation.
The 16-bit grayscale image is divided into multiple grayscale sub-intervals or sub-images, and mapped into 8-bit grayscale images. After edge enhancement, CLAHE parameter correction and Gamma correction, they are merged. The particle swarm algorithm and genetic algorithm are combined to optimize the parameters and optimize the image quality.
It achieves detail enhancement of 16-bit grayscale images on ordinary monitors, avoids missed detection and false detection of small defects, and improves image quality and film evaluation accuracy.
Smart Images

Figure CN120107137B_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of image processing, and more specifically, relates to a method and system for adaptively enhancing 16-bit grayscale images of casting X-ray flaw detection. Background Art
[0002] In recent years, X-ray flaw detection technology has been widely used in the detection of internal defects in castings. In order to obtain higher-precision and better-quality images, the flaw detection equipment will save the detection results as a 16-bit grayscale image, ensuring that each pixel can be represented by 65,536 grayscale values. Ordinary monitors can generally only display 8-bit (256 levels) of grayscale, while 16-bit grayscale images have 65,536 levels of grayscale. Therefore, when a 16-bit grayscale image is displayed directly on an ordinary monitor, the following situations will occur: (1) Grayscale loss: Since the monitor can only display 8-bit grayscale, the grayscale information of the image will be compressed or lost. Usually, the 16-bit grayscale image will be simply truncated to 8 bits when displayed, that is, only the highest 256 levels of grayscale values will be displayed, resulting in the loss of details in the dark or bright parts of the image. (2) Visual effect deterioration: The details in the 16-bit image will be compressed into the dynamic range of the 8-bit monitor, causing the image to appear overexposed or too dark, with insufficient details, and important details in the image may not be seen. When manually reviewing 16-bit grayscale images, a "window adjustment" is performed, which involves selecting a specific grayscale range and mapping it to the 8-bit display range. During manual review, the window width and window position must be repeatedly adjusted, and even the slightest inattention can lead to errors such as missing minor defects or misdetecting similar defects. Summary of the Invention
[0003] In response to the defects of the existing technology, the purpose of this application is to provide a method and system for adaptive enhancement of 16-bit grayscale images of casting X-ray flaw detection, aiming to solve the problem of loss of details when existing X-ray flaw detection images are displayed on ordinary monitors, which in turn leads to missed detections and false detections during manual film evaluation.
[0004] To achieve the above objectives, the present application provides a method for adaptively enhancing 16-bit grayscale images of casting X-ray flaw detection, comprising:
[0005] S1: dividing a 16-bit grayscale image into a plurality of grayscale subintervals, and mapping each grayscale subinterval into an 8-bit grayscale image; dividing the 16-bit grayscale image into a plurality of subimages, and mapping each subimage into an 8-bit subimage;
[0006] S2 enhances and merges the 8-bit grayscale images to obtain an enhanced grayscale image; enhances each 8-bit sub-image to obtain an enhanced sub-image;
[0007] S3 evaluates the image quality of the enhanced grayscale image to obtain a first evaluation result; evaluates the image quality of each enhanced sub-image, and obtains an average value of all evaluation results as a second evaluation result;
[0008] S4 uses the first evaluation result and the second evaluation result as target evaluation functions, respectively, optimizes the parameter combinations of the enhanced grayscale image and the enhanced sub-image, and outputs the corresponding optimal parameters and the enhanced image corresponding to the optimal parameters; compares the evaluation scores corresponding to the optimal parameters output by the two optimization methods, and outputs the enhanced image corresponding to the maximum evaluation score as the final enhanced image.
[0009] Compared with the existing technology, the above technical solution conceived by the present application enhances the 16-bit grayscale image through two division methods, obtains the corresponding evaluation results of the enhanced image as the optimization target, and combines the optimization algorithm to achieve the best enhancement processing of the 16-bit grayscale image, thereby avoiding the subsequent missed detection and false detection of small defects.
[0010] Furthermore, in step S2, the step of enhancing the 8-bit grayscale image includes:
[0011] S201 performs edge enhancement processing on the 8-bit grayscale image to obtain an edge-enhanced image;
[0012] S202 performs overall image enhancement processing on the edge-enhanced image to obtain the enhanced grayscale image.
[0013] Furthermore, in step S201, the edge enhancement processing method is: identifying the edge of the 8-bit grayscale image, and sharpening the 8-bit grayscale image with the identified edge using the following formula to obtain an edge-enhanced image:
[0014]
[0015] in, is the enhancement coefficient, I 8 is an 8-bit grayscale image. is the image after Gaussian smoothing, (x,y) Represents image pixels.
[0016] Furthermore, in step S202, the overall image enhancement processing method is:
[0017] Apply CLAHE parameter correction to the edge enhanced image to obtain a corrected image. The correction formula is:
[0018]
[0019] in, C limit _1 for CLAHE parameters, and ,
[0020] Then use the Gamma parameter to perform secondary correction on the corrected image to obtain the enhanced image. The secondary correction formula is:
[0021]
[0022] in, γ 1 is the Gamma parameter, and , I enh _1 To enhance the image;
[0023] The step of enhancing the 8-bit grayscale image is the same as the step of enhancing the grayscale image.
[0024] Furthermore, in step S3, the image quality of the enhanced grayscale image is evaluated to obtain a first evaluation result by: obtaining an edge clarity index, a local contrast index, and an image entropy index of the enhanced grayscale image; normalizing the edge clarity index, the local contrast index, and the image entropy index, and obtaining the first evaluation result using the following formula:
[0025]
[0026] in, is the normalized edge sharpness, is the normalized local contrast, is the normalized image entropy index; ω E 、ω C 、ω H They are different coefficients, and the sum of the three is 1. Q represents the first evaluation result;
[0027] Furthermore, the method for evaluating the image quality of each enhanced sub-image is the same as the method for evaluating the image quality of the enhanced grayscale image.
[0028] Furthermore, the method for obtaining the edge clarity index of the enhanced grayscale image includes:
[0029] S301 uses the Canny edge detection algorithm to extract the edges of the enhanced grayscale image respectively;
[0030] S302 calculates the gradient amplitude of the corresponding edge pixel points, and obtains the average value of the gradient amplitude as an edge clarity index.
[0031] Furthermore, the method for obtaining the local contrast index of the enhanced grayscale image includes:
[0032] S311: dividing the enhanced grayscale image into a plurality of local sub-blocks of the same size;
[0033] S312 calculates the grayscale mean of pixels in each local sub-block, and uses the grayscale mean to obtain the grayscale standard deviation;
[0034] S313 obtains the average value of the grayscale standard deviation as a local contrast index.
[0035] Furthermore, the method for obtaining the image entropy index of the enhanced grayscale image includes:
[0036] S321: Counting the grayscale histogram of the enhanced grayscale image and calculating the total number of pixels in the grayscale histogram;
[0037] S322 obtains the occurrence probability of each gray level using the grayscale histogram and the total number of pixels;
[0038] S323 obtains the image entropy index based on the occurrence probability of each gray level using the following formula:
[0039]
[0040] in, H score is the image entropy index, p (g) is the probability of occurrence of gray level, g=0,1,...,255。
[0041] Furthermore, in step S4, the first evaluation result and the second evaluation result are respectively used as target evaluation functions, and the particle swarm algorithm is used to optimize the parameter combination of the enhanced grayscale image and the enhanced sub-image respectively. The steps of the particle swarm algorithm are as follows:
[0042] The steps of the particle swarm algorithm are:
[0043] S401 randomly generates M particles in the image parameter space, each particle represents a set of parameter combinations;
[0044] S402 obtains the evaluation score of each particle, compares the evaluation score of each particle with the evaluation scores of two adjacent particles, and updates the position of the current particle to the particle with the highest evaluation score among the adjacent particles;
[0045] S403 uses a tournament selection strategy to select several particles from the particles whose positions have been updated as parents; performs a crossover operation on the corresponding parameters of each of the parents to obtain offspring; uses an adaptive mutation strategy to mutate the offspring according to a preset probability. During the mutation process, an elite retention strategy is used to directly retain excellent offspring, and a selection mechanism based on fitness ratio is used to screen the remaining offspring;
[0046] S404 repeats steps S401 to S403 until a predetermined number of iterations is reached or the evaluation score converges, and then outputs the optimal parameters.
[0047] Furthermore, the parameter combination includes the following parameters: grayscale step size, window width, window level, edge enhancement parameter, CLAHE parameter and Gamma parameter.
[0048] According to another aspect of the present application, a system for implementing the aforementioned method for adaptively enhancing 16-bit grayscale images of casting X-ray flaw detection is also provided, comprising:
[0049] a quantization module, configured to divide a 16-bit grayscale image into a plurality of grayscale subintervals and map each grayscale subinterval into an 8-bit grayscale image; and further configured to divide the 16-bit grayscale image into a plurality of subimages and map each subimage into an 8-bit subimage;
[0050] An enhancement processing module is used to perform enhancement processing on the 8-bit grayscale images and then merge them to obtain an enhanced grayscale image; it is also used to perform enhancement processing on each 8-bit sub-image to obtain an enhanced sub-image;
[0051] An evaluation module, configured to evaluate the image quality of the enhanced grayscale image to obtain a first evaluation result; and further configured to evaluate the image quality of each enhanced sub-image and obtain an average value of all evaluation results as a second evaluation result;
[0052] An optimization module is used to use the first evaluation result and the second evaluation result as target evaluation functions, respectively, to optimize the parameter combinations of the enhanced grayscale image and all enhanced sub-images, and output the corresponding optimal parameters and the enhanced images corresponding to the optimal parameters; it is also used to compare the evaluation scores corresponding to the optimal parameters output by the two optimization methods, and output the enhanced image corresponding to the maximum evaluation score as the final enhanced image.
[0053] The above technical solutions conceived by this application have the following beneficial effects compared with the existing technology:
[0054] (1) This application enhances 16-bit grayscale images through two parallel image processing methods, and performs quality assessment on the enhanced grayscale images and enhanced sub-images after the two enhancement processes. The respective quality assessment results are used as optimization target evaluation functions, and the optimization algorithms are used to optimize them respectively, thereby obtaining the enhanced processed image with the best image quality, thereby achieving the beneficial effect of avoiding subsequent missed detection and false detection of small defects.
[0055] (2) This application uses the same set of image quality evaluation systems to evaluate the two types of 8-bit images after enhancement processing. The evaluation indicators include edge clarity, local contrast and grayscale distribution (i.e., image entropy). These evaluation indicators are used to calculate the normalized comprehensive index, and the comprehensive index is used as the target evaluation function of the optimization algorithm. The enhanced processed image corresponding to the optimal parameter combination obtained by the optimization algorithm has higher image quality.
[0056] (3) The adaptive image enhancement method provided by this application is more adaptable and can adjust the evaluation indicators according to different needs, thereby obtaining different optimization target evaluation functions and optimization results. The selection, crossover, and mutation operations of the genetic algorithm are interspersed in the optimization algorithm. The selection operation determines which individuals can reproduce offspring, the crossover operation introduces new parameter combinations, and the mutation operation increases the diversity of the population by introducing randomness, preventing the algorithm from falling into a local optimal solution. This can effectively balance the global search ability and local search ability of the algorithm, while avoiding the loss of excellent solutions due to random operations. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] Figure 1 This is a flow chart of a method for adaptively enhancing 16-bit grayscale images of casting X-ray flaw detection provided by an embodiment of the present application;
[0058] Figure 2 1. This is a schematic diagram of the processing process of the adaptive enhancement method for 16-bit grayscale images of casting X-ray flaw detection provided by an embodiment of the present application;
[0059] Figure 3 This is a schematic diagram of an image after dividing a 16-bit grayscale image into multiple grayscale intervals and enhancing the image provided by an embodiment of the present application;
[0060] Figure 4 This is a schematic diagram of an image after dividing a 16-bit grayscale image into multiple sub-images and enhancing the image provided by an embodiment of the present application;
[0061] Figure 5 It is a structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0062] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.
[0063] In the description of this application, it should be understood that the terms "first" and "second" are used for descriptive purposes only and should not be understood to indicate or imply relative importance or implicitly specify the number of the technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of this application, "plurality" means two or more, unless otherwise specifically defined.
[0064] Additionally, references throughout this specification to "one embodiment," "one embodiment," "an example," or similar language indicate that a particular feature, structure, or characteristic described in connection with the embodiment is included in at least one embodiment of the present application. Thus, appearances of the phrase "in one embodiment," "in one embodiment," and similar language throughout this specification may, but do not necessarily, all refer to the same embodiment.
[0065] The embodiment of the present application provides a method for adaptively enhancing 16-bit grayscale images of casting X-ray flaw detection, such as Figure 1 and Figure 2 As shown, the method includes the following steps:
[0066] S1 divides the 16-bit grayscale image into multiple grayscale subintervals and maps each grayscale subinterval into an 8-bit grayscale image; divides the 16-bit grayscale image into multiple subimages and maps each subimage into an 8-bit subimage;
[0067] S2 enhances and merges the 8-bit grayscale image to obtain the following Figure 3 The enhanced grayscale image shown in FIG; each 8-bit sub-image is enhanced to obtain the following Figure 4 Enhancer diagram shown;
[0068] S3 evaluates the image quality of the enhanced grayscale image to obtain a first evaluation result; evaluates the image quality of each enhanced sub-image, and obtains the average value of all evaluation results as a second evaluation result;
[0069] S4 uses the first evaluation result as the target evaluation function to optimize the parameter combination of the enhanced grayscale image, and outputs the corresponding evaluation score, optimal parameters and the enhanced image corresponding to the optimal parameters; uses the second evaluation result as the target evaluation function to optimize the parameter combination of the complete image composed of all enhanced sub-images, and outputs the corresponding evaluation score, optimal parameters and the enhanced image corresponding to the optimal parameters; compares the evaluation scores corresponding to the two optimal parameters, and outputs the enhanced image corresponding to the maximum evaluation score as the final enhanced image (i.e., output Figure 4 (as shown above or below in the last step in [1].
[0070] In the above step S1, the width and height of the 16-bit grayscale image of the casting X-ray flaw detection are obtained, which are recorded as w and h respectively; assuming that the input image is I , I(x,y) Represents pixel coordinates (x,y) Gray value on , and 0≤ I(x,y) ≤65535, divide the 16-bit grayscale image into multiple grayscale sub-intervals, and map the grayscale sub-intervals into 8-bit grayscale images. The specific division steps include:
[0071] S101 sets the grayscale step size step , divide the grayscale interval inton Grayscale subintervals are expressed as:
[0072] (1)
[0073] in, n represents the sequence number of the grayscale subinterval, and ; step Indicates the step length, the value is , such as the second subinterval is , No. n The subinterval is , G min is the minimum grayscale value of a 16-bit grayscale image, G max is the maximum grayscale value of a 16-bit grayscale image;
[0074] S102 maps the 1st to nth grayscale sub-intervals into an 8-bit range in sequence using the following formula:
[0075] (2)
[0076] in, WW n For the n The window width of the subintervals, WL n For the n The window level of each subinterval;
[0077] S103 combines the images corresponding to all the mapped grayscale sub-intervals to obtain an 8-bit grayscale image.
[0078] In the aforementioned step S2, the step of enhancing the 8-bit grayscale image includes:
[0079] S201 first performs edge enhancement processing on the 8-bit grayscale image to obtain an edge-enhanced image.
[0080] Specifically, the Canny edge detection operator is used to process the 8-bit grayscale image to obtain the edge map E 1. The parameters of the Canny edge detection operator include the low threshold T low and high threshold T high , T low The value is [0.05×max_grad,0.15×max_grad], T high The value is [0.2×max_grad, 0.4×max_grad], where max_grad is the maximum gradient amplitude of the image; the enhancement coefficient λ ranges from 0.5 to 1.0.E 1 (x,y)= 1 means the pixel (x, y) is an edge pixel of the image, otherwise E 1 (x,y)= 0. The following formula is used to calculate the edge graph E 1. Sharpen to obtain an edge-enhanced image:
[0081] (3)
[0082] in, This is the edge enhanced image after Gaussian smoothing.
[0083] S202 performs overall image enhancement processing on the edge-enhanced image to obtain an enhanced grayscale image. The overall image enhancement processing method is:
[0084] Edge-enhanced image Apply CLAHE parameter correction to obtain the corrected image. The correction formula is:
[0085] (4)
[0086] in, C limit _1 for CLAHE parameters, and ,
[0087] Then use the Gamma parameter to perform secondary correction on the corrected image to obtain the enhanced image. The secondary correction formula is:
[0088] (5)
[0089] in, γ 1 is the Gamma parameter, and , I enh_1 To enhance the image;
[0090] In the aforementioned step S1, the step of dividing the 16-bit grayscale image into a plurality of sub-images and mapping each sub-image into an 8-bit sub-image includes:
[0091] S111 divides the 16-bit grayscale image into multiple sub-images evenly, that is, evenly divides it into rows and columns, such as cutting it into 12 sub-images;
[0092] S112 maps the grayscale values of the multiple sub-images to an 8-bit range according to the following formula:
[0093] (6)
[0094] in, For the n sub-images, For the n The window width of the sub-graph, For the n The window level of each sub-image;
[0095] S113 merges all mapped sub-images to obtain an 8-bit sub-image.
[0096] In this embodiment, the steps for enhancing the 8-bit sub-image are the same as those for enhancing the grayscale image. The specific steps are:
[0097] Use the Canny edge detection operator to process the 8-bit sub-image and obtain the edge map E 1_ n The parameters of the Canny edge detection operator include the low threshold T low and high threshold T high , T low The value is [0.05×max_grad,0.15×max_grad], T high The value is [0.2×max_grad, 0.4×max_grad], where max_grad is the maximum gradient amplitude of the image; the enhancement coefficient λ n The range is 0.5~1.0, E 1_ n (x,y)= 1 means the pixel (x, y) is an edge pixel of the image, otherwise E 1_ n (x,y)= 0. The following formula is used to calculate the edge graph E 1_ n (x,y)= 1 to obtain an edge-enhanced image:
[0098] (7)
[0099] in, It is the edge enhanced image after Gaussian smoothing.
[0100] Edge-enhanced image Apply CLAHE parameter correction to obtain the corrected image. The correction formula is:
[0101] (8)
[0102] in, for CLAHE parameters, and .
[0103] Then use the Gamma parameter to perform secondary correction on the corrected image to obtain the enhanced image. The secondary correction formula is:
[0104] (9)
[0105] in, is the Gamma parameter, and , I enh_2_n To enhance the image.
[0106] In the aforementioned step S3, the image quality of the enhanced grayscale image is evaluated, and the method for obtaining the first evaluation result is: obtaining the edge clarity index, local contrast index, and image entropy index of the enhanced grayscale image; normalizing the edge clarity index, local contrast index, and image entropy index, and obtaining the first evaluation result using the following formula:
[0107] (10)
[0108] in, is the normalized edge sharpness, is the normalized local contrast, is the normalized image entropy index; ω E 、ω C 、ω H They are different coefficients, and the sum of the three is 1.
[0109] More specifically, when scoring, the entire image that has been divided into multiple grayscale intervals and enhanced is scored, and the score is used as the first evaluation result; the multiple enhanced sub-images that have been divided into multiple sub-images and enhanced are scored separately, and then the average of the scores of all enhanced sub-images is taken as the second evaluation result.
[0110] In this embodiment, the method for evaluating the image quality of each enhanced sub-image is the same as the method for evaluating the image quality of the enhanced grayscale image.
[0111] The method for obtaining the edge clarity index of the aforementioned enhanced grayscale image includes:
[0112] S301 uses the Canny edge detection algorithm to extract the edges and pixels of the enhanced grayscale image. E(x,y)=1 The area is the edge pixel, otherwise E(x,y)=0 ;
[0113] S302 calculates the gradient amplitude of the corresponding edge pixel points and obtains the average value of the gradient amplitude as an edge clarity index;
[0114] Calculate the enhanced 8-bit grayscale image The gradient component G x (x,y)With G y (x,y) :
[0115] (11)
[0116]
[0117] The gradient amplitude of each edge pixel is calculated using the aforementioned gradient components. The calculation formula is:
[0118] (12)
[0119] In all E(x,y)=1 In the edge pixel set of G(x,y), the average is calculated using the following formula:
[0120] (13)
[0121] The larger it is, the greater the average gradient amplitude of the edge pixels of the image is, and the higher the edge clarity is.
[0122] The method for obtaining the edge clarity index of the enhanced sub-image is the same as the method for obtaining the edge clarity index of the enhanced grayscale image.
[0123] The method for obtaining the local contrast index of the enhanced grayscale image includes:
[0124] S311 divides the enhanced grayscale image into multiple local sub-blocks of the same size; divides the enhanced 8-bit grayscale image into M local sub-blocks of the same size R k (For example, each sub-block is 16×16 pixels).
[0125] S312 calculates the grayscale mean of the pixels in each local sub-block and uses the grayscale mean to obtain the grayscale standard deviation; the grayscale mean calculation formula in each sub-block is:
[0126] (14)
[0127] in, N k For the k The number of pixels in each sub-block;
[0128] The grayscale standard deviation calculation formula is:
[0129] (15)
[0130] S313 obtains the average value of the grayscale standard deviation as the local contrast index; the calculation formula for taking the average value of the grayscale standard deviation of all sub-blocks is:
[0131] (16)
[0132] The larger the value is, the more obvious the difference in grayscale distribution in the local area is, and the higher the local contrast is.
[0133] The method for obtaining the image entropy index of the enhanced sub-image is the same as the method for obtaining the image entropy index of the enhanced grayscale image.
[0134] The method for obtaining the local contrast index of the enhanced grayscale image includes:
[0135] S321 Grayscale histogram of statistically enhanced grayscale image h(g) , g=0,1,...,255, and calculate the total number of pixels in the grayscale histogram ;
[0136] S322 uses the grayscale histogram and the total number of pixels to obtain the probability of occurrence of each grayscale level p(g) :
[0137] (17)
[0138] S323 obtains the image entropy index based on the occurrence probability of each gray level using the following formula:
[0139] (18)
[0140] in, H score is the image entropy index, p (g) is the probability of occurrence of gray level, g=0,1,...,255, when p(g) It is 0 o'clock.
[0141] In the aforementioned step S4, the first evaluation result and the second evaluation result are respectively used as target evaluation functions, and the particle swarm algorithm is used to optimize the parameter combinations of the enhanced grayscale image and the enhanced sub-image respectively; and / or, the parameter combination includes the following parameters: grayscale step size, window width, window position, edge enhancement parameter, CLAHE parameter and Gamma parameter.
[0142] In this embodiment, the first evaluation result and the second evaluation result are respectively used as target evaluation functions, and the particle swarm algorithm is used to optimize the parameter combination of the enhanced grayscale image and the enhanced sub-image. The specific optimization steps include:
[0143] S401 Initialization: Randomly generate M particles in the parameter space. Each particle represents a set of parameter combinations. Each set of parameters includes:
[0144] Grayscale step length step, the value is [1000,Gmax -G min ];
[0145] Window width , the value is 0.5 to 1 times the current grayscale interval or sub-image width;
[0146] Window level , the value is 0.3 to 0.7 times the current grayscale interval or the average grayscale value of the sub-image;
[0147] Edge enhancement parameters, low threshold T low and high threshold T high , T low The value is [0.05×max_grad,0.15×max_grad], T high The value is [0.2×max_grad, 0.4×max_grad], where max_grad is the maximum gradient amplitude of the image; the enhancement coefficient λ ranges from 0.5 to 1.0;
[0148] CLAHE parameters, ;
[0149] Gamma parameter, .
[0150] S402 runs a complete enhancement process for each particle's parameter combination, calculates the evaluation score Q value (i.e., fitness) corresponding to each particle, and updates the particle speed and position: updates based on the particle's historical optimal and global optimal positions, that is, compares the evaluation score of the current particle with the evaluation scores of the two adjacent particles, and updates the current particle to the position of the adjacent particle with a higher evaluation score, thereby continuously making the particle swarm approach the global optimal solution. The update formula is as follows:
[0151] (19)
[0152] and:
[0153] (20)
[0154] in, for k After iterations, particles i The flight velocity vector d dimensional component, The particle position vector d Dimensional component; c 1. c 2 is the acceleration constant, take 2; r 1. r2 are two random numbers in the range [0,1]; w is the inertia weight.
[0155] To prevent particles from falling into local optima, S403 introduces selection, crossover, and mutation operations into the optimization process using a genetic algorithm. Specifically, a tournament selection strategy is used to select particles with the best fitness (i.e., the highest evaluation scores) from the updated positions as parents. Any corresponding parameters between any two parents are crossovered to obtain multiple offspring. An adaptive mutation strategy is then used to mutate these offspring according to a preset probability. During the mutation process, an elite retention strategy is used to directly retain the best offspring, while a fitness-ratio-based selection mechanism is used to screen the remaining offspring.
[0156] More specifically, the goal of the selection operation is to select excellent parents for crossover and mutation operations. A tournament selection strategy is employed, specifically: Each time, a certain number of particles (e.g., 10 particles) with the best evaluation scores are selected from the original particle population. The particles with the best evaluation scores are selected from these particles as parents, and the remaining particles are placed in the original particle population for a second screening. During this second screening, a batch of particles with the best evaluation scores are again selected from the particle population, and the particles with the best evaluation scores from this batch are selected as parents. The aforementioned selection steps are repeated until a sufficient number of parents are obtained, and the next crossover operation is performed. Crossover operations are performed on the corresponding parameters of each pair of parent generations to obtain offspring. Specifically, the corresponding parameters contained in each pair of parent generations are randomly crossovered, such as swapping the window width and window position corresponding to parent 1 and parent 2; swapping the CLAHE parameters corresponding to parent 3 and parent 4; and so on. Two to four corresponding parameter information items can be randomly swapped to obtain offspring 1, 2, 3, 4, and so on.
[0157] Finally, the swapped offspring undergoes a mutation operation. According to a preset probability (e.g., 0.05), the value of a particle dimension is increased or decreased. This dimension value is represented in binary form and the mutation operation is performed. For example, 11110001 may mutate to 11010001. During the mutation process, if the offspring's evaluation score is sufficiently high, such as a quality score higher than a preset score of 85, it is directly copied to the next generation population to ensure that excellent solutions are not lost. Otherwise, the retention probability is used based on the proportion of each particle's total evaluation scores in the parent and offspring generations, and suitable particles are selected for the next generation. During the mutation process, the number of particles entering the next generation is ensured to remain constant.
[0158] S404 repeats the iteration until a predetermined number of generations (such as 100) is reached or the fitness converges, and the optimal parameters corresponding to the two image division methods are output respectively. and , thus obtaining and The corresponding parameter sets for image enhancement optimization , and the corresponding enhanced image under this parameter set .
[0159] S405 compares the evaluation scores corresponding to the optimal parameters , select the one with the larger evaluation score and as the final output image.
[0160] In another embodiment, a system for implementing the aforementioned method for adaptively enhancing 16-bit grayscale images of casting X-ray flaw detection is provided, the system comprising:
[0161] a quantization module, configured to divide a 16-bit grayscale image into a plurality of grayscale subintervals and map each grayscale subinterval into an 8-bit grayscale image; and further configured to divide the 16-bit grayscale image into a plurality of subimages and map each subimage into an 8-bit subimage;
[0162] An enhancement processing module is used to perform enhancement processing on the 8-bit grayscale images and then merge them to obtain an enhanced grayscale image; it is also used to perform enhancement processing on each 8-bit sub-image to obtain an enhanced sub-image;
[0163] An evaluation module, configured to evaluate the image quality of the enhanced grayscale image to obtain a first evaluation result; and further configured to evaluate the image quality of each enhanced sub-image and obtain an average value of all evaluation results as a second evaluation result;
[0164] The optimization module is used to use the first evaluation result and the second evaluation result as the target evaluation function, respectively, to optimize the parameter combination of the enhanced grayscale image and all enhanced sub-images, and output the corresponding optimal parameters and the enhanced image corresponding to the optimal parameters; it is also used to compare the evaluation scores corresponding to the optimal parameters output by the two optimization methods, and output the enhanced image corresponding to the maximum evaluation score as the final enhanced image.
[0165] It should be understood that the above-mentioned device is used to execute the method in the above-mentioned embodiment. The implementation principle and technical effect of the corresponding program module in the device are similar to those described in the above-mentioned method. The working process of the device can refer to the corresponding process in the above-mentioned method and will not be repeated here.
[0166] Based on the methods described in the above embodiments, embodiments of the present application provide an electronic device. The device may include: at least one memory for storing programs and at least one processor for executing the programs stored in the memory. When the programs stored in the memory are executed, the processor is configured to execute the methods described in the above embodiments.
[0167] Figure 5 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application, such as Figure 5As shown, the electronic device may include: a processor 501, a communication interface 502, a memory 503, and a communication bus 504. The processor 501, the communication interface 502, and the memory 503 communicate with each other via the communication bus 504. The processor 501 may call software instructions in the memory 503 to execute the methods described in the above embodiments.
[0168] In addition, the logic instructions in the memory 503 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on this understanding, the technical solution of the present application, or the part that contributes to the relevant technology, or the part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a number of instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the various embodiments of the present application.
[0169] Based on the method in the above embodiment, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program runs on a processor, the processor executes the method in the above embodiment.
[0170] Based on the method in the above embodiment, an embodiment of the present application provides a computer program product. When the computer program product runs on a processor, the processor executes the method in the above embodiment.
[0171] It is understood that the processor in the embodiments of the present application may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field programmable gate arrays (FPGA), other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. The general-purpose processor may be a microprocessor or any conventional processor.
[0172] The method steps in the embodiments of the present application can be implemented by hardware or by a processor executing software instructions. The software instructions can be composed of corresponding software modules, which can be stored in random access memory (RAM), flash memory, read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), registers, hard disks, mobile hard disks, CD-ROMs, or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be an integral part of the processor. The processor and the storage medium can be located in an ASIC.
[0173] The above embodiments can be implemented in whole or in part using software, hardware, firmware, or any combination thereof. When implemented using software, they can be implemented in whole or in part in the form of a computer program product. A computer program product comprises one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions according to the embodiments of the present application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted via a computer-readable storage medium. The computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that can be accessed by a computer, or a data storage device such as a server or data center that integrates one or more available media. Available media can include magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs), or semiconductor media (e.g., solid-state drives (SSDs)).
[0174] It will be understood that the various numerical numbers involved in the embodiments of the present application are merely distinctions for the convenience of description and are not intended to limit the scope of the embodiments of the present application.
[0175] It is easy for those skilled in the art to understand that the above are only preferred embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent replacements and improvements made within the spirit and principles of the present application should be included in the scope of protection of the present application.
Claims
1. A method for adaptively enhancing 16-bit grayscale images of casting X-ray flaw detection, characterized in that: include: S1: dividing a 16-bit grayscale image into a plurality of grayscale subintervals, and mapping each grayscale subinterval into an 8-bit grayscale image; dividing the 16-bit grayscale image into a plurality of subimages, and mapping each subimage into an 8-bit subimage; S2 enhances and merges the 8-bit grayscale images to obtain an enhanced grayscale image; Enhance each 8-bit sub-image to obtain an enhanced sub-image; S3 evaluates the image quality of the enhanced grayscale image to obtain a first evaluation result; Evaluate the image quality of each enhanced sub-image, and obtain the average value of all evaluation results as the second evaluation result; S4 uses the first evaluation result and the second evaluation result as target evaluation functions respectively, optimizes the parameter combinations of the enhanced grayscale image and all enhanced sub-images respectively, obtains the corresponding evaluation scores, optimal parameters and enhanced images corresponding to the optimal parameters; compares the two evaluation scores, and outputs the enhanced image corresponding to the maximum evaluation score as the final enhanced image.
2. The method for adaptively enhancing 16-bit grayscale images of casting X-ray flaw detection according to claim 1, characterized in that: In step S2, the step of enhancing the 8-bit grayscale image includes: S201 performs edge enhancement processing on the 8-bit grayscale image to obtain an edge-enhanced image; S202 performs overall image enhancement processing on the edge-enhanced image to obtain the enhanced grayscale image.
3. The method for adaptively enhancing 16-bit grayscale images of casting X-ray flaw detection according to claim 2, characterized in that: In step S201, the edge enhancement processing method is: identifying the edge of the 8-bit grayscale image, and sharpening the 8-bit grayscale image with the identified edge using the following formula to obtain an edge-enhanced image: in, is the enhancement coefficient, I 8 is an 8-bit grayscale image. is the image after Gaussian smoothing, (x,y) Represents image pixels.
4. The method for adaptively enhancing 16-bit grayscale images of casting X-ray flaw detection according to claim 3, characterized in that: In step S202, the overall image enhancement processing method is: Apply CLAHE parameter correction to the edge enhanced image to obtain a corrected image. The correction formula is: in, C limit _1 for CLAHE parameters, and , Then, the Gamma parameter is used to perform secondary correction on the corrected image to obtain an enhanced image. The secondary correction formula is: in, γ 1 is the Gamma parameter, and , I enh _1 To enhance the image; And / or, the step of enhancing the 8-bit sub-image is the same as the step of enhancing the grayscale image.
5. The method for adaptively enhancing 16-bit grayscale images of casting X-ray flaw detection according to claim 1, characterized in that: In step S3, the image quality of the enhanced grayscale image is evaluated to obtain a first evaluation result by: obtaining an edge clarity index, a local contrast index, and an image entropy index of the enhanced grayscale image; normalizing the edge clarity index, the local contrast index, and the image entropy index, and obtaining the first evaluation result using the following formula: in, is the normalized edge sharpness, is the normalized local contrast, is the normalized image entropy index; ω E 、ω C 、ω H They are different coefficients, and the sum of the three is 1; And / or, the method for evaluating the image quality of each enhanced sub-image is the same as the method for evaluating the image quality of the enhanced grayscale image.
6. The method for adaptively enhancing 16-bit grayscale images of casting X-ray flaw detection according to claim 5, characterized in that: The method for obtaining the edge clarity index of the enhanced grayscale image includes: S301 uses the Canny edge detection algorithm to extract the edges of the enhanced grayscale image respectively; S302 calculates the gradient amplitude of the corresponding edge pixel points, and obtains the average value of the gradient amplitude as an edge clarity index.
7. The method for adaptively enhancing 16-bit grayscale images of casting X-ray flaw detection according to claim 5, characterized in that: The method for obtaining the local contrast index of the enhanced grayscale image includes: S311: dividing the enhanced grayscale image into a plurality of local sub-blocks of the same size; S312 calculates the grayscale mean of pixels in each local sub-block, and uses the grayscale mean to obtain the grayscale standard deviation; S313 obtains the average value of the grayscale standard deviation as a local contrast index.
8. The method for adaptively enhancing 16-bit grayscale images of casting X-ray flaw detection according to claim 5, characterized in that: The method for obtaining the image entropy index of the enhanced grayscale image includes: S321: Counting the grayscale histogram of the enhanced grayscale image and calculating the total number of pixels in the grayscale histogram; S322 obtains the occurrence probability of each gray level using the grayscale histogram and the total number of pixels; S323 obtains the image entropy index based on the occurrence probability of each gray level using the following formula: in, H score is the image entropy index, p (g) is the probability of occurrence of gray level, g=0,1,...,255 .
9. The method for adaptively enhancing 16-bit grayscale images of casting X-ray flaw detection according to claim 1, characterized in that: In step S4, the first evaluation result and the second evaluation result are respectively used as target evaluation functions, and the particle swarm algorithm is used to optimize the parameter combination of the enhanced grayscale image and the enhanced sub-image. The steps of the particle swarm algorithm are as follows: S401 randomly generates M particles in the image parameter space, each particle represents a set of parameter combinations; S402 obtains the evaluation score of each particle, compares the evaluation score of each particle with the evaluation scores of two adjacent particles, and updates the position of the current particle to the particle with the highest evaluation score among the adjacent particles; S403 uses a tournament selection strategy to select several particles from the particles whose positions have been updated as parents; performs a crossover operation on the corresponding parameters of each of the parents to obtain offspring; uses an adaptive mutation strategy to mutate the offspring according to a preset probability. During the mutation process, an elite retention strategy is used to directly retain excellent offspring, and a selection mechanism based on fitness ratio is used to screen the remaining offspring; S404 repeats steps S401 to S403 until a predetermined number of iterations is reached or the fitness converges, and then outputs the optimal parameters and the enhanced image corresponding to the optimal parameters.
10. A system for implementing the method for adaptively enhancing 16-bit grayscale images of casting X-ray flaw detection according to any one of claims 1 to 9, characterized in that: include: Quantization module, used to divide the 16-bit grayscale image into multiple grayscale sub-intervals and map each grayscale sub-interval into an 8-bit grayscale image; It is also used to divide the 16-bit grayscale image into multiple sub-images, and map each sub-image into an 8-bit sub-image; An enhancement processing module, configured to perform enhancement processing on the 8-bit grayscale images and then merge them to obtain an enhanced grayscale image; It is also used to enhance each 8-bit sub-image to obtain an enhanced sub-image; An evaluation module, configured to evaluate the image quality of the enhanced grayscale image and obtain a first evaluation result; It is also used to evaluate the image quality of each enhanced sub-image and obtain the average value of all evaluation results as the second evaluation result; An optimization module is used to use the first evaluation result and the second evaluation result as target evaluation functions, respectively, to optimize the parameter combinations of the enhanced grayscale image and all enhanced sub-images, and output the corresponding optimal parameters and the enhanced images corresponding to the optimal parameters; it is also used to compare the evaluation scores corresponding to the optimal parameters output by the two optimization methods, and output the enhanced image corresponding to the maximum evaluation score as the final enhanced image.
Citation Information
Patent Citations
Self-adaptive contrast adjustment method and device based on image histogram equalization characteristic
CN113989130A
Self-adaptive pseudo-color display enhancement method for X-ray negative film of solid engine
CN116258646A