Grayscale image enhancement method and device based on adaptive particle swarm algorithm
The parameters determined by the adaptive particle swarm algorithm, combined with K-Means clustering and Kalinsky-Harabas index, solve the problems of complex structure and poor robustness of the image enhancement algorithm in the existing technology, and achieve the image information amount The guarantee and contour enhancement improve the stability and efficiency of image enhancement.
Patent Information
- Application Number
- CN202210277440.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-16
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2042-03-16
AI Technical Summary
When existing image enhancement technology deals with noise and improves image contrast, the optimization algorithm has a complex structure and poor robustness. It is easy to fall into the local optimal solution and the processing speed is slow. Moreover, the traditional method only considers the global information of the image and ignores local differences, resulting in image enhancement. Weak ability and poor stability.
A grayscale image enhancement method based on adaptive particle swarm algorithm is adopted. By defining an image conversion function including the global average value of pixels, local average value and adjustable parameters, and using the adaptive particle swarm algorithm to determine the parameter values, combined with K-Means clustering class and Kalinsky-Harabas index to achieve the protection of image information and the enhancement of contours.
Without losing the amount of image information, the image outline is strengthened to achieve an adaptive balance between global search and local mining, avoid the blindness of manual adjustment of parameters, and improve the stability and solution efficiency of the algorithm.
Smart Images

