Method for encrypting and decrypting image

By generating and recording the NxN and MxM pixel block encryption matrix of grayscale images, the information loss during image printing and acquisition is used to solve the problems of image sensitive information privacy and tamper-proof, and the secure transmission and storage of images are realized.

CN120378550APending Publication Date: 2025-07-25HUN DUN (FU JIAN) KE JI YOU XIAN GONG SI
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510278041.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-10
Publication Date
2025-07-25

AI Technical Summary

Technical Problem

The prior art is difficult to effectively protect the sensitive information in images to maintain privacy during transmission and storage, and cannot prevent image content from being tampered with and forged.

Method used

By generating a grayscale image and decomposing it into NxN and MxM pixel blocks, the binary information is calculated to obtain the primary and secondary encryption matrix, recorded it to the database, and encrypted using the information loss during image printing and acquisition. Only when the comparison matrix is equal during the decryption process can it be successful.

Benefits of technology

It realizes the privacy protection of images, prevents unauthorized access and tampering, and improves the security and user trust of QR codes and authentication images.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120378550A_ABST
    Figure CN120378550A_ABST
Patent Text Reader

Abstract

The invention relates to a method for encrypting and decrypting an image, which comprises the following steps of: generating an image, processing to obtain a grayscale image, and calculating binary information of the grayscale image to obtain a primary encryption matrix; after printing a gray level image, acquiring the gray level image as a first-level encrypted image Extracting a second-level encryption image from the first-level encryption image, and calculating binary information of the second-level encryption image to obtain a second-level encryption matrix; recording the first-level encryption image, the first-level encryption matrix, the second-level encryption image, the second-level encryption matrix and the ROI region information into a database; the invention also relates to an image decryption process. According to the encrypted image, an unauthorized person who is not granted to the decrypted image can be prevented from accessing or reading the image content, sensitive information in the image is protected, and privacy of the information in the transmission and storage process can be ensured in the two-dimensional code, the identity verification image or the scanning copy and encryption of the confidential document.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of encryption technology, and particularly to a method for encrypting and decrypting images. Background Art

[0002] The encryption and decryption technology of images is of great significance in the field of information security, especially in aspects such as confidential information transmission, digital copyright protection, and identity authentication. With the wide application of two-dimensional codes in fields such as commerce, payment, identity authentication, and information transmission, the image encryption technology for two-dimensional codes has gradually become the focus of research and practice. In addition, other types of images such as trademark Logos and characteristic images also play an important role in information protection and brand anti-counterfeiting. Therefore, the encryption technology for these images has broad application prospects. Summary of the Invention

[0003] The purpose of the present invention is to provide a method for encrypting and decrypting images, which can encrypt images by using image noise, artifacts, and distortion to change the image information during the image printing and acquisition process, and improve the confidentiality of the images.

[0004] The present invention is realized through the following technical solutions:

[0005] A method for encrypting and decrypting images, the encryption process of the image is as follows:

[0006] S1, generate an image, obtain a grayscale image through image preprocessing, decompose the grayscale image into NxN pixel blocks and calculate its binary information to obtain a matrix Q, and record the matrix Q as a primary encryption matrix;

[0007] S2, print the grayscale image and then collect it as a primary encrypted image through a camera. During the printing and collection process, the primary encrypted image has image information loss;

[0008] S3, extract a pixel block A from the primary encrypted image as a secondary encrypted image according to the preset ROI region information, decompose the secondary encrypted image into MxM pixel blocks and calculate its binary information to obtain a matrix R, and record the matrix R as a secondary encryption matrix;

[0009] S4, record the primary encrypted image, the primary encryption matrix, the secondary encrypted image, the secondary encryption matrix, and the ROI region information in a database;

[0010] The decryption process of the image is as follows:

[0011] S5, obtain a decrypted image, obtain a grayscale decrypted image through image preprocessing, decompose the grayscale decrypted image into NxN pixel blocks and calculate its binary information to obtain a primary decryption matrix;

[0012] S6. Compare the first-level decryption matrix with the first-level encryption matrix. If they are equal, proceed to the next step; otherwise, exit the process due to decryption failure.

[0013] S7. Extract the pixel block B from the grayscale decrypted image according to the ROI region information in the database. Decompose the pixel block B into MxM pixel blocks and calculate its binary information to obtain the second-level decryption matrix.

[0014] S8. Compare the second-level decryption matrix with the second-level encryption matrix. If they are equal, the decryption is successful; otherwise, exit the process due to decryption failure.

[0015] Compared with the prior art, the beneficial effects of the present invention are as follows:

[0016] 1. The encrypted image of the present invention can prevent unauthorized personnel who have not been granted the right to decrypt the image from accessing or reading the image content, protecting the sensitive information in the image. Whether it is a QR code, an authentication image, or a scanned copy of a confidential document, encryption can ensure the privacy of information during transmission and storage.

