Image classification method and device, program product and storage medium
By calculating the image entropy value to adjust parameters, adding Gaussian noise and performing image denoising and sharpening, the problem of poor generalization ability of adversarial samples in existing technologies is solved, and the accuracy and security of image classification are improved.
Patent Information
- Application Number
- CN202510744632.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-05
- Publication Date
- 2025-09-19
AI Technical Summary
Existing technologies have poor generalization capabilities when facing adversarial samples and cannot effectively filter adversarial perturbations in images, affecting the accuracy and security of image classification.
By calculating the image entropy value, the Gaussian parameters, noise reduction parameters and sharpening parameters are dynamically adjusted, Gaussian noise is added, and image noise reduction and Laplace sharpening are performed to weaken the effect of the anti-disturbance and restore the original information of the image.
It improves the generalization ability and classification accuracy of image classification, ensures that the image maintains clarity and structural integrity after noise processing, and enhances the robustness and security of the image classification model.
Smart Images

Figure CN120673138A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of image processing, and in particular to an image classification method, device, program product, and storage medium. Background Art
[0002] With the widespread adoption of deep learning technology in image classification systems, its application in critical areas such as identity verification in banking systems is gaining increasing attention. However, in real-world applications, these systems may face the threat of adversarial examples. Adversarial examples, by adding subtle and imperceptible perturbations to the original image, can cause image classification models to misclassify. Such misclassifications not only impact system performance but can also pose security risks. Therefore, filtering adversarial examples from image classification systems and restoring the original input to improve the robustness and security of deep learning models has become a crucial task in the field of deep learning.
[0003] Most current methods for dealing with adversarial perturbations in images simply assume the size of the adversarial perturbation and directly perform noise reduction on the input image. This approach may not be effective against adversarial examples generated by different attack algorithms, resulting in poor generalization and affecting the final classification results. Summary of the Invention
[0004] Embodiments of the present invention provide an image classification method, device, program product, and storage medium, which can effectively filter out adversarial perturbations in adversarial samples, restore the original information of the image, and improve the generalization ability and classification accuracy of image classification.
[0005] In a first aspect, an embodiment of the present invention provides an image classification method, comprising:
[0006] Get the image to be processed;
[0007] Calculating an image entropy value of the image to be processed based on image information of the image to be processed, and determining Gaussian parameters, noise reduction parameters, and sharpening parameters according to the image entropy value;
[0008] Adding Gaussian noise to each pixel value of the image to be processed based on the Gaussian parameter to obtain a noise superimposed image;
[0009] Performing image denoising on the noise-superimposed image according to a predetermined sliding window, a three-dimensional transformation algorithm, and the denoising parameters to obtain a denoised image corresponding to the image to be processed;
[0010] Performing Laplace sharpening on the denoised image to obtain a sharpened image;
[0011] The sharpened image is input into a predetermined image classification model to obtain an image classification result output by the image classification model, and the image classification result is displayed to a user.
[0012] In a second aspect, an embodiment of the present invention provides an image classification device, comprising:
[0013] An image acquisition module, used for acquiring an image to be processed;
[0014] A first processing module, configured to calculate an image entropy value of the image to be processed based on image information of the image to be processed, and determine Gaussian parameters, noise reduction parameters, and sharpening parameters according to the image entropy value;
[0015] A second processing module is configured to add Gaussian noise to each pixel value of the image to be processed based on the Gaussian parameter to obtain a noise superimposed image;
[0016] a third processing module, configured to perform image denoising on the noise-superimposed image according to a predetermined sliding window, a three-dimensional transformation algorithm, and the denoising parameters, to obtain a denoised image corresponding to the image to be processed;
[0017] a fourth processing module, configured to perform Laplace sharpening on the denoised image to obtain a sharpened image;
[0018] The image classification module is used to input the sharpened image into a predetermined image classification model, obtain the image classification result output by the image classification model, and display the image classification result to the user.
[0019] In a third aspect, an embodiment of the present invention further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, an image classification method as described in any one of the embodiments of the present invention is implemented.
[0020] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the image classification method as described in any one of the embodiments of the present invention.
[0021] In a fifth aspect, an embodiment of the present invention provides a computer program product, comprising a computer program, which, when executed by a processor, implements the image classification method as described in any one of the embodiments of the present invention.
[0022] In an embodiment of the present invention, an image to be processed is obtained; an image entropy value of the image to be processed is calculated based on image information of the image to be processed, and Gaussian parameters, noise reduction parameters, and sharpening parameters are determined based on the image entropy value; Gaussian noise is added to each pixel value of the image to be processed based on the Gaussian parameters to obtain a noise-superimposed image; image noise reduction is performed on the noise-superimposed image based on a predetermined sliding window, a three-dimensional transformation algorithm, and noise reduction parameters to obtain a noise-reduced image corresponding to the image to be processed; Laplace sharpening is performed on the noise-reduced image to obtain a sharpened image; the sharpened image is input into a predetermined image classification model to obtain an image classification result output by the image classification model, and the image classification result is displayed to a user. The method of the embodiment of the present invention dynamically adjusts the Gaussian parameters, noise reduction parameters, and sharpening parameters based on the image entropy value, can automatically adapt to different image types, and ensure the optimality of the processing flow. Random Gaussian noise is superimposed on the image to disrupt the accuracy of the adversarial perturbation. Image noise reduction eliminates the superimposed Gaussian noise and any adversarial perturbation, thereby weakening the effect of the adversarial perturbation. Image sharpening enhances image edges and details, ensuring that images retain clarity and structural integrity after noise processing, thereby ensuring the quality and security of data input into image classification models. This means that embodiments of the present invention can effectively filter out adversarial perturbations in adversarial examples, restore the original image information, and improve the generalization capability and classification accuracy of image classification. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. It should be understood that the following drawings only illustrate certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without paying any creative work.
[0024] Figure 1 A first flow chart of an image classification method provided by an embodiment of the present invention;
[0025] Figure 2 A second flow chart of an image classification method provided by an embodiment of the present invention;
[0026] Figure 3 A schematic structural diagram of an image classification device provided by an embodiment of the present invention;
[0027] Figure 4 A schematic structural diagram of an electronic device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0028] The present invention will be further described in detail below with reference to the accompanying drawings and examples. It will be understood that the specific embodiments described herein are intended only to illustrate the present invention and are not intended to limit the present invention. It should also be noted that, for ease of description, the accompanying drawings only illustrate portions relevant to the present invention, not all structures.
[0029] Figure 1 This is a first flow chart of an image classification method provided by an embodiment of the present invention. The method of the embodiment of the present invention can effectively filter out adversarial perturbations in adversarial samples, restore the original information of the image, and improve the generalization ability and classification accuracy of image classification. The information collected in the method of the embodiment of the present invention is information and data authorized by the first user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of relevant data comply with the relevant laws, regulations and standards of relevant countries and regions, take necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation entrances for the first user to choose to authorize or refuse. The method can be executed by an image classification device provided by an embodiment of the present invention, and the device can be implemented in software and / or hardware. The following embodiments will be described by taking the device integrated in an electronic device as an example. The electronic device can be a server or computer device that carries a banking system, etc., with reference to Figure 1 , the method may specifically include the following steps:
[0030] Step 101: Obtain an image to be processed; calculate an image entropy value of the image to be processed based on image information of the image to be processed, and determine Gaussian parameters, noise reduction parameters, and sharpening parameters according to the image entropy value.
[0031] The image to be processed is the image that needs to be classified. When a user needs to classify an image to be processed, they can upload the image to the system, and the system will receive the uploaded image. The image to be processed can also be an image stored in a database or an image generated in real time by an external system. The system can directly access the image to be processed from the database or access the image to be processed generated in real time by an external system through a pre-defined interface. Image information includes the image type, which can be grayscale or color. Image entropy is an important indicator of image complexity and information content, used to quantify the distribution of pixel values in the image. A higher image entropy indicates more detail and texture in the image, and greater information content; a lower entropy indicates a smoother image, and less information content. The Gaussian parameter is the parameter used when superimposing Gaussian noise on the image to be processed. In this solution, the Gaussian parameter can be the standard deviation of the Gaussian noise. The denoising parameter is the parameter used when denoising the data to be processed. In this solution, the denoising parameter can be a hard threshold. The sharpening parameter is the parameter used when sharpening the data to be processed. In this solution, the sharpening parameter can be a sharpening weight.
[0032] Specifically, after obtaining the image to be processed, the image entropy value of the image to be processed can be calculated according to the image type of the image to be processed, and the optimal Gaussian parameters, noise reduction parameters, and sharpening parameters can be determined according to the image entropy value. In this solution, optionally, the image entropy value of the image to be processed is calculated according to the image type of the image to be processed, including: when the image to be processed is a grayscale image, calculating the probability of each grayscale value of the image to be processed appearing in the image to be processed; calculating the image entropy value based on the probability and a predetermined entropy value formula; when the image to be processed is a color image, respectively calculating the grayscale value probability distribution of the three color channels of the image to be processed; and calculating the image entropy value of each color channel based on the grayscale value probability distribution of each color channel.
[0033] Among them, a grayscale image is an image that contains only intensity information for each pixel. The intensity information can be represented by grayscale values, and the grayscale value ranges from 0 to 255. 0 represents black (darkest) and 255 represents white (brightest). When the image to be processed is a grayscale image, traverse each pixel in the image to be processed and count the number of times each grayscale value (0 to 255) appears. Assume that the total number of pixels in the image to be processed is M×N, and p i represents the probability that the i-th gray value of the image to be processed appears in the image to be processed, then Furthermore, the image entropy value corresponding to each grayscale value of the image to be processed is calculated according to the entropy formula. The entropy formula is: Furthermore, the image entropy values corresponding to all grayscale values are added together to obtain the image entropy value of the image to be processed.
[0034] If the image to be processed is a color image, the grayscale probability distribution of each of the three color channels of the image to be processed is calculated: the red channel, the green channel, and the blue channel. The number of occurrences of each grayscale value (0 to 255) in each color channel is counted, and the image entropy value corresponding to each color channel is calculated using the same method as the image entropy value for the grayscale image. Furthermore, the image entropy values corresponding to the three color channels are averaged to obtain the image entropy value of the image to be processed.
[0035] This solution dynamically adjusts parameters based on image entropy to ensure optimal processing results for both low-complexity smooth images and high-complexity, textured images. This also makes the solution adaptable to different image types, avoiding over- or under-processing and improving the universality and effectiveness of defenses against adversarial examples.
[0036] Specifically, different image entropy values correspond to different Gaussian parameters, noise reduction parameters, and sharpening parameters. The Gaussian parameters, noise reduction parameters, and sharpening parameters of the image to be processed can be determined based on the image type and image entropy value of the image to be processed. In this solution, optionally, the Gaussian parameters, noise reduction parameters, and sharpening parameters are determined based on the image entropy value, including: determining the entropy level of the image to be processed based on the image entropy value and a preset entropy value; and determining the Gaussian parameters, noise reduction parameters, and sharpening parameters based on the entropy level of the image to be processed and a predetermined level parameter mapping table.
[0037] Among them, the entropy value level includes a high level or a low level. The Gaussian parameters, noise reduction parameters and sharpening parameters corresponding to different entropy value levels are defined in the level parameter mapping table. Specifically, after determining the image entropy value, the image entropy value is compared with the preset entropy value. If the image entropy value is greater than or equal to the preset entropy value, the entropy value level of the image to be processed is determined to be a high level. If the image entropy value is less than or equal to the preset entropy value, the entropy value level of the image to be processed is determined to be a low level. Further, the standard deviation of the Gaussian noise corresponding to the entropy value level of the image to be processed is determined in the level parameter mapping table. Exemplarily, if the preset entropy value is 4 and the image entropy value of the image to be processed is 5, then the image entropy value of the image to be processed is determined to be a high level. In the level parameter mapping table, it is determined that the standard deviation of the Gaussian noise corresponding to the entropy value level of the image to be processed is 0.02; the hard threshold is 1; and the sharpening weight is 0.4. If the preset entropy value is 4 and the image entropy value of the image to be processed is 3, then the image entropy value of the image to be processed is determined to be a low level. In the level parameter mapping table, it is determined that the entropy level of the image to be processed corresponds to the standard deviation of Gaussian noise of 0.04, the hard threshold of 1.3, and the sharpening weight of 0.6.
[0038] The Gaussian parameters, noise reduction parameters and sharpening parameters are dynamically adjusted according to the entropy value of the image, which can automatically adapt to different types of images and ensure the optimality of the processing flow.
[0039] Step 102: Add Gaussian noise to each pixel value of the image to be processed based on Gaussian parameters to obtain a noise superimposed image.
[0040] Among them, the Gaussian parameters are parameters used in the process of superimposing Gaussian noise on the processed image. The Gaussian parameters in this scheme include the standard deviation of Gaussian noise, and the noise superimposed image is the image obtained after superimposing Gaussian noise on the processed image. Specifically, Gaussian noise is a random noise whose probability distribution conforms to the normal distribution (Gaussian distribution). In adversarial sample defense, the addition of Gaussian noise can destroy the specificity of adversarial perturbations, thereby reducing the impact of adversarial samples on the classification model. After determining the standard deviation of the Gaussian noise, random noise is added to each pixel value according to the standard deviation of the Gaussian noise and a predetermined noise addition formula to obtain a noise superimposed image. By adding Gaussian noise, the adversarial perturbations in the image are destroyed and masked by random noise, while laying the foundation for subsequent denoising steps.
[0041] Step 103 : performing image denoising on the noise-superimposed image according to a predetermined sliding window, three-dimensional transformation algorithm, and denoising parameters to obtain a denoised image corresponding to the image to be processed.
[0042] The sliding window is used to obtain image blocks of the noise-superimposed image. A three-dimensional transformation algorithm is used to convert a three-dimensional array from the spatial domain to the transform domain, so that noise and useful image information are separated in the transform domain. The three-dimensional transformation algorithm in this solution can be a discrete cosine transform or a discrete wavelet transform. The noise reduction parameter is a parameter used in the noise reduction process of the processed data. The noise reduction parameter in this solution can be a hard threshold. Specifically, after obtaining the noise-superimposed image, the image blocks in the noise-superimposed image can be extracted using a sliding window. For each image block, the similarity between each other image block and the current image block is calculated. Based on the similarity, the blocks with the highest similarity are selected (for example, if there are 20 blocks, the top 15 blocks with the highest similarity are selected). Similar image blocks of the current image block are stacked to obtain a three-dimensional array. The obtained three-dimensional array is subjected to a discrete cosine transform or a discrete wavelet transform to obtain a candidate three-dimensional array. Furthermore, hard threshold processing is performed on each three-dimensional array corresponding to the noise-superimposed image based on the hard threshold to obtain a candidate three-dimensional array after hard threshold processing. The hard threshold processed three-dimensional array is inversely transformed to convert the data in the transform domain back to the spatial domain. The image blocks in the three-dimensional array after the inverse transformation are combined to obtain the denoised image corresponding to the image to be processed.
[0043] Step 104: Perform Laplace sharpening on the denoised image to obtain a sharpened image.
[0044] Laplace sharpening is an image sharpening technique based on the Laplace operator. It detects and enhances image edges by calculating the second-order derivative of the image. Laplace sharpening can significantly enhance image clarity, ensuring that the image remains sufficiently recognizable even after noise processing. Specifically, after obtaining the denoised image, the Laplace operator is applied to calculate the second-order derivative of the image, and the denoised image is Laplace filtered. The denoised image after Laplace filtering is then weighted and combined with the original denoised image to generate the final sharpened image.
[0045] Step 105: Input the sharpened image into a predetermined image classification model, obtain an image classification result output by the image classification model, and display the image classification result to the user.
[0046] The image classification model is pre-trained and used to identify and classify image content, thereby generating image classification results. After obtaining a sharpened image, the sharpened image is fed into the image classification model, which then classifies the sharpened image and generates an image classification result for the image being processed. Furthermore, the system can display the image classification results to the user via a front-end interface.
[0047] The technical solution of this embodiment comprises obtaining an image to be processed; calculating an image entropy value of the image to be processed based on image information of the image to be processed, and determining Gaussian parameters, noise reduction parameters, and sharpening parameters based on the image entropy value; adding Gaussian noise to each pixel value of the image to be processed based on the Gaussian parameters to obtain a noise-superimposed image; performing image denoising on the noise-superimposed image based on a predetermined sliding window, a three-dimensional transformation algorithm, and noise reduction parameters to obtain a noise-reduced image corresponding to the image to be processed; performing Laplace sharpening on the noise-reduced image to obtain a sharpened image; inputting the sharpened image into a predetermined image classification model to obtain an image classification result output by the image classification model, and displaying the image classification result to a user. The technical solution of this embodiment dynamically adjusts the Gaussian parameters, noise reduction parameters, and sharpening parameters based on the image entropy value, and can automatically adapt to different image types to ensure the optimality of the processing flow. Random Gaussian noise is superimposed on the image to disrupt the accuracy of the adversarial perturbation. Image denoising eliminates the superimposed Gaussian noise and any existing adversarial perturbation, weakening the effect of the adversarial perturbation. Image sharpening enhances image edges and details, ensuring that the image retains clarity and structural integrity after noise processing, thereby ensuring the quality and security of the data input into the image classification model. This embodiment effectively filters adversarial perturbations in adversarial examples, restores the original image information, and improves the generalization ability and classification accuracy of image classification.
[0048] Figure 2This is a second flow chart of an image classification method provided by an embodiment of the present invention. This embodiment is a refinement based on the above embodiment. The specific method can be as follows: Figure 2 As shown, the method may include the following steps:
[0049] Step 201: Acquire an image to be processed; calculate an image entropy value of the image to be processed based on image information of the image to be processed, and determine Gaussian parameters, noise reduction parameters, and sharpening parameters according to the image entropy value.
[0050] Step 202: Add Gaussian noise to each pixel value of the image to be processed based on the standard deviation, the pixel value of the image to be processed, and a predetermined noise addition formula to obtain a noise superimposed image.
[0051] Specifically, after obtaining the image to be processed and determining the standard deviation of the Gaussian noise, for each pixel value I(x, y) in the image, a Gaussian random number N(0, σ) with a mean of 0 and a standard deviation of σ can be generated. Furthermore, the following formula is used to add Gaussian noise to each pixel value of the image to be processed: I noisy (x,y)=I(x,y)+N(0,σ),I noisy (x, y) is Gaussian noise.
[0052] Step 203: extract each image block in the noise-superimposed image through a sliding window.
[0053] Among them, the sliding window is used to extract each image block from the noise superposition image for subsequent similar block matching and three-dimensional transformation processing. After obtaining the noise superposition image, each image block in the noise superposition image can be extracted through the sliding window. Exemplarily, the size of the noise superposition image is 24×24, and the size of the sliding window is 8×8. The position of the initial sliding window is (0,0). The first 8×8 image block is extracted from (0,0) through the sliding window. After obtaining the first image block, the sliding window is moved to the right by a step length, the step length of which is equal to the side length of the sliding window, so as to extract the next 8×8 image block, and the operation of extracting image blocks is repeated until the entire noise superposition image is traversed. For a noise superposition image of size 24×24, 3×3=9 image blocks of size 8×8 can be extracted.
[0054] Step 204 : For each image block, calculate the similarity between the current image block and each other image block according to a predetermined similarity calculation method, and determine similar image blocks to the current image block according to the similarities.
[0055] Among them, the similarity calculation method is used to calculate the similarity between two image blocks. The similarity calculation method can be mean square error or normalized cross-correlation, etc. For each image block, an empty similar block list is initialized, and the similar block list is used to store other image blocks (similar image blocks) similar to the current image block. After obtaining each image block, the similarity calculation method is used to calculate the similarity between the previous image block and the other image blocks, and a preset number of similar image blocks are selected according to each similarity. For example, in addition to the current image block, there are 20 image blocks. The top 15 similarity image blocks can be selected as similar image blocks of the current image block, and the similar blocks of the current image block are stored in the similar block list of the current image block.
[0056] Step 205 : performing image denoising on the noise-superimposed image based on similar image blocks of each image block, a hard threshold, and a three-dimensional transformation algorithm to obtain a denoised image.
[0057] A three-dimensional transformation algorithm is used to convert a three-dimensional array from a spatial domain to a transform domain, so that noise and useful image information are separated in the transform domain. The three-dimensional transformation algorithm in this solution can be a discrete cosine transform or a discrete wavelet transform. A denoising parameter is a parameter used in the denoising process of the processed data. The denoising parameter in this solution can be a hard threshold. After obtaining similar image blocks for each image block, image denoising is performed on the noise-superimposed image based on the similar image blocks of each image block, a hard threshold, and the three-dimensional transformation algorithm to obtain a denoised image. In this solution, image denoising is optionally performed on the noise-superimposed image based on the similar image blocks of each image block, a hard threshold, and the three-dimensional transformation algorithm to obtain a denoised image. This includes: determining an initial three-dimensional array corresponding to the image to be processed based on the similar image blocks of each image block, performing a three-dimensional transformation on the three-dimensional array using the three-dimensional transformation algorithm to obtain a candidate three-dimensional array; performing hard thresholding on the candidate three-dimensional array based on the hard threshold, and performing an inverse transformation and image reconstruction on the candidate three-dimensional array after hard thresholding to obtain a denoised image.
[0058] Specifically, after obtaining similar blocks for each image block, for each image block, similar image blocks of the current image block are stacked together to obtain a three-dimensional array, namely the initial three-dimensional array. For example, if each image block has 15 similar blocks, and the size of each similar block is 8×8 pixels, the size of the three-dimensional array corresponding to each image block is 8×8×15. The three-dimensional array is converted from the spatial domain to the transform domain using a discrete cosine transform or a discrete wavelet transform to obtain a candidate three-dimensional array. The candidate three-dimensional array is hard-thresholded according to a determined hard threshold, and components in the candidate three-dimensional array that are less than the hard threshold are set to zero, while components that are greater than the threshold are retained. Furthermore, the candidate three-dimensional array after hard thresholding is inversely transformed. If the candidate three-dimensional array is obtained using a discrete cosine transform, the inverse transform of the discrete cosine transform is used to inversely transform the candidate three-dimensional array after hard thresholding. If the candidate three-dimensional array is obtained using a discrete wavelet transform, the inverse transform of the discrete wavelet transform is used to inversely transform the candidate three-dimensional array after hard thresholding.
[0059] Furthermore, the image blocks corresponding to the inverse transformed three-dimensional array are reconstructed. For example, for each pixel position (x, y), the weighted average of all similar blocks is calculated: Among them, w i is the weight of the i-th similar block (can be pre-set), I den (x, y) represents the pixel position, T' i (x, y) represents the pixel value of the i-th similar block at position (x, y) (determined based on the three-dimensional array after inverse transformation), and k is the total number of similar blocks. Furthermore, a denoised image is obtained based on each pixel position.
[0060] Step 206: Calculate the second-order derivative of the denoised image based on the Laplace operator to obtain an initial sharpened image.
[0061] Laplace sharpening is an image sharpening technique based on the Laplace operator. It detects and enhances the edges of an image by calculating the second-order derivative of the image. The Laplace operator is a discrete second-order derivative operator that can highlight rapidly changing areas (usually edges) in an image, thereby enhancing the contrast of these areas and making the image clearer. Specifically, the Laplace operator can be represented by a 3x3 convolution kernel, for example: Δ represents the Laplace operator. Use the Laplace operator to denoise the image I den Perform convolution operation and calculate the second-order derivative of the denoised image to obtain the initial sharpened image I la =I den *Δ; where I la is the initial sharpened image, and * represents the convolution operation.
[0062] Step 207: Perform weighted combination of the denoised image and the initial sharpened image according to the sharpening weight to obtain a sharpened image.
[0063] The sharpening parameter is a parameter used in the process of sharpening the data to be processed. The sharpening parameter in this solution can be a sharpening weight. Weighted combination can achieve image enhancement or fusion by performing a weighted summation of two images. In Laplace sharpening, by performing a weighted combination of the initial sharpened image and the denoised image, the edge information of the image can be enhanced while avoiding artifacts or noise amplification caused by over-sharpening. Exemplarily, the following formula is used to perform a weighted combination of the initial sharpened image and the denoised image to obtain a sharpened image: I sh =I den +a·I la ; Among them, I sh is the sharpening image, and a is the sharpening weight.
[0064] Step 208: Input the sharpened image into a predetermined image classification model, obtain an image classification result output by the image classification model, and display the image classification result to the user.
[0065] In the technical solution of this embodiment, an image to be processed is obtained; an image entropy value of the image to be processed is calculated based on image information of the image to be processed, and Gaussian parameters, noise reduction parameters, and sharpening parameters are determined based on the image entropy value. Gaussian noise is added to each pixel value of the image to be processed based on the standard deviation, the pixel value of the image to be processed, and a predetermined noise addition formula to obtain a noise superposition image. Image blocks in the noise superposition image are extracted using a sliding window; for each image block, the similarity between the current image block and each other image block is calculated according to a predetermined similarity calculation method, and similar image blocks to the current image block are determined based on each similarity. Image denoising is performed on the noise superposition image based on the similar image blocks, a hard threshold, and a three-dimensional transformation algorithm to obtain a denoised image. The second-order derivative of the denoised image is calculated based on the Laplacian operator to obtain an initial sharpened image; and the denoised image and the initial sharpened image are weightedly combined according to predetermined weight information to obtain a sharpened image. The technical solution of this embodiment, by superimposing Gaussian noise, causes the adversarial perturbation originally hidden in the image to be masked or mixed with random noise, losing its original effect. The randomness of Gaussian noise makes adversarial perturbations no longer specific and purposeful, thus undermining the perturbation's targeted attack on the classification model. By searching for similar image blocks in the image and stacking them together, a three-dimensional data structure is utilized for joint processing. This not only effectively removes the superimposed Gaussian noise, but also weakens or eliminates the adversarial perturbation. Hard thresholding can remove small noise components in the frequency domain and also has a significant effect on removing adversarial perturbations. By calculating the second-order derivative of the image, edge information is highlighted, effectively restoring image details lost through noise reduction. Through sharpening operations, key structures and edges in the image are restored, further ensuring that the image after the entire preprocessing process still has sufficient identification information. In other words, this solution not only improves the model's resistance to adversarial samples, but also ensures the model's classification accuracy for normal images, thereby enhancing the model's robustness and security overall.
[0066] Figure 3 This is a schematic diagram of the structure of an image classification device provided by an embodiment of the present invention, which is suitable for executing the image classification method provided by an embodiment of the present invention. Figure 3 As shown, the device may specifically include:
[0067] An image acquisition module 301 is used to acquire an image to be processed;
[0068] A first processing module 302 is configured to calculate an image entropy value of the image to be processed based on image information of the image to be processed, and determine Gaussian parameters, noise reduction parameters, and sharpening parameters according to the image entropy value;
[0069] A second processing module 303 is configured to add Gaussian noise to each pixel value of the image to be processed based on the Gaussian parameter to obtain a noise superimposed image;
[0070] A third processing module 304 is configured to perform image denoising on the noise-superimposed image according to a predetermined sliding window, a three-dimensional transformation algorithm, and the denoising parameters, to obtain a denoised image corresponding to the image to be processed;
[0071] The fourth processing module 305 is configured to perform Laplace sharpening on the denoised image to obtain a sharpened image.
[0072] The image classification module 306 is configured to input the sharpened image into a predetermined image classification model, obtain an image classification result output by the image classification model, and display the image classification result to a user.
[0073] Optionally, the first processing module 302 is specifically configured to: when the image to be processed is the grayscale image, calculate the probability that each grayscale value of the image to be processed appears in the image to be processed; and calculate the image entropy value based on the probability and a predetermined entropy value formula;
[0074] When the image to be processed is the color image, the grayscale value probability distributions of the three color channels of the image to be processed are calculated respectively; and the image entropy value of each color channel is calculated based on the grayscale value probability distribution of each color channel.
[0075] Optionally, the first processing module 302 is further configured to: determine an entropy level of the image to be processed according to the image entropy value and a preset entropy value; wherein the entropy level includes a high level or a low level;
[0076] The Gaussian parameter, the noise reduction parameter, and the sharpening parameter are determined based on the entropy level of the image to be processed and a predetermined level parameter mapping table.
[0077] Optionally, the second processing module 303 is specifically configured to add Gaussian noise to each pixel value of the image to be processed based on the standard deviation, the pixel value of the image to be processed and a predetermined noise addition formula to obtain a noise superimposed image.
[0078] Optionally, the third processing module 304 is specifically configured to: extract each image block in the noise-superimposed image through the sliding window;
[0079] For each image block, respectively calculating the similarity between the current image block and each other image block according to a predetermined similarity calculation method, and determining similar image blocks of the current image block according to each similarity;
[0080] Image denoising is performed on the noise-superimposed image based on similar image blocks of each image block, the hard threshold, and the three-dimensional transformation algorithm to obtain the denoised image.
[0081] Optionally, the third processing module 304 is further configured to: determine an initial three-dimensional array corresponding to the image to be processed based on similar image blocks of the image blocks, and perform a three-dimensional transformation on the three-dimensional array using the three-dimensional transformation algorithm to obtain a candidate three-dimensional array;
[0082] The candidate three-dimensional array is hard-thresholded based on the hard threshold, and the candidate three-dimensional array after the hard threshold processing is inversely transformed and reconstructed to obtain the denoised image.
[0083] Optionally, the fourth processing module 305 is specifically configured to: calculate the second-order derivative of the denoised image based on a Laplace operator to obtain an initial sharpened image;
[0084] The denoised image and the initial sharpened image are weightedly combined according to the sharpening weight to obtain the sharpened image.
[0085] The image classification device provided in the embodiment of the present invention can execute the image classification method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method. For the contents not fully described in this embodiment, reference can be made to the description of any method embodiment of the present invention.
[0086] An embodiment of the present invention also provides a computer program product.
[0087] Various embodiments of the systems and techniques described herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system-on-chip systems (SOCs), programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer program products, which can include one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0088] Figure 4 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention, referring to Figure 4 , Figure 4 The electronic device 12 shown is only an example and should not limit the functions and scope of use of the embodiments of the present application. Figure 4As shown, electronic device 12 is implemented as a general-purpose computing device. Components of electronic device 12 may include, but are not limited to, one or more processors or processing units 16, system memory 28, and a bus 18 that connects various system components (including system memory 28 and processing unit 16).
[0089] Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, or a local bus using any of a variety of bus architectures. Examples of these architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MAC) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.
[0090] The electronic device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the electronic device 12, including volatile and non-volatile media, removable and non-removable media.
[0091] The system memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. The electronic device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 34 may be configured to read and write non-removable, non-volatile magnetic media ( Figure 4 Not shown, often called a "hard drive"). Although Figure 4 Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 18 via one or more data medium interfaces. The memory 28 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of the various embodiments of the present application.
[0092] A program / utility 40 having a set (at least one) of program modules 46 may be stored, for example, in memory 28. Such program modules 46 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data, each of which, or some combination thereof, may include an implementation of a network environment. Program modules 46 generally implement the functions and / or methods of the embodiments described herein.
[0093] The electronic device 12 may also communicate with one or more external devices 14 (e.g., a keyboard, a pointing device, a display 24, etc.), and may also communicate with one or more devices that enable a first user to interact with the electronic device 12, and / or any device that enables the electronic device 12 to communicate with one or more other computing devices (e.g., a network card, a modem, etc.). Such communication may be performed through an input / output (I / O) interface 22. Furthermore, the electronic device 12 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through a network adapter 20. As shown, the network adapter 20 communicates with the other modules of the electronic device 12 via the bus 18. It should be understood that although Figure 4 Not shown, other hardware and / or software modules may be used in conjunction with the electronic device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RA identification systems, tape drives, and data backup storage systems.
[0094] The processing unit 16 executes various functional applications and data processing by running the program stored in the system memory 28, such as implementing an image classification method provided by an embodiment of the present invention: obtaining an image to be processed; calculating the image entropy value of the image to be processed based on the image information of the image to be processed, and determining Gaussian parameters, noise reduction parameters and sharpening parameters according to the image entropy value; adding Gaussian noise to each pixel value of the image to be processed based on the Gaussian parameters to obtain a noise superposition image; performing image noise reduction on the noise superposition image according to a predetermined sliding window, a three-dimensional transformation algorithm and the noise reduction parameters to obtain a noise reduction image corresponding to the image to be processed; performing Laplace sharpening on the noise reduction image to obtain a sharpened image; inputting the sharpened image into a predetermined image classification model to obtain an image classification result output by the image classification model, and displaying the image classification result to a user.
[0095] An embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon. When executed by a processor, the program implements an image classification method as provided in all embodiments of the present invention: obtaining an image to be processed; calculating an image entropy value of the image to be processed based on image information of the image to be processed, and determining Gaussian parameters, noise reduction parameters, and sharpening parameters based on the image entropy value; adding Gaussian noise to each pixel value of the image to be processed based on the Gaussian parameters to obtain a noise-superimposed image; performing image noise reduction on the noise-superimposed image based on a predetermined sliding window, a three-dimensional transformation algorithm, and the noise reduction parameters to obtain a noise-reduced image corresponding to the image to be processed; performing Laplacian sharpening on the noise-reduced image to obtain a sharpened image; inputting the sharpened image into a predetermined image classification model to obtain an image classification result output by the image classification model, and presenting the image classification result to a user. The computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium may be, for example, but not limited to, an electronic device, apparatus, or device that is electrical, magnetic, optical, electromagnetic, infrared, or semiconductor, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection having one or more conductors, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), optical fibers, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction-executing electronic device, apparatus, or device.
[0096] A computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transfer a program for use by or in conjunction with an instruction-executing electronic device, apparatus, or device.
[0097] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0098] Computer program code for performing the operations of the present invention can be written in one or more programming languages, or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the first user computer, partially on the first user computer, as a separate software package, partially on the first user computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer can be connected to the first user computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0099] Note that the above are only preferred embodiments of the present invention and the technical principles employed. Those skilled in the art will appreciate that the present invention is not limited to the specific embodiments herein, and that various obvious changes, readjustments, and substitutions are possible for those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments and may include many other equivalent embodiments without departing from the scope of the present invention. The scope of the present invention is determined by the scope of the appended claims.
Claims
1. An image classification method, characterized in that: The method comprises: Get the image to be processed; Calculating an image entropy value of the image to be processed based on image information of the image to be processed, and determining Gaussian parameters, noise reduction parameters, and sharpening parameters according to the image entropy value; Adding Gaussian noise to each pixel value of the image to be processed based on the Gaussian parameter to obtain a noise superimposed image; Performing image denoising on the noise-superimposed image according to a predetermined sliding window, a three-dimensional transformation algorithm, and the denoising parameters to obtain a denoised image corresponding to the image to be processed; Performing Laplace sharpening on the denoised image to obtain a sharpened image; The sharpened image is input into a predetermined image classification model to obtain an image classification result output by the image classification model, and the image classification result is displayed to a user.
2. The method according to claim 1, characterized in that The image information includes an image type, and the image type is a grayscale image or a color image; Calculating the image entropy value of the image to be processed based on the image information of the image to be processed includes: When the image to be processed is the grayscale image, calculating the probability that each grayscale value of the image to be processed appears in the image to be processed; and calculating the image entropy value based on the probability and a predetermined entropy value formula; When the image to be processed is the color image, the grayscale value probability distributions of the three color channels of the image to be processed are calculated respectively; and the image entropy value of each color channel is calculated based on the grayscale value probability distribution of each color channel.
3. The method according to claim 1, characterized in that Determining Gaussian parameters, noise reduction parameters, and sharpening parameters according to the image entropy value; Determining an entropy level of the image to be processed according to the image entropy value and a preset entropy value; wherein the entropy level includes a high level or a low level; The Gaussian parameter, the noise reduction parameter, and the sharpening parameter are determined based on the entropy level of the image to be processed and a predetermined level parameter mapping table.
4. The method according to claim 1, wherein The Gaussian parameter includes a standard deviation of the Gaussian noise, and Gaussian noise is added to each pixel value of the image to be processed based on image information of the image to be processed to obtain a noise superimposed image, including: Gaussian noise is added to each pixel value of the image to be processed based on the standard deviation, the pixel value of the image to be processed and a predetermined noise addition formula to obtain a noise superimposed image.
5. The method according to claim 1, wherein The noise reduction parameters include a hard threshold, and image noise reduction is performed on the noise-superimposed image according to a predetermined sliding window, a three-dimensional transformation algorithm, and the noise reduction parameters to obtain a noise-reduced image corresponding to the image to be processed, including: Extracting each image block in the noise superimposed image through the sliding window; For each image block, respectively calculating the similarity between the current image block and each other image block according to a predetermined similarity calculation method, and determining similar image blocks of the current image block according to each similarity; Image denoising is performed on the noise-superimposed image based on similar image blocks of each image block, the hard threshold, and the three-dimensional transformation algorithm to obtain the denoised image.
6. The method according to claim 5, characterized in that Performing image denoising on the noise-superimposed image based on similar image blocks of each image block, the hard threshold, and the three-dimensional transformation algorithm to obtain the denoised image includes: determining an initial three-dimensional array corresponding to the image to be processed based on similar image blocks of each image block, and performing a three-dimensional transformation on the three-dimensional array using the three-dimensional transformation algorithm to obtain a candidate three-dimensional array; The candidate three-dimensional array is hard-thresholded based on the hard threshold, and the candidate three-dimensional array after the hard threshold processing is inversely transformed and reconstructed to obtain the denoised image.
7. The method according to claim 1, characterized in that The sharpening parameters include sharpening weights, and Laplace sharpening is performed on the denoised image to obtain a sharpened image, including: Calculating the second-order derivative of the denoised image based on a Laplace operator to obtain an initial sharpened image; The denoised image and the initial sharpened image are weightedly combined according to the sharpening weight to obtain the sharpened image.
8. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the computer program implements an image classification method according to any one of claims 1 to 7.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the image classification method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the image classification method according to any one of claims 1 to 7 is implemented.