Figure CN114972060B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of image processing technology, and in particular to a grayscale image enhancement method and device based on an adaptive particle swarm algorithm. Background Art
[0002] With the development of society, intelligent information management has become a development trend, among which video and image processing is an important part of intelligent information management. In the process of video recording, the image will be noisy due to the influence of the shooting environment, and the contrast between different areas in the image may not be strong enough, which is not conducive to the interpretation of the image and subsequent image analysis. Therefore, image enhancement technology is needed to preprocess the image, remove the noise of the image and highlight the important information in the image, so as to improve the accuracy of subsequent image operations such as image segmentation. In the process of image enhancement, due to the large randomness of human eye observation, it is impossible to objectively judge the quality of image enhancement. Therefore, the image processing process is often set in advance, and the intelligent optimization algorithm is used for automatic operation, which has high image processing efficiency and good effect. At present, in the field of image enhancement, the optimization algorithm used is complex in structure and poor in robustness. The parameter change of the basic optimization algorithm is not flexible, and it is easy to fall into the local optimal solution in the later stage of iteration, resulting in weak image enhancement ability and poor stability; the parallel or serial optimization algorithm takes a long time, the processing speed is slow, and the processing efficiency is not satisfactory. On the other hand, when constructing the image conversion function, only the global information of the image is often considered or only one index of the image is selected, ignoring the local differences of the image. Therefore, developing a grayscale image enhancement method and device based on an adaptive particle swarm algorithm that can effectively overcome the defects in the above-mentioned related technologies has become a technical problem that needs to be urgently solved in the industry. Summary of the invention
[0003] In view of the above problems existing in the prior art, an embodiment of the present invention provides a grayscale image enhancement method and device based on an adaptive particle swarm algorithm.
[0004] In the first aspect, an embodiment of the present invention provides a grayscale image enhancement method based on an adaptive particle swarm algorithm, including: S1: defining an image conversion function, through which an input grayscale image will be enhanced; S2: determining parameter values in the image conversion function through an adaptive particle swarm algorithm, and obtaining a clearer image contour while ensuring the amount of image information; S3: outputting an enhanced grayscale image through the image conversion function according to the parameter values determined by the adaptive particle swarm algorithm.
[0005] Based on the content of the above method embodiment, the grayscale image enhancement method based on the adaptive particle swarm algorithm provided in the embodiment of the present invention, in step S1, the image conversion function includes the global average value of pixels, the local average value of pixels, the local standard deviation of pixels and four adjustable parameters, and the calculation formula is:
[0006]
[0007]
[0008]
[0009]
[0010] Among them, a, b, c and k are four adjustable parameters, and their values are determined according to the adaptive particle swarm algorithm; G is the global average value of pixels; m(i,j) and σ(i,j) are the grayscale value average and grayscale value standard deviation of the pixel at the (i,j) position of the input grayscale image within the range of n×n, respectively, and n is an integer greater than 1 and less than 20; f(i,j) is the grayscale value of the pixel at the (i,j) position of the input grayscale image; g(i,j) is the grayscale value of the pixel at the (i,j) position of the input grayscale image after image enhancement, and M×N is the length and width of the image; f(x,y) is the grayscale value of the pixel at the (x,y) position of the input grayscale image within the range of n×n.
[0011] Based on the content of the above method embodiment, the grayscale image enhancement method based on the adaptive particle swarm algorithm provided in the embodiment of the present invention, in step S2, the adaptive particle swarm algorithm includes:
[0012] S2.1: Parameter initialization, including objective function, solution dimension, number of particles N, iteration limit T, subgroup number upper limit Z, subgroup particle number lower limit n min , structure update interval t update 、Search range[X min ,X max ]、Speed range [V min ,V max ]、Inertia weight variation range [ω l ,ω u ], the first acceleration factor variation range [c 1l ,c 1u ], the second acceleration factor range [c 2l ,c 2u ], the third acceleration factor variation range [c 3l ,c 3u ];
[0013] Among them, the objective function is used to measure the degree of image enhancement. The larger its value, the better the image enhancement effect. The solution dimension is the number of parameters to be determined. In this method, a, b, c and k need to be solved, and the dimension is fixed to four. The number of particles N represents the number of potential solutions. The position of a particle in the solution space is the specific size of the four parameters. Therefore, a particle represents a potential solution. The solution space consists of the upper and lower limits of the values of the four parameters. The iteration upper limit T is the set algorithm termination condition. The upper limit of the number of subgroups Z is the maximum number of groups when the subsequent K-Means clustering algorithm groups particles. Each group of particles after the grouping is completed is called a subgroup. The lower limit of the number of subgroup particles n min is to ensure that each subgroup contains no less than n min particles; structure update interval t update The meaning is that every time t update Each iteration step triggers the K-Means clustering algorithm once; the search range is the upper and lower limits of the values of the four parameters; the speed range is used to limit the amplitude of the position change of the particle in each iteration; the inertia weight ω, the first acceleration factor c1, the second acceleration factor c2 and the third acceleration factor c3 are the four parameters of the speed iteration formula in the adaptive particle swarm algorithm, and the size is adaptively adjusted within the set range of change;
[0014] S2.2: Divide the particle swarm into multiple subgroups using the K-Means clustering algorithm, repeat 100 times to obtain sufficient grouping results and calculate the Kalinsky-Harabas index, and select the number of subgroups Z corresponding to the maximum value of the Kalinsky-Harabas index set The K-Means clustering algorithm is used to complete this division. The number of cluster centers in this division process is fixed at Z. set ;
[0015] K-Means clustering algorithm: Generate Z cluster centers at random positions in space, group particles according to their distance from each cluster center, and when there are fewer than n particles in a group, min When , the number of cluster centers decreases by 1 and all particles are regrouped until the number of particles in all subgroups meets the requirement. After the division is completed, the new cluster center position is calculated; when the positions of the new and old cluster centers change, the particles are divided again until the positions of the new and old cluster centers coincide, the K-Means clustering algorithm ends and the clustering result is obtained; the calculation formula of the Kalinsky-Harabas index is:
[0016]
[0017] In the formula, Z end is the number of cluster centers after the K-Means clustering algorithm is completed, n z is the number of particles in the zth subgroup, s zis the center position of the z-th subgroup, s is the center position of the solution space, score is the Kalinsky-Harabas index, x i is the position of each particle;
[0018] S2.3: Substitute the initial position of the particle in the solution space into the objective function to obtain the fitness value of the particle, record the position and fitness value of each particle and formally enter the iteration loop. In the iteration loop, update the parameters (ω, c1, c2, c3) in the iteration formula of each particle speed, update the speed, position and fitness value of the particle, and update the individual extreme value p used in the iteration formula of the particle speed. i , subgroup extreme value p z and the global extreme value p g After the update is completed, it is considered as an iteration step. The number of iterations reaches the structure update interval t update Then, the S2.2 operation is performed once, and when the number of iterations reaches the iteration upper limit T, the algorithm stops.
[0019] Based on the content of the above method embodiment, the grayscale image enhancement method based on the adaptive particle swarm algorithm provided in the embodiment of the present invention, after the adaptive particle swarm algorithm stops, takes out the particle with the largest fitness value, and the position of the particle in the solution space is the 4 parameter values determined by the adaptive particle swarm algorithm. The 4 parameters are substituted into the image conversion function to obtain the enhanced grayscale image.
[0020] Based on the content of the above method embodiment, the grayscale image enhancement method based on the adaptive particle swarm algorithm provided in the embodiment of the present invention, the objective function in step S2.1 includes three image features: entropy value, edge strength and edge pixel number, and the calculation formula is:
[0021]
[0022] In the formula, F(I e ) is the objective function; log is the logarithmic function; I e is the enhanced image obtained by the image conversion function; I s isI e Edge image obtained by Sobel algorithm; N edg (I s ) is the number of pixels with non-zero pixel values in the edge image; N gray (I s ) is the sum of the pixel values of the edge image, representing the edge strength; the entropy value E(I e ) is calculated as:
[0023]
[0024]
[0025] Among them, h i is the enhanced image I e The frequency of occurrence of gray value i.
[0026] The calculation formula of Sobel algorithm is:
[0027]
[0028]
[0029] Among them, I s,x is the operator in the x direction, I s,y is the operator in the y direction.
[0030] Based on the content of the above method embodiment, in the grayscale image enhancement method based on the adaptive particle swarm algorithm provided in the embodiment of the present invention, the particle velocity update formula and position update formula in step S2.3 are:
[0031]
[0032]
[0033] in, represents the position component of the dth dimension of the i-th particle at the t+1th iteration; represents the velocity component of the dth dimension of the i-th particle at the t+1th iteration; ω t represents the inertia weight at the tth iteration; represents the first acceleration factor of the ith particle in the tth iteration, represents the second acceleration factor of the ith particle in the tth iteration, represents the third acceleration factor of the ith particle in the tth iteration, It represents the individual extreme value of the i-th particle in the t-th iteration, that is, the maximum fitness value of the particle from the beginning of the algorithm to the current iteration step; It represents the subgroup extreme value of the zth subgroup in the tth iteration, that is, the maximum value of the maximum fitness value of the individuals in the subgroup from the appearance of the subgroup to the current iteration step; It represents the global extreme value in the tth iteration, that is, the only maximum fitness value generated among all particles from the beginning of the algorithm to the current iteration step; r1, r2, and r3 are random numbers in the range of [0,1].
[0034] Based on the content of the above method embodiment, in the grayscale image enhancement method based on the adaptive particle swarm algorithm provided in the embodiment of the present invention, the parameters (ω, c1, c2, c3) in the speed iteration formula in step S2.3 will be adjusted with the iteration process, and the calculation formula is:
[0035]
[0036] in, is the gradient of the fitness value.
[0037] In the second aspect, an embodiment of the present invention provides a grayscale image enhancement device based on an adaptive particle swarm algorithm, comprising: a first main module, used to define an image conversion function, through which an input grayscale image will be enhanced; a second main module, used to determine parameter values in the image conversion function through an adaptive particle swarm algorithm, so as to obtain a clearer image contour while ensuring the amount of image information; a third main module, used to output an enhanced grayscale image through the image conversion function according to the parameter values determined by the adaptive particle swarm algorithm.
[0038] In a third aspect, an embodiment of the present invention provides an electronic device, including:
[0039] at least one processor; and
[0040] at least one memory in communication with the processor, wherein:
[0041] The memory stores program instructions that can be executed by the processor, and the processor calls the program instructions to execute the grayscale image enhancement method based on the adaptive particle swarm algorithm provided by any one of the various implementations of the first aspect.
[0042] In a fourth aspect, an embodiment of the present invention provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions enable a computer to execute a grayscale image enhancement method based on an adaptive particle swarm algorithm provided by any one of the various implementation methods of the first aspect.
[0043] The grayscale image enhancement method and device based on the adaptive particle swarm algorithm provided in the embodiment of the present invention improve the deficiency of only considering the global information of the image in traditional image enhancement by considering the local information of the image when constructing the image conversion function, strengthen the image contour without losing the amount of image information, and achieve an adaptive balance between the global search and local mining of the solution space. It not only avoids the blindness of manual adjustment of parameters, but also ensures that the algorithm is in a stable search state and has a higher solution efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, a brief introduction is given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0045] Figure 1 A flow chart of a grayscale image enhancement method based on an adaptive particle swarm algorithm provided in an embodiment of the present invention;
[0046] Figure 2 A schematic diagram of the structure of a grayscale image enhancement device based on an adaptive particle swarm algorithm provided in an embodiment of the present invention;
[0047] Figure 3 A schematic diagram of the physical structure of an electronic device provided by an embodiment of the present invention;
[0048] Figure 4 Schematic diagram of three grayscale images input and image enhancement results obtained by three different methods provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0049] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. In addition, the technical features in the various embodiments or single embodiments provided by the present invention can be arbitrarily combined with each other to form a feasible technical solution. This combination is not subject to the constraints of the sequence of steps and / or the structural composition mode, but must be based on the ability of ordinary technicians in this field to achieve. When the combination of technical solutions is contradictory or cannot be achieved, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection required by the present invention.
[0050] The embodiment of the present invention provides a grayscale image enhancement method based on an adaptive particle swarm algorithm. Figure 1 The method includes: S1: defining an image conversion function, and the input grayscale image will be enhanced through the image conversion function; S2: determining the parameter values in the image conversion function through an adaptive particle swarm algorithm, and obtaining a clearer image contour while ensuring the amount of image information; S3: outputting the enhanced grayscale image through the image conversion function according to the parameter values determined by the adaptive particle swarm algorithm.
[0051] Based on the content of the above method embodiment, as an optional embodiment, the grayscale image enhancement method based on the adaptive particle swarm algorithm provided in the embodiment of the present invention, in step S1, the image conversion function includes the global average value of pixels, the local average value of pixels, the local standard deviation of pixels and four adjustable parameters, and the calculation formula is:
[0052]
[0053]
[0054]
[0055]
[0056] Among them, a, b, c and k are four adjustable parameters, and their values are determined according to the adaptive particle swarm algorithm; G is the global average value of pixels; m(i,j) and σ(i,j) are the grayscale value average and grayscale value standard deviation of the pixel at the (i,j) position of the input grayscale image within the range of n×n, respectively, and n is an integer greater than 1 and less than 20; f(i,j) is the grayscale value of the pixel at the (i,j) position of the input grayscale image; g(i,j) is the grayscale value of the pixel at the (i,j) position of the input grayscale image after image enhancement, and M×N is the length and width of the image; f(x,y) is the grayscale value of the pixel at the (x,y) position of the input grayscale image within the range of n×n.
[0057] Specifically, 100 CT scan images are selected as input images, with a uniform size of 300×300. Figure 4 Column (a) in shows three of the images used in this embodiment. Define an image conversion function. The image conversion function includes a global pixel average, a local pixel average, a local pixel standard deviation, and four adjustable parameters, and the calculation formula is shown in formula (1). m(i,j) and σ(i,j) are the grayscale value average and grayscale value standard deviation of the pixel at the (i,j)th position of the input grayscale image within the range of n×n, that is, the local pixel average and the local pixel standard deviation, n is an integer greater than 1 and less than 20, and in this embodiment n=3; f(i,j) is the grayscale value of the pixel at the (i,j)th position of the input grayscale image; g(i,j) is the grayscale value of the pixel at the (i,j)th position of the input grayscale image after image enhancement. For an image with a length and width size of 300×300, the calculation formulas of m(i,j), σ(i,j) and G are shown in formulas (2), (3) and (4), respectively.
[0058] Based on the content of the above method embodiment, as an optional embodiment, the grayscale image enhancement method based on the adaptive particle swarm algorithm provided in the embodiment of the present invention, in step S2, the adaptive particle swarm algorithm includes:
[0059] S2.1: Parameter initialization, including objective function, solution dimension, number of particles N, iteration limit T, subgroup number upper limit Z, subgroup particle number lower limit n min , structure update interval t update 、Search range[X min ,X max ]、Speed range [V min ,V max ]、Inertia weight variation range [ω l ,ω u ], the first acceleration factor variation range [c 1l ,c 1u ], the second acceleration factor range [c 2l ,c 2u ], the third acceleration factor variation range [c 3l ,c 3u ];
[0060] Among them, the objective function is used to measure the degree of image enhancement. The larger its value, the better the image enhancement effect. The solution dimension is the number of parameters to be determined. In this method, a, b, c and k need to be solved, and the dimension is fixed to four. The number of particles N represents the number of potential solutions. The position of a particle in the solution space is the specific size of the four parameters. Therefore, a particle represents a potential solution. The solution space consists of the upper and lower limits of the values of the four parameters. The iteration upper limit T is the set algorithm termination condition. The upper limit of the number of subgroups Z is the maximum number of groups when the subsequent K-Means clustering algorithm groups particles. Each group of particles after the grouping is completed is called a subgroup. The lower limit of the number of subgroup particles n min is to ensure that each subgroup contains no less than n min particles; structure update interval t update The meaning is that every time t update Each iteration step triggers the K-Means clustering algorithm once; the search range is the upper and lower limits of the values of the four parameters; the speed range is used to limit the amplitude of the position change of the particle in each iteration; the inertia weight ω, the first acceleration factor c1, the second acceleration factor c2 and the third acceleration factor c3 are the four parameters of the speed iteration formula in the adaptive particle swarm algorithm, and the size is adaptively adjusted within the set range of change;
[0061] S2.2: Divide the particle swarm into multiple subgroups using the K-Means clustering algorithm, repeat 100 times to obtain sufficient grouping results and calculate the Kalinsky-Harabas index, and select the number of subgroups Z corresponding to the maximum value of the Kalinsky-Harabas indexset The K-Means clustering algorithm is used to complete this division. The number of cluster centers in this division process is fixed at Z. set ;
[0062] K-Means clustering algorithm: Generate Z cluster centers at random positions in space, group particles according to their distance from each cluster center, and when there are fewer than n particles in a group, min When , the number of cluster centers decreases by 1 and all particles are regrouped until the number of particles in all subgroups meets the requirement. After the division is completed, the new cluster center position is calculated; when the positions of the new and old cluster centers change, the particles are divided again until the positions of the new and old cluster centers coincide, the K-Means clustering algorithm ends and the clustering result is obtained; the calculation formula of the Kalinsky-Harabas index is:
[0063]
[0064] In the formula, Z end is the number of cluster centers after the K-Means clustering algorithm is completed, n z is the number of particles in the zth subgroup, s z is the center position of the z-th subgroup, s is the center position of the solution space, score is the Kalinsky-Harabas index, x i is the position of each particle;
[0065] S2.3: Substitute the initial position of the particle in the solution space into the objective function to obtain the fitness value of the particle, record the position and fitness value of each particle and formally enter the iteration loop. In the iteration loop, update the parameters (ω, c1, c2, c3) in the iteration formula of each particle speed, update the speed, position and fitness value of the particle, and update the individual extreme value p used in the iteration formula of the particle speed. i , subgroup extreme value p z and the global extreme value p g After the update is completed, it is considered as an iteration step. The number of iterations reaches the structure update interval t update Then, the S2.2 operation is performed once, and when the number of iterations reaches the iteration upper limit T, the algorithm stops.
[0066] Specifically, 8 cluster centers are randomly generated in space, and particles are grouped according to their distance from each cluster center. When there are fewer particles in a group than the lower limit of 5 particles in the subgroup, the number of cluster centers is reduced by 1 and all particles are regrouped until the number of particles in all subgroups meets the requirements. After the division is completed, the new cluster center position is calculated. When the positions of the new and old cluster centers change, the particles are divided again until the positions of the new and old cluster centers coincide. The K-Means clustering algorithm ends and the clustering results are obtained. Repeat 100 times to obtain sufficient clustering results. The Kalinsky-Harabas index is calculated by formula (5). The Kalinsky-Harabas index is calculated based on the obtained clustering results, and the number of subgroups Z corresponding to the maximum value of the Kalinsky-Harabas index is selected. set The K-Means clustering algorithm is used to complete this division. The number of cluster centers in this division process is fixed at Z. set .
[0067] Based on the content of the above method embodiment, as an optional embodiment, the grayscale image enhancement method based on the adaptive particle swarm algorithm provided in the embodiment of the present invention, after the adaptive particle swarm algorithm stops, takes out the particle with the largest fitness value, and the position of the particle in the solution space is the 4 parameter values determined by the adaptive particle swarm algorithm. The 4 parameters are substituted into the image conversion function to obtain an enhanced grayscale image.
[0068] Based on the content of the above method embodiment, as an optional embodiment, the grayscale image enhancement method based on the adaptive particle swarm algorithm provided in the embodiment of the present invention, the objective function in step S2.1 includes three image features: entropy value, edge intensity and edge pixel number, and the calculation formula is:
[0069]
[0070] In the formula, F(I e ) is the objective function; log is the logarithmic function; I e is the enhanced image obtained by the image conversion function; I s isI e Edge image obtained by Sobel algorithm; N edg (I s ) is the number of pixels with non-zero pixel values in the edge image; N gray (I s ) is the sum of the pixel values of the edge image, representing the edge strength; the entropy value E(I e ) is calculated as:
[0071]
[0072] Among them, h i is the enhanced image I eThe frequency of occurrence of gray value i.
[0073] The calculation formula of Sobel algorithm is:
[0074]
[0075]
[0076] Among them, I s,x is the operator in the x direction, I s,y is the operator in the y direction.
[0077] Specifically, the solution dimension in this embodiment is 4, the number of particles is set to 100, the upper limit of iteration is set to 2000, the upper limit of the number of subgroups is set to 8, the lower limit of the number of subgroup particles is set to 5, the structure update interval is set to 200, the search ranges of parameters a, b, c and k are [0,1.5], [0,0.5], [0,1] and [0,1.5] respectively, the speed range is set to [-0.25,0.25], the inertia weight variation range is set to [0.5,1], the first acceleration factor variation range is set to [0.5,1.5], the second acceleration factor variation range is [0.5,1.5], and the third acceleration factor variation range is [0.5,1.5]. The objective function includes three image features: entropy value, edge strength and edge pixel number, and the calculation formula is shown in formula (6). Entropy value E(I e The calculation formula of ) is shown in formula (7). The calculation formula of Sobel algorithm is shown in formula (8) and formula (9).
[0078] Based on the content of the above method embodiment, as an optional embodiment, in the grayscale image enhancement method based on the adaptive particle swarm algorithm provided in the embodiment of the present invention, the particle velocity update formula and position update formula in step S2.3 are:
[0079]
[0080]
[0081] in, represents the position component of the dth dimension of the i-th particle at the t+1th iteration; represents the velocity component of the dth dimension of the i-th particle at the t+1th iteration; ω t represents the inertia weight at the tth iteration; represents the first acceleration factor of the ith particle in the tth iteration, represents the second acceleration factor of the ith particle in the tth iteration, represents the third acceleration factor of the ith particle in the tth iteration, It represents the individual extreme value of the i-th particle in the t-th iteration, that is, the maximum fitness value of the particle from the beginning of the algorithm to the current iteration step; It represents the subgroup extreme value of the zth subgroup in the tth iteration, that is, the maximum value of the maximum fitness value of the individuals in the subgroup from the appearance of the subgroup to the current iteration step; It represents the global extreme value in the tth iteration, that is, the only maximum fitness value generated among all particles from the beginning of the algorithm to the current iteration step; r1, r2, and r3 are random numbers in the range of [0,1].
[0082] Specifically, the initial position of the particle in the solution space is substituted into the objective function to obtain the fitness value of the particle. The larger the fitness value, the better the image enhancement effect that can be obtained. The position and fitness value of each particle are recorded and the iteration cycle is formally entered. The number of iterations is increased by 1, and the velocity and position of the particle are updated according to formulas (10) and (11).
[0083] Based on the content of the above method embodiment, as an optional embodiment, in the grayscale image enhancement method based on the adaptive particle swarm algorithm provided in the embodiment of the present invention, the parameters (ω, c1, c2, c3) in the speed iteration formula in step S2.3 will be adjusted with the iteration process, and the calculation formula is:
[0084]
[0085] in, is the gradient of the fitness value.
[0086] Specifically, the fitness value of each particle is calculated according to the new position, the individual extreme value, subgroup extreme value and global extreme value are updated, and the corresponding position is recorded. The parameters ω, c1, c2 and c3 in the update speed iteration formula are calculated as shown in (12). It is determined whether the number of iterations t reaches the structure update interval 200. If so, the particle group is regrouped. If not, the algorithm continues. In this embodiment, one division will be performed when the algorithm starts running. In the process of gradually iterating to the maximum number of iterations T = 2000, a total of 9 divisions will be performed (the algorithm ends when t = 2000 and no division is performed), a total of 10 times. It is determined whether the number of iterations t reaches the iteration upper limit 2000. If so, the algorithm stops. After the algorithm ends, the position of the particle with the largest global fitness value in the solution space is the size of the four parameters determined by the algorithm. Substituting this group of parameters into the image conversion function can obtain an enhanced grayscale image.
[0087] The grayscale image enhancement method of the present invention is compared with other methods. Figure 4 The middle column (b) shows the enhanced image obtained by this method. Figure 4 The middle column (c) shows the enhanced image obtained by the median filter algorithm. Figure 4 The middle column (d) shows the enhanced image obtained by the grayscale average algorithm. From a subjective point of view, the enhanced image obtained by the present invention has clear object contours and uniform pixel values inside the object, while the images obtained by the other two algorithms still have more noise inside and the contrast is reduced due to the reduction of grayscale values.
[0088] In order to objectively verify the effectiveness of the present invention, the signal-to-noise ratio (SNR), peak signal-to-noise ratio (PSNR), and structural similarity (SSIM) are used for comparison. The larger the values of the signal-to-noise ratio and the peak signal-to-noise ratio, the more noise is filtered before and after the image enhancement, and the higher the image quality. The structural similarity comprehensively evaluates whether the image is distorted from three perspectives: brightness, contrast, and structure. The larger the value of this indicator, the higher the image similarity, and the image is not distorted. The experimental data is shown in Table 1 (Grayscale Image Enhancement Evaluation Index Results).
[0089] Table 1
[0090]
[0091]
[0092] From the grayscale image enhancement evaluation index results in Table 1, it can be seen that the SNR, PSNR and SSIM of the image enhancement algorithm of the present invention are the best among the three algorithms. This is mainly because the method can take into account both the global information and the local information of the image. In the optimization process, not only the image information volume is ensured, but also the contour characteristics of the image are considered.
[0093] The grayscale image enhancement method based on the adaptive particle swarm algorithm provided in the embodiment of the present invention improves the deficiency of only considering the global information of the image in traditional image enhancement by considering the local information of the image when constructing the image conversion function, strengthens the image contour without losing the amount of image information, and realizes the adaptive balance between the global search and local mining of the solution space. It not only avoids the blindness of manual adjustment of parameters, but also ensures that the algorithm is in a stable search state and has a higher solution efficiency.
[0094] The implementation basis of each embodiment of the present invention is to implement programmed processing through a device with a processor function. Therefore, in engineering practice, the technical solutions and functions of each embodiment of the present invention can be encapsulated into various modules. Based on this reality, on the basis of the above embodiments, an embodiment of the present invention provides a grayscale image enhancement device based on an adaptive particle swarm algorithm, which is used to execute the grayscale image enhancement method based on an adaptive particle swarm algorithm in the above method embodiment. Figure 2The device includes: a first main module, which is used to define an image conversion function, and the input grayscale image will be enhanced through the image conversion function; a second main module, which is used to determine the parameter values in the image conversion function through an adaptive particle swarm algorithm, and obtain a clearer image contour while ensuring the amount of image information; a third main module, which is used to output the enhanced grayscale image through the image conversion function according to the parameter values determined by the adaptive particle swarm algorithm.
[0095] The grayscale image enhancement device based on the adaptive particle swarm algorithm provided by the embodiment of the present invention adopts Figure 2 Several modules in it improve the deficiency of traditional image enhancement that only considers global information of the image by considering local information of the image when constructing the image conversion function, strengthen the image contour without losing the amount of image information, and realize the adaptive balance between global search and local mining in the solution space. It not only avoids the blindness of manual adjustment of parameters, but also ensures that the algorithm is in a stable search state and has a higher solution efficiency.
[0096] It should be noted that the device in the device embodiment provided by the present invention can be used to implement the method in the above method embodiment as well as the method in other method embodiments provided by the present invention. The only difference is that the corresponding functional modules are set, and the principle is basically the same as the principle of the above device embodiment provided by the present invention. As long as the technical personnel in the field refer to the specific technical solutions in other method embodiments on the basis of the above device embodiment, obtain the corresponding technical means and the technical solutions composed of these technical means by combining technical features, the device in the above device embodiment can be improved on the premise of ensuring the practicality of the technical solution, thereby obtaining the corresponding device class embodiment, which is used to implement the methods in other method class embodiments. For example:
[0097] Based on the content of the above device embodiment, as an optional embodiment, the grayscale image enhancement device based on the adaptive particle swarm algorithm provided in the embodiment of the present invention further includes: a first submodule, which is used to implement the image conversion function in step S1, which includes a global average value of pixels, a local average value of pixels, a local standard deviation of pixels and four adjustable parameters, and the calculation formula is:
[0098]
[0099]
[0100]
[0101]
[0102] Among them, a, b, c and k are four adjustable parameters, and their values are determined according to the adaptive particle swarm algorithm; G is the global average value of pixels; m(i,j) and σ(i,j) are the grayscale value average and grayscale value standard deviation of the pixel at the (i,j) position of the input grayscale image within the range of n×n, respectively, and n is an integer greater than 1 and less than 20; f(i,j) is the grayscale value of the pixel at the (i,j) position of the input grayscale image; g(i,j) is the grayscale value of the pixel at the (i,j) position of the input grayscale image after image enhancement, and M×N is the length and width of the image; f(x,y) is the grayscale value of the pixel at the (x,y) position of the input grayscale image within the range of n×n.
[0103] Based on the content of the above device embodiment, as an optional embodiment, the grayscale image enhancement device based on the adaptive particle swarm algorithm provided in the embodiment of the present invention further includes: a second submodule, which is used to implement the adaptive particle swarm algorithm in step S2, including:
[0104] S2.1: Parameter initialization, including objective function, solution dimension, number of particles N, iteration limit T, subgroup number upper limit Z, subgroup particle number lower limit n min , structure update interval t update 、Search range[X min ,X max ]、Speed range [V min ,V max ]、Inertia weight variation range [ω l ,ω u ], the first acceleration factor variation range [c 1l ,c 1u ], the second acceleration factor range [c 2l ,c 2u ], the third acceleration factor variation range [c 3l ,c 3u ];
[0105] Among them, the objective function is used to measure the degree of image enhancement. The larger its value, the better the image enhancement effect. The solution dimension is the number of parameters to be determined. In this method, a, b, c and k need to be solved, and the dimension is fixed to four. The number of particles N represents the number of potential solutions. The position of a particle in the solution space is the specific size of the four parameters. Therefore, a particle represents a potential solution. The solution space consists of the upper and lower limits of the values of the four parameters. The iteration upper limit T is the set algorithm termination condition. The upper limit of the number of subgroups Z is the maximum number of groups when the subsequent K-Means clustering algorithm groups particles. Each group of particles after the grouping is completed is called a subgroup. The lower limit of the number of subgroup particles n min is to ensure that each subgroup contains no less than n min particles; structure update interval tupdate The meaning is that every time t update Each iteration step triggers the K-Means clustering algorithm once; the search range is the upper and lower limits of the values of the four parameters; the speed range is used to limit the amplitude of the position change of the particle in each iteration; the inertia weight ω, the first acceleration factor c1, the second acceleration factor c2 and the third acceleration factor c3 are the four parameters of the speed iteration formula in the adaptive particle swarm algorithm, and the size is adaptively adjusted within the set range of change;
[0106] S2.2: Divide the particle swarm into multiple subgroups using the K-Means clustering algorithm, repeat 100 times to obtain sufficient grouping results and calculate the Kalinsky-Harabas index, and select the number of subgroups Z corresponding to the maximum value of the Kalinsky-Harabas index set The K-Means clustering algorithm is used to complete this division. The number of cluster centers in this division process is fixed at Z. set ;
[0107] K-Means clustering algorithm: Generate Z cluster centers at random positions in space, group particles according to their distance from each cluster center, and when there are fewer than n particles in a group, min When , the number of cluster centers decreases by 1 and all particles are regrouped until the number of particles in all subgroups meets the requirement. After the division is completed, the new cluster center position is calculated; when the positions of the new and old cluster centers change, the particles are divided again until the positions of the new and old cluster centers coincide, the K-Means clustering algorithm ends and the clustering result is obtained; the calculation formula of the Kalinsky-Harabas index is:
[0108]
[0109] In the formula, Z end is the number of cluster centers after the K-Means clustering algorithm is completed, n z is the number of particles in the zth subgroup, s z is the center position of the z-th subgroup, s is the center position of the solution space, score is the Kalinsky-Harabas index, x i is the position of each particle;
[0110] S2.3: Substitute the initial position of the particle in the solution space into the objective function to obtain the fitness value of the particle, record the position and fitness value of each particle and formally enter the iteration loop. In the iteration loop, update the parameters (ω, c1, c2, c3) in the iteration formula of each particle speed, update the speed, position and fitness value of the particle, and update the individual extreme value p used in the iteration formula of the particle speed. i , subgroup extreme value p z and the global extreme value p gAfter the update is completed, it is considered as an iteration step. The number of iterations reaches the structure update interval t update Then, the S2.2 operation is performed once, and when the number of iterations reaches the iteration upper limit T, the algorithm stops.
[0111] Based on the content of the above-mentioned device embodiment, as an optional embodiment, the grayscale image enhancement device based on the adaptive particle swarm algorithm provided in the embodiment of the present invention also includes: a third sub-module, which is used to take out the particle with the largest fitness value after the adaptive particle swarm algorithm stops. The position of the particle in the solution space is the 4 parameter values determined by the adaptive particle swarm algorithm. The 4 parameters are substituted into the image conversion function to obtain an enhanced grayscale image.
[0112] Based on the content of the above device embodiment, as an optional embodiment, the grayscale image enhancement device based on the adaptive particle swarm algorithm provided in the embodiment of the present invention further includes: a fourth submodule, which is used to implement the objective function in step S2.1, including three image features of entropy value, edge intensity and edge pixel number, and the calculation formula is:
[0113]
[0114] In the formula, F(I e ) is the objective function; log is the logarithmic function; I e is the enhanced image obtained by the image conversion function; I s isI e Edge image obtained by Sobel algorithm; N edg (I s ) is the number of pixels with non-zero pixel values in the edge image; N gray (I s ) is the sum of the pixel values of the edge image, representing the edge strength; the entropy value E(I e ) is calculated as:
[0115]
[0116]
[0117] Among them, h i is the enhanced image I e The frequency of occurrence of gray value i.
[0118] The calculation formula of Sobel algorithm is:
[0119]
[0120]
[0121] Among them, I s,x is the operator in the x direction, Is,y is the operator in the y direction.
[0122] Based on the content of the above device embodiment, as an optional embodiment, the grayscale image enhancement device based on the adaptive particle swarm algorithm provided in the embodiment of the present invention further includes: a fifth submodule, which is used to implement the particle velocity update formula and position update formula in step S2.3 as follows:
[0123]
[0124]
[0125] in, represents the position component of the dth dimension of the i-th particle at the t+1th iteration; represents the velocity component of the dth dimension of the i-th particle at the t+1th iteration; ω t represents the inertia weight at the tth iteration; represents the first acceleration factor of the ith particle in the tth iteration, represents the second acceleration factor of the ith particle in the tth iteration, represents the third acceleration factor of the ith particle in the tth iteration, It represents the individual extreme value of the i-th particle in the t-th iteration, that is, the maximum fitness value of the particle from the beginning of the algorithm to the current iteration step; It represents the subgroup extreme value of the zth subgroup in the tth iteration, that is, the maximum value of the maximum fitness value of the individuals in the subgroup from the appearance of the subgroup to the current iteration step; It represents the global extreme value in the tth iteration, that is, the only maximum fitness value generated among all particles from the beginning of the algorithm to the current iteration step; r1, r2, and r3 are random numbers in the range of [0,1].
[0126] Based on the content of the above device embodiment, as an optional embodiment, the grayscale image enhancement device based on the adaptive particle swarm algorithm provided in the embodiment of the present invention further includes: a sixth submodule, which is used to realize that the parameters (ω, c1, c2, c3) in the speed iteration formula in step S2.3 will be adjusted along with the iteration process, and the calculation formula is:
[0127]
[0128] in, is the gradient of the fitness value.
[0129] The method of the embodiment of the present invention is implemented by relying on electronic devices, so it is necessary to introduce the relevant electronic devices. Based on this purpose, the embodiment of the present invention provides an electronic device, such as Figure 3As shown, the electronic device includes: at least one processor, a communication interface, at least one memory, and a communication bus, wherein at least one processor, the communication interface, and at least one memory communicate with each other through the communication bus. At least one processor can call the logic instructions in at least one memory to execute all or part of the steps of the method provided by the aforementioned various method embodiments.
[0130] In addition, the logic instructions in the at least one memory mentioned above can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each method embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0131] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0132] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0133] The flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the systems, methods and computer program products according to multiple embodiments of the present invention. Based on this understanding, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and sometimes in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of the boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0134] In this patent, the terms "include", "comprises" or any other variation thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of more restrictions, the elements defined by the sentence "includes..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0135] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A grayscale image enhancement method based on an adaptive particle swarm algorithm, characterized in that: include: S1: Define the image conversion function, the input grayscale image will be enhanced by the image conversion function; Wherein, in step S1, the image conversion function includes the global average value of pixels, the local average value of pixels, the local standard deviation of pixels and four adjustable parameters, and the calculation formula is: Among them, a, b, c and k are four adjustable parameters, and their values are determined according to the adaptive particle swarm algorithm; G is the global average value of pixels; and are the input grayscale images. The pixel position is The gray value average and gray value standard deviation within the range, n is an integer greater than 1 and less than 20; is the input grayscale image in The gray value of the pixel at the position; is the input grayscale image in The gray value of the pixel at the position after image enhancement, is the length and width of the image; The input grayscale image is In range Gray value of the pixel at the position S2: Determine the parameter values in the image conversion function through the adaptive particle swarm algorithm to obtain a clearer image contour while ensuring the image information volume; In step S2, the adaptive particle swarm algorithm includes: S2.1: Parameter initialization, including objective function, solution dimension, number of particles N, iteration limit T, subgroup number upper limit Z, subgroup particle number lower limit , Structure update interval , Search range , Speed range , Inertia weight variation range , the first acceleration factor range , the second acceleration factor range , the third acceleration factor range ; Among them, the objective function is used to measure the degree of image enhancement. The larger its value, the better the image enhancement effect. The solution dimension is the number of parameters to be determined. In this method, a, b, c and k need to be solved, and the dimension is fixed to four. The number of particles N represents the number of potential solutions. The position of a particle in the solution space is the specific size of the four parameters. Therefore, a particle represents a potential solution. The solution space consists of the upper and lower limits of the four parameters. The iteration upper limit It is the termination condition of the algorithm; the upper limit of the number of subgroups It is the maximum number of groups when the subsequent K-Means clustering algorithm groups particles. Each group of particles after grouping is called a subgroup. The lower limit of the number of subgroup particles is to ensure that each subgroup contains no less than Particles; structure update interval The meaning is that every time Each iteration step triggers the K-Means clustering algorithm; the search range is the upper and lower limits of the four parameters; the speed range is used to limit the position change of the particle in each iteration; the inertia weight , the first acceleration factor , the second acceleration factor and the third acceleration factor These are the four parameters of the speed iteration formula in the adaptive particle swarm algorithm, and their sizes are adaptively adjusted within the set range; S2.2: Divide the particle swarm into multiple subgroups using the K-Means clustering algorithm, repeat 100 times to obtain sufficient grouping results and calculate the Kalinsky-Harabas index, and select the number of subgroups corresponding to the maximum value of the Kalinsky-Harabas index. The K-Means clustering algorithm is used to complete this division. The number of cluster centers in this division process is fixed as ; K-Means clustering algorithm: Generate Z cluster centers at random positions in space, group particles according to the distance between the particles and each cluster center, and separate them when there are fewer particles in the group. When , the number of cluster centers decreases by 1 and all particles are regrouped until the number of particles in all subgroups meets the requirement. After the division is completed, the new cluster center position is calculated; when the positions of the new and old cluster centers change, the particles are divided again until the positions of the new and old cluster centers coincide, the K-Means clustering algorithm ends and the clustering result is obtained; the calculation formula of the Kalinsky-Harabas index is: In the formula, is the number of cluster centers after the K-Means clustering algorithm is completed, is the number of particles in the zth subgroup, is the center position of the z-th subgroup, s is the center position of the solution space, score is the Kalinsky-Harabas index, is the position of each particle; S2.3: Substitute the initial position of the particle in the solution space into the objective function to obtain the fitness value of the particle, record the position and fitness value of each particle and formally enter the iteration loop. In the iteration loop, update the parameters in the iteration formula of each particle velocity ( ), update the particle's velocity, position, and fitness value, and update the individual extreme value used in the particle velocity iteration formula , subgroup extreme value and global extremum After the update is completed, it is considered an iteration step. The number of iterations reaches the structure update interval Then, the S2.2 operation is performed once. When the number of iterations reaches the iteration upper limit T, the algorithm stops. S3: According to the parameter values determined by the adaptive particle swarm algorithm, the enhanced grayscale image is output through the image conversion function.
2. The grayscale image enhancement method based on the adaptive particle swarm algorithm according to claim 1 is characterized in that: After the adaptive particle swarm algorithm stops, the particle with the largest fitness value is taken out. The position of the particle in the solution space is the four parameter values determined by the adaptive particle swarm algorithm. The four parameters are substituted into the image conversion function to obtain the enhanced grayscale image.
3. The grayscale image enhancement method based on adaptive particle swarm algorithm according to claim 2 is characterized in that: The objective function in step S2.1 includes three image features: entropy value, edge strength and edge pixel number, and the calculation formula is: In the formula, is the objective function; log is the logarithmic function; is the enhanced image obtained by the image conversion function; yes Edge image obtained by Sobel algorithm; is the number of pixels with non-zero pixel values in the edge image; It is the sum of the pixel values of the edge image, representing the edge strength; entropy value The calculation formula is: in, It is an enhanced image The frequency of occurrence of gray value i; The calculation formula of Sobel algorithm is: in, is the operator in the x direction, is the operator in the y direction.
4. The grayscale image enhancement method based on adaptive particle swarm algorithm according to claim 3 is characterized in that: The particle velocity update formula and position update formula in step S2.3 are: in, represents the position component of the dth dimension of the i-th particle at the t+1th iteration; represents the velocity component of the dth dimension of the i-th particle at the t+1th iteration; represents the inertia weight at the tth iteration; represents the first acceleration factor of the ith particle in the tth iteration, represents the second acceleration factor of the ith particle in the tth iteration, represents the third acceleration factor of the ith particle in the tth iteration, It represents the individual extreme value of the i-th particle in the t-th iteration, that is, the maximum fitness value of the particle from the beginning of the algorithm to the current iteration step; It represents the subgroup extreme value of the zth subgroup in the tth iteration, that is, the maximum value of the maximum fitness value of the individuals in the subgroup from the appearance of the subgroup to the current iteration step; It represents the global extreme value in the tth iteration, that is, the only maximum fitness value generated by all particles from the beginning of the algorithm to the current iteration step; , , for A random number in the range.
5. The grayscale image enhancement method based on adaptive particle swarm algorithm according to claim 4 is characterized in that: The parameters in the speed iteration formula in step S2.3 ( ) will be adjusted during the iteration process, and the calculation formula is: in, is the gradient of the fitness value.
6. A grayscale image enhancement device based on an adaptive particle swarm algorithm, the device being used to implement the grayscale image enhancement method based on an adaptive particle swarm algorithm as claimed in claim 1, characterized in that: include: The first main module is used to define an image conversion function, and the input grayscale image will be enhanced by the image conversion function; The second main module is used to determine the parameter values in the image conversion function through the adaptive particle swarm algorithm to obtain a clearer image contour while ensuring the amount of image information; the third main module is used to output the enhanced grayscale image through the image conversion function according to the parameter values determined by the adaptive particle swarm algorithm.
7. An electronic device, characterized in that: include: At least one processor, at least one memory and a communication interface; wherein, The processor, memory and communication interface communicate with each other; The memory stores program instructions that can be executed by the processor, and the processor calls the program instructions to execute the method according to any one of claims 1 to 5.
8. A non-transitory computer-readable storage medium, characterized in that: The non-transitory computer-readable storage medium stores computer instructions, which cause the computer to execute the method of any one of claims 1 to 5.