[0017] 2. The encrypted image of the present invention can detect and prevent the image content from being tampered with. Through encryption, any attempt to modify the image content can be identified, thus ensuring the authenticity and integrity of the image, protecting user privacy, and preventing personal information from being illegally obtained and misused.

[0018] 3. When it comes to QR code encryption, this encryption method can also provide an additional privacy protection layer in sensitive applications such as payment and identity authentication, enhancing users' trust in the application system and preventing the illegal acquisition, imitation, and forgery of QR codes. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] Figure 1 is the flowchart of encrypting the image;

[0020] Figure 2 is the schematic diagram of encrypting the image;

[0021] Figure 3 is the flowchart of decrypting the image. DETAILED DESCRIPTION OF THE INVENTION

[0022] The following will describe the present invention in detail with reference to the accompanying drawings, but the protection scope of the present invention is not limited to the following:

[0023] As Figure 1 and Figure 2 shown, a method for encrypting and decrypting an image. The encryption process of the image is as follows:

[0024] S1. Generate an image, obtain a grayscale image through image preprocessing, decompose the grayscale image into NxN pixel blocks, calculate their binary information to obtain matrix Q, and record matrix Q as the first-level encryption matrix;

[0025] S2. After printing the grayscale image, collect it as the first-level encrypted image through a camera. During the printing and collection process, the first-level encrypted image incurs image information loss;

[0026] S3. Extract pixel block A from the first-level encrypted image as the second-level encrypted image according to the preset ROI region information, decompose the second-level encrypted image into MxM pixel blocks, calculate their binary information to obtain matrix R, and record matrix R as the second-level encryption matrix;

[0027] S4. Record the first-level encrypted image, the first-level encryption matrix, the second-level encrypted image, the second-level encryption matrix, and the ROI region information in the database;

[0028] The decryption process of the image is as follows:

[0029] S5. Obtain the decrypted image, obtain the grayscale decrypted image through image preprocessing, decompose the grayscale decrypted image into NxN pixel blocks, and calculate their binary information to obtain the first-level decryption matrix;

[0030] S6. Compare the first-level decryption matrix with the first-level encryption matrix. If they are equal, proceed to the next process; otherwise, exit the process due to decryption failure;

[0031] S7. According to the ROI region information in the database, extract pixel block B from the grayscale decrypted image, decompose pixel block B into MxM pixel blocks, and calculate their binary information to obtain the second-level decryption matrix;

[0032] S8. Compare the second-level decryption matrix with the second-level encryption matrix. If they are equal, the decryption is successful; otherwise, exit the process due to decryption failure.

[0033] Furthermore, the image preprocessing includes image grayscale conversion and image binarization. Image grayscale conversion and image binarization are both conventional techniques, so no further elaboration will be made.

[0034] As Figure 2 shown, in step S1, the grayscale image is decomposed into NxN pixel blocks, where black pixels represent binary 1 and white pixels represent binary 0, and their binary information is a matrix Q with N rows and N columns; similarly, in step S3 when decomposing the second-level encrypted image, and during the decryption process when decomposing the grayscale decrypted image and pixel block B, matrix information is obtained using this rule.

[0035] It should be noted that in the present invention, image noise, artifacts and distortions of images are collectively referred to as a kind of image information loss. Since the image information loss is randomly generated, the first-level decrypted image collected after printing is an image information with randomness and uniqueness. The present invention uses this image information loss to encrypt the image, so that the encrypted image has only a set of image information and matrix information that can be correctly recognized, and the image cannot be copied by means of taking pictures or printing. Only the first-level encrypted image, the second-level encrypted image, the first-level encrypted matrix and the second-level encrypted matrix provided by the system can be matched and recognized successfully, so that the present invention can effectively prevent the tampering and forgery of images, protect the information of images and avoid abuse.

[0036] In the process of printing and collecting images, the generation of image information loss is inevitable:

[0037] During the printing process:

[0038] ① Due to uneven tone changes, noise with uneven transitions appears in the image.

[0039] ② Due to slight errors in ink or toner, the colors of the image may be inconsistent with the original image, manifested as local color offsets or distortions.

[0040] ③ During inkjet or laser printing, due to the inconsistent size of ink droplets during ink diffusion or laser imaging, the image details are blurred or unclear.

[0041] During the collection process:

[0042] ① Photonic Noise: Due to the insufficient light-sensing ability of the sensor under low-light conditions, randomly scattered bright or dark spots appear in the image, usually manifested as "snowflake"-like noise.

[0043] ② Thermal Noise: During long exposures or in high-temperature environments, random currents generated by the internal thermal motion of the image sensor cause noise in the image, especially more obvious in dark areas.

[0044] ③ Quantization Noise: Due to the quantization error of the sensor when digitizing the image signal, the image brightness or color shows a staircase effect, manifested as discontinuous colors or brightness transitions.

[0045] The schematic diagrams of Step 2 and Step 3 are as Figure 2 shown, where the first-level encrypted image is decomposed into a matrix of 20 rows and 20 columns;

[0046] The second-level encrypted image can be decomposed into a matrix A of 2 rows and 2 columns, or can be decomposed into matrix A2 (16 rows and 16 columns);

[0047] Where A1 is the decomposition diagram corresponding to matrix A in the grayscale image before printing and acquisition. It can be seen that the red-marked part in matrix A2 is the image information loss generated after printing and acquisition.

[0048] The ROI region information includes the ROI starting coordinates and the ROI size.

[0049] Further, in step S3, the operation of extracting pixel block A from the first-level encrypted image according to the preset ROI region information includes the following steps:

[0050] S301, define the ROI starting coordinates and the ROI size of the ROI region;

[0051] S302, load the first-level encrypted image, start reading the first-level encrypted image at the ROI starting coordinate position in the first-level encrypted image, and extract the first-level encrypted image of the ROI size region to obtain pixel block A. Similarly, in step S7, the principle of extracting pixel block B from the grayscale decrypted image according to the ROI region information in the database is the same as that of steps S301 - S302. Only by replacing the first-level encrypted image with the grayscale decrypted image and repeating the operations of steps S301 - S302 can it be achieved.

[0052] Further, the image includes a two-dimensional code and a trademark LOGO.

[0053] Further, the two-dimensional code includes common two-dimensional codes such as QR Code (Quick Response Code), Dot Code, DataMatrix, Micro QR Code, Aztec Code, MaxiCode, and Han Xin Code. Generally speaking, the two-dimensional code commonly referred to by the public refers to the QR code, that is, QRCode (Quick Response Code), whose full name is Quick Response Code, and it is a two-dimensional bar code technology widely used in various scenarios. The QR code has the advantages of large information capacity, wide coding range, strong error correction ability, etc., and thus has been widely used in fields such as commodity identification, payment systems, and information storage.

[0054] In summary, the present invention can be applied to the encryption of various images, trademark LOGOs, and two-dimensional codes, further improving the confidentiality of images and trademark LOGOs, protecting user privacy, and preventing personal information from being illegally obtained and misused. In sensitive applications involving payment, identity authentication, etc., this technology can also provide an additional privacy protection layer and enhance users' trust in the application system.

[0055] Although the present invention is illustrated and described by way of specific embodiments and their alternatives, it should be understood that various changes and modifications can be implemented as long as they do not depart from the spirit of the present invention. Therefore, it should be understood that the present invention is not limited in any sense except by the limitations of the appended claims and their equivalent conditions.

Claims

1. A method for encrypting and decrypting an image, characterized in that, The encryption process of the image is as follows: S1. Generate an image, obtain a grayscale image through image preprocessing, decompose the grayscale image into NxN pixel blocks, calculate their binary information to obtain matrix Q, and record matrix Q as the first-level encryption matrix; S2. Print the grayscale image and collect it as the first-level encrypted image through a camera. During the printing and collection process, the first-level encrypted image has image information loss; S3. Take out pixel block A from the first-level encrypted image as the second-level encrypted image according to the preset ROI region information, decompose the second-level encrypted image into MxM pixel blocks, calculate their binary information to obtain matrix R, and record matrix R as the second-level encryption matrix; S4. Record the first-level encrypted image, the first-level encryption matrix, the second-level encrypted image, the second-level encryption matrix, and the ROI region information in the database; The decryption process of the image is as follows: S5. Obtain the decrypted image, obtain the grayscale decrypted image through image preprocessing, decompose the grayscale decrypted image into NxN pixel blocks, and calculate their binary information to obtain the first-level decryption matrix; S6. Compare the first-level decryption matrix with the first-level encryption matrix. If they are equal, proceed to the next process; Otherwise, the decryption fails and the process exits; S7. Take out pixel block B from the grayscale decrypted image according to the ROI region information in the database, decompose pixel block B into MxM pixel blocks, and calculate their binary information to obtain the second-level decryption matrix; S8. Compare the second-level decryption matrix with the second-level encryption matrix. If they are equal, the decryption is successful; Otherwise, the decryption fails and the process exits.

2. The method for encrypting and decrypting an image according to claim 1, wherein: The image preprocessing includes image grayscale conversion and image binarization.

3. The method for encrypting and decrypting an image according to claim 1, wherein: The ROI region information includes the ROI starting coordinates and the ROI size.

4. The method for encrypting and decrypting an image according to claim 3, wherein In step S3, the operation of taking out pixel block A from the first-level encrypted image according to the preset ROI region information includes the following steps: S301. Define the ROI starting coordinates and the ROI size of the ROI region; S302. Load the first-level encrypted image, start reading the first-level encrypted image at the ROI starting coordinate position in the first-level encrypted image, and take out the first-level encrypted image in the ROI size region to obtain pixel block A.

5. The method for encrypting and decrypting an image according to claim 1, wherein: The image includes a QR code and a trademark LOGO.

6. The method for encrypting and decrypting an image according to claim 5, characterized in that: The QR code includes QRCode, Dot Code, and Data Matrix.