Image encryption and decryption methods and electronic devices
By using a flood filling algorithm and color space matrix information processing, combined with RGB and RGBA color spaces, and utilizing a second image with obfuscated information for image encryption, the problem of insufficient image encryption security in existing technologies is solved, achieving higher security and faster deployment.
Patent Information
- Application Number
- CN202310923144.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-25
- Publication Date
- 2026-11-17
- Estimated Expiration
- 2043-07-25
AI Technical Summary
The security of existing image encryption technologies still needs to be improved, and they are difficult to effectively prevent unauthorized access and tampering.
By employing a flood fill algorithm combined with RGB and RGBA color space matrix information, an encrypted image with obfuscated information is created by calculating the overall brightness value of pixels and the opacity value of the alpha channel. This image is then used to further encrypt the image.
It improves the security of image encryption, enables simple and fast deployment and high scalability, and effectively prevents unauthorized access and tampering.
Smart Images

Figure CN117201688B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of image transmission technology, specifically to the fields of image encryption and image decryption, and particularly to an image encryption and decryption method and electronic device. Background Technology
[0002] Image encryption is a technique that processes images using specific algorithms, making them difficult to understand or interpret without authorization. Its purpose is to protect the content of an image and prevent unauthorized access or alteration. Common image encryption methods include symmetric encryption algorithms, asymmetric encryption algorithms, and chaotic encryption algorithms.
[0003] The core principle of image encryption is to transform or replace the pixel data of an image, making it impossible for unauthorized individuals to directly recognize the image content. In other words, image encryption aims to protect the confidentiality and integrity of images, preventing unauthorized access and tampering. Decryption involves reversing the encryption algorithm to restore the original image content.
[0004] Currently, the security of image encryption still needs to be improved. Summary of the Invention
[0005] This disclosure provides an image encryption and decryption method and electronic device that can improve the security of image encryption.
[0006] According to a first aspect of this disclosure, an image encryption method is provided, the method comprising:
[0007] A first image to be encrypted and a second image with obfuscation information are obtained, the first image and the second image having the same width and height; the RGB three-color space matrix information of the first image and the second image are obtained using a flood fill algorithm; based on the RGB three-color space matrix information of the first image, the overall brightness value of each pixel in the first image is calculated; based on a first threshold and the overall brightness value of each pixel in the first image, the alpha channel opacity value of each pixel in the first image is calculated; based on the RGB three-color space matrix information of the first image and the alpha channel opacity value of each pixel in the first image, the four-color space matrix information of the first image with alpha channels is obtained; based on the RGB three-color space matrix information of the second image, the four-color space matrix information of each pixel in the second image is calculated. The overall brightness value; based on the second threshold and the overall brightness value of each pixel in the second image, the alpha channel opacity value of each pixel in the second image is calculated; based on the RGB three-color space matrix information of the second image and the alpha channel opacity value of each pixel in the second image, the four-color space matrix information of the second image with alpha channels is obtained; a completely transparent image with an alpha channel of 0 is created, the width of the completely transparent image is the same as the width of the first image, and the height of the completely transparent image is the same as the height of the first image; after writing the four-color space matrix information of the first image with alpha channels to the completely transparent image through the flood fill algorithm, the four-color space matrix information of the second image with alpha channels is then written to the completely transparent image to obtain an encrypted image after encrypting the first image.
[0008] According to a second aspect of this disclosure, an image decryption method is provided, the method comprising:
[0009] The RGBA four-color space matrix information of the encrypted image is obtained by using a flood filling algorithm. The encrypted image is obtained by encrypting the first image with a second image containing obfuscation information according to the image decryption method described in the first aspect. A grayscale image with an overall brightness value of 0 or 255 for each pixel is created. The RGBA four-color space matrix information of the encrypted image is written into the grayscale image according to the overall brightness value of each pixel in the second image to obtain the decrypted first image.
[0010] According to a third aspect of this disclosure, an image encryption device is provided, the device comprising:
[0011] The acquisition unit is used to acquire a first image to be encrypted and a second image with obfuscated information, wherein the first image and the second image have the same width and height.
[0012] The image processing unit is configured to acquire the RGB three-color space matrix information of the first image and the RGB three-color space matrix information of the second image using a flood fill algorithm; calculate the overall brightness value of each pixel in the first image based on the RGB three-color space matrix information of the first image; calculate the alpha channel opacity value of each pixel in the first image based on a first threshold and the overall brightness value of each pixel in the first image; and obtain the four-color space matrix information of the first image with an alpha channel based on the RGB three-color space matrix information of the first image and the alpha channel opacity value of each pixel in the first image.
[0013] The image processing unit is further configured to calculate the overall brightness value of each pixel in the second image based on the RGB three-color space matrix information of the second image; calculate the alpha channel opacity value of each pixel in the second image based on the second threshold and the overall brightness value of each pixel in the second image; and obtain the four-color space matrix information of the second image with alpha channel based on the RGB three-color space matrix information of the second image and the alpha channel opacity value of each pixel in the second image.
[0014] An image encryption unit is used to create a completely transparent image with an alpha channel of 0. The width of the transparent image is the same as the width of the first image, and the height of the transparent image is the same as the height of the first image. After writing the four-color space matrix information of the first image with an alpha channel to the transparent image using the flood fill algorithm, the four-color space matrix information of the second image with an alpha channel is then written to the transparent image to obtain an encrypted image after encrypting the first image.
[0015] According to a fourth aspect of this disclosure, an image decryption apparatus is provided, the apparatus comprising:
[0016] The acquisition unit is used to acquire the RGBA four-color space matrix information of the encrypted image through a flood filling algorithm. The encrypted image is an image obtained by encrypting the first image with a second image containing obfuscation information according to the image decryption device described in the third aspect.
[0017] The image decryption unit is used to create a grayscale image with an overall brightness value of 0 or 255 for each pixel; based on the overall brightness value of each pixel in the second image, the RGBA four-color space matrix information of the encrypted image is written into the grayscale image to obtain the decrypted first image.
[0018] According to a fifth aspect of this disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the method as described in the first or second aspect.
[0019] According to a sixth aspect of this disclosure, a non-transitory computer-readable storage medium is provided storing computer instructions for causing a computer to perform the method described according to the first or second aspect.
[0020] According to a seventh aspect of this disclosure, a computer program product is provided, comprising a computer program that, when executed by a processor, implements the method according to the first or second aspect.
[0021] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description
[0022] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure. Wherein:
[0023] Figure 1 This is a flowchart illustrating the image encryption method provided in this embodiment of the disclosure;
[0024] Figure 2 A schematic diagram of RGB three-color space matrix information of a first image provided in an embodiment of this disclosure;
[0025] Figure 3 A schematic diagram of RGBA four-color space matrix information of a first image provided in an embodiment of this disclosure;
[0026] Figure 4 A schematic flowchart illustrating the image decryption method provided in this embodiment of the disclosure;
[0027] Figure 5 This is a schematic diagram illustrating the composition of the image encryption device provided in the embodiments of this disclosure;
[0028] Figure 6 This is a schematic diagram illustrating the composition of an image decryption apparatus provided in an embodiment of this disclosure. Detailed Implementation
[0029] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0030] It should be understood that in the embodiments of this disclosure, the character " / " generally indicates that the preceding and following objects are in an "or" relationship. The terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated.
[0031] Image encryption is a technique that processes images using specific algorithms, making them difficult to understand or interpret without authorization. Its purpose is to protect the content of images and prevent unauthorized access or alteration.
[0032] Common image encryption methods include symmetric encryption algorithms, asymmetric encryption algorithms, and chaotic encryption algorithms. Symmetric encryption algorithms use the same key for both encryption and decryption. Common symmetric encryption algorithms include the Advanced Encryption Standard (AES) and the Data Encryption Standard (DES). These algorithms can be applied to image data and offer high encryption performance and security.
[0033] Asymmetric encryption algorithms use public and private keys for encryption and decryption. Unlike symmetric encryption algorithms, asymmetric encryption algorithms use different keys for encryption and decryption. The public key is used for encryption, and the private key is used for decryption. Common asymmetric encryption algorithms include RSA and elliptic curve cryptography (ECC).
[0034] Chaotic encryption algorithms leverage the complex and unpredictable characteristics of chaotic dynamic systems, performing an XOR operation between image data and a chaotic sequence to achieve encryption. Chaotic encryption algorithms possess good randomness and diffusion, providing a high level of security.
[0035] The core principle of image encryption is to transform or replace the pixel data of an image, making it impossible for unauthorized individuals to directly recognize the image content. In other words, image encryption aims to protect the confidentiality and integrity of images, preventing unauthorized access and tampering. Decryption involves reversing the encryption algorithm to restore the original image content.
[0036] Currently, the security of image encryption still needs to be improved.
[0037] In view of this, the present disclosure provides an image encryption method that can effectively improve the security of image encryption, and the image encryption method has the characteristics of simple implementation, rapid deployment, good scalability, and high resource availability.
[0038] In some embodiments, the subject executing the method may be a terminal device with image processing capabilities, a computer, or a server.
[0039] The server can be a single server or a server cluster consisting of multiple servers. In some embodiments, the server cluster can also be a distributed cluster. This disclosure does not limit the specific implementation of the server.
[0040] This disclosure does not restrict the subject of execution of this method.
[0041] For example, the functionality of this method can be implemented through an application or code within an application. The application can be installed on the aforementioned terminal device, server, or computer.
[0042] For example, the application could be an image encryption application, an image transfer application, or a mini-program or plugin. There are no restrictions on the implementation form of the application.
[0043] The image encryption method is illustrated below.
[0044] Figure 1 This is a schematic flowchart illustrating the image encryption method provided in an embodiment of this disclosure. Figure 1 As shown, the method may include S101-S110.
[0045] S101. Obtain the first image to be encrypted and the second image with obfuscated information.
[0046] For example, the first image can be an image that needs to be encrypted. For instance, the first image can be encrypted before it is transmitted to improve the security of the transmission of the first image.
[0047] Obfuscation information refers to information contained in the second image. For example, the second image may include image content different from the first image. When the second image is used to encrypt the first image, the image content of the second image can be used as obfuscation information to encrypt the first image.
[0048] For example, the first image can be a landscape image, and the second image can also be a landscape image, but the landscape content included in the second image and the second image is different. In this case, the landscape content in the second image can be considered as confusing information.
[0049] Optionally, the second image can be any image selected randomly, and this disclosure does not limit the method of obtaining the second image.
[0050] S102. Use the flood filling algorithm to obtain the RGB three-color space matrix information of the first image and the RGB three-color space matrix information of the second image.
[0051] The flood fill algorithm is a fundamental algorithm used in image processing and computer graphics. It involves filling the surrounding pixels with a predetermined fill color value based on the color value of a starting point. Starting from the starting point, the algorithm gradually expands outwards, filling pixels that meet the specified conditions until the entire area is filled or a predetermined termination condition is met.
[0052] RGB (Red, Green, Blue) is a commonly used color model for representing colors in digital images. In the RGB color space, colors are described by three components: red (R), green (G), and blue (B). Each component typically ranges from 0 to 255, representing the intensity or lightness of the color.
[0053] The matrix information in the RGB color space refers to representing the color value of each pixel in an image as a matrix. Suppose an image has a width of W and a height of H. For each pixel (x, y), its RGB color value can be represented as a 3D vector, i.e., (R, G, B). Then, the entire image can be represented as a 3D matrix M, with a size of W × H × 3, meaning the width of the matrix is the image width multiplied by 3, and the height is the image height.
[0054] Each element in matrix M represents the color value of the corresponding pixel in the image. For example, M(x, y, 0) represents the red component value of the pixel at position (x, y), M(x, y, 1) represents the green component value, and M(x, y, 2) represents the blue component value.
[0055] In S102, the RGB three-color space matrix information of the first image and the RGB three-color space matrix information of the second image can be extracted respectively by the flood filling algorithm.
[0056] S103. Calculate the overall brightness value of each pixel in the first image based on the RGB three-color space matrix information of the first image.
[0057] The overall brightness value can be used for various image processing tasks, such as brightness adjustment, image enhancement, and grayscale conversion.
[0058] In some embodiments, S103 may specifically include: for each pixel in the first image, summing the brightness values of the R channel, G channel, and B channel with the weight of the brightness value of the R (red) channel as the first weight, the weight of the brightness value of the G (green) channel as the second weight, and the weight of the brightness value of the B (blue) channel as the third weight, and taking the average of the summation results to obtain the overall brightness value of each pixel in the first image.
[0059] For example, the overall brightness value of each pixel in the first image can be calculated using the following formula (1).
[0060] L=(a1*r+a2*g+a3*b) / 3 Formula (1)
[0061] In the above formula (1), * means multiplication; a1 represents the first weight, a2 represents the second weight, a3 represents the third weight, and a1, a2, and a3 are all numbers greater than 0; r, g, and b represent the RGB channel brightness values of each pixel in the first image, and L represents the overall brightness value of each pixel in the first image.
[0062] In other embodiments, the first weight, second weight, third weight, etc., mentioned above may all be 1, and this is not a limitation.
[0063] S104. Based on the first threshold and the overall brightness value of each pixel in the first image, calculate the alpha channel opacity value of each pixel in the first image.
[0064] For example, the first threshold can be 100, 90, 80, etc., and there is no limitation on the size of the first threshold. The alpha channel can also be simply referred to as the A channel.
[0065] In some embodiments, S104 may include: subtracting a first threshold from the overall brightness value of each pixel in the first image to obtain the alpha channel opacity value of each pixel in the first image. That is, adding 0 to the overall brightness value of each pixel in the first image and then subtracting the first threshold to obtain the alpha channel opacity value (referred to as the alpha channel value) of each pixel in the first image.
[0066] In other embodiments, S104 may also include: subtracting the overall brightness value of each pixel in the first image from 255, and then subtracting the first threshold to obtain the alpha channel opacity value of each pixel in the first image.
[0067] The aforementioned 255 / 0 can also be referred to as the decrypted color value. This disclosure does not limit the specific calculation method of the alpha channel opacity value of each pixel in the first image.
[0068] S105. Based on the RGB three-color space matrix information of the first image and the alpha channel opacity value of each pixel in the first image, obtain the four-color space matrix information of the first image with alpha channels.
[0069] For example, the alpha channel opacity value of each pixel in the first image can be used as the value of the A channel, and together with the RGB three-color space matrix information, they can form the RGBA four-color space matrix information. The RGBA four-color space matrix information is the four-color space matrix information of the first image with the alpha channel (A channel).
[0070] For example, Figure 2 This is a schematic diagram of the RGB three-color space matrix information of a first image provided in an embodiment of the present disclosure. Figure 3 This is a schematic diagram of the RGBA four-color space matrix information of a first image provided in an embodiment of this disclosure. Figure 2 As shown, the schematic diagram of the RGB three-color space matrix information of the first image can include: the values of the RGB three channels for each pixel. For example... Figure 3 As shown, the RGBA four-color space matrix information of the first image can include the values of the four RGBA channels.
[0071] S106. Calculate the overall brightness value of each pixel in the second image based on the RGB three-color space matrix information of the second image.
[0072] The method for calculating the overall brightness value of each pixel in the second image can be referenced from the method for calculating the overall brightness value of each pixel in the first image.
[0073] For example, S106 may specifically include: for each pixel in the second image, summing the brightness values of the R channel, G channel, and B channel with the weight of the brightness value of the R (red) channel as the fourth weight, the weight of the brightness value of the G (green) channel as the fifth weight, and the weight of the brightness value of the B (blue) channel as the sixth weight, and taking the average of the summing results to obtain the overall brightness value of each pixel in the second image.
[0074] Optionally, the fourth, fifth, and sixth weights mentioned above can all be 1, without any restriction.
[0075] S107. Based on the second threshold and the overall brightness value of each pixel in the second image, calculate the alpha channel opacity value of each pixel in the second image.
[0076] For example, the second threshold can be 60, 70, 80, etc., and there is no limitation on the size of the second threshold. The first threshold and the second threshold can be different or the same. When the first threshold and the second threshold are different, the encryption effect is better.
[0077] The calculation method for the alpha channel opacity value of each pixel in the second image is similar to that used in the first image. The difference is that the methods used are reversed.
[0078] For example, when adding the overall brightness value of each pixel in the first image to 0 and then subtracting the first threshold to obtain the alpha channel opacity value of each pixel in the first image, S107 may include: subtracting the overall brightness value of each pixel in the second image to 255 and then subtracting the second threshold to obtain the alpha channel opacity value of each pixel in the second image.
[0079] When subtracting the overall brightness value of each pixel in the first image from 255, and then subtracting the first threshold to obtain the alpha channel opacity value of each pixel in the first image, step S107 may include: subtracting the second threshold from the overall brightness value of each pixel in the second image to obtain the alpha channel opacity value of each pixel in the second image. That is, adding 0 to the overall brightness value of each pixel in the second image, and then subtracting the second threshold to obtain the alpha channel opacity value of each pixel in the second image.
[0080] S108. Based on the RGB three-color space matrix information of the second image and the alpha channel opacity value of each pixel in the second image, obtain the four-color space matrix information of the second image with alpha channels.
[0081] The four-color space matrix information of the second image with the alpha channel can be found by referring to the four-color space matrix information of the first image with the alpha channel mentioned above, and will not be repeated here.
[0082] S109. Create a completely transparent image with an alpha channel of 0. The width of the completely transparent image is the same as the width of the first image, and the height of the completely transparent image is the same as the height of the first image.
[0083] A completely transparent image with an alpha channel of 0 means that all pixels have a value of 0 in both the RGB color channels and the alpha channel. In a 4-channel RGBA image, each pixel consists of four channels: red, green, blue, and alpha, with the alpha channel controlling transparency. When the alpha channel value is 0, the pixel is completely transparent. Such an image will be completely invisible because all pixels are transparent, and nothing can be seen. In computer graphics processing, this type of image is often used to create masks, overlays, or as a transparent background when overlaying images.
[0084] S110. After writing the four-color space matrix information of the first image with the alpha channel to the pure transparent image using the flood filling algorithm, the four-color space matrix information of the second image with the alpha channel is then written to the pure transparent image to obtain the encrypted image after encrypting the first image.
[0085] For example, by writing the four-color space matrix information of the first image with the alpha channel to the pure transparent image using the flood filling algorithm, and then writing the four-color space matrix information of the second image with the alpha channel to the pure transparent image, the image can be saved as an image with the RGBA four-color space, thus obtaining an encrypted image.
[0086] This disclosure combines encrypting a first image with a second image containing obfuscated information, which can effectively improve the security of image encryption. Furthermore, this image encryption method is characterized by its simplicity, rapid deployment, good scalability, and high resource availability.
[0087] In some possible scenarios, the solutions provided in this disclosure can be used in the field of image encryption, without conflicting with existing solutions, achieving higher security and featuring simple implementation, rapid deployment, good scalability, and high resource availability.
[0088] In other possible scenarios, the solutions provided in this disclosure can also be used in the field of CAPTCHA security. The surface obfuscation image can effectively prevent automated robot attacks in a simple and efficient manner.
[0089] In other scenarios, the solutions provided in this disclosure can also be applied to applications with attributes such as social networking and gaming, and have the ability to quickly deploy on both the client and server sides.
[0090] Optionally, the image encryption method may further include: using a key to further encrypt the encrypted image to improve the security of the encryption and its unreadableness during transmission.
[0091] In some possible implementations, the first threshold and the second threshold can be preset values, and there is no restriction on the size of the first threshold and the second threshold.
[0092] In other possible implementations, the first threshold and the second threshold mentioned above can also be dynamic values. For example, the method may further include: before calculating the alpha channel opacity value of each pixel in the first image based on the first threshold and the overall brightness value of each pixel in the first image, summing the overall brightness values of at least two (such as all) pixels in the first image and taking the average value to obtain the first threshold.
[0093] For example, the method may further include: before calculating the alpha channel opacity value of each pixel in the second image based on the second threshold and the overall brightness value of each pixel in the second image, summing the overall brightness values of at least two (such as all) pixels in the second image and taking the average value to obtain the second threshold.
[0094] By dynamically determining the first and second thresholds as described above, the flexibility of the first and second thresholds can be improved, further enhancing the image encryption effect.
[0095] Based on the image encryption method provided in the foregoing embodiments, this disclosure also provides an image decryption method. The image decryption method is described below by way of example.
[0096] Figure 4 This is a schematic flowchart illustrating the image decryption method provided in an embodiment of this disclosure. Figure 4 As shown, the method may include S401-S403.
[0097] S401. Obtain the RGBA four-color space matrix information of the encrypted image through the flood filling algorithm. The encrypted image is the image obtained by encrypting the first image with a second image containing obfuscation information.
[0098] The first and second images have the same width and the same height.
[0099] The RGBA four-color space matrix information can be referred to in the above embodiments and will not be repeated here. The encrypted image can also be called the image to be decrypted. For example, the encrypted image can be the image obtained by encrypting the first image with a second image containing obfuscation information in the above embodiments.
[0100] S402. Create a grayscale image where the overall brightness value of each pixel is 0 or 255.
[0101] S403. Based on the overall brightness value of each pixel in the second image, write the RGBA four-color space matrix information of the encrypted image into the grayscale image to obtain the decrypted first image.
[0102] For example, when writing the RGBA four-color space matrix information of the encrypted image into the grayscale image, the overall brightness value of the corresponding pixel in the second image can be subtracted from the value of the alpha channel in the RGBA four-color space matrix information of the encrypted image to obtain the decrypted first image.
[0103] It should be understood that in this embodiment of the disclosure, the encrypted first image is a grayscale image, containing only brightness information and not color. Correspondingly, the decrypted first image is also a grayscale image.
[0104] In other possible implementations, image enhancement methods can be used to improve the contrast and detail of the black-and-white image (i.e., the decrypted first image, also known as a grayscale image). Then, the black-and-white image is converted to a suitable color space, such as RGB or Lab, to separate brightness and color information. Finally, the missing color information is restored to the black-and-white image through color filling or color mapping. In this way, a decrypted first image with color information can be obtained.
[0105] In an exemplary embodiment, this disclosure also provides an image encryption device that can be used to implement the image encryption method as described in the foregoing embodiments. Figure 5 This is a schematic diagram illustrating the composition of an image encryption device provided in an embodiment of this disclosure. Figure 5 As shown, the device may include: an acquisition unit 501, an image processing unit 502, and an image encryption unit 503.
[0106] The acquisition unit 501 is used to acquire a first image to be encrypted and a second image with obfuscated information, wherein the first image and the second image have the same width and height.
[0107] The image processing unit 502 is used to obtain the RGB three-color space matrix information of the first image and the RGB three-color space matrix information of the second image using a flood fill algorithm; calculate the overall brightness value of each pixel in the first image based on the RGB three-color space matrix information of the first image; calculate the alpha channel opacity value of each pixel in the first image based on a first threshold and the overall brightness value of each pixel in the first image; and obtain the four-color space matrix information of the first image with alpha channels based on the RGB three-color space matrix information of the first image and the alpha channel opacity value of each pixel in the first image.
[0108] The image processing unit 502 is further configured to calculate the overall brightness value of each pixel in the second image based on the RGB three-color space matrix information of the second image; calculate the alpha channel opacity value of each pixel in the second image based on the second threshold and the overall brightness value of each pixel in the second image; and obtain the four-color space matrix information of the second image with alpha channels based on the RGB three-color space matrix information of the second image and the alpha channel opacity value of each pixel in the second image.
[0109] Image encryption unit 503 is used to create a completely transparent image with an alpha channel of 0. The width of the completely transparent image is the same as the width of the first image, and the height of the completely transparent image is the same as the height of the first image. After writing the four-color space matrix information of the first image with an alpha channel to the completely transparent image using a flood filling algorithm, the four-color space matrix information of the second image with an alpha channel is then written to the completely transparent image to obtain an encrypted image after encrypting the first image.
[0110] The image processing unit 502 is specifically used to: for each pixel in the first image, sum the brightness values of the R channel, G channel, and B channel respectively, using the weight of the brightness value of the R channel as the first weight, the weight of the brightness value of the G channel as the second weight, and the weight of the brightness value of the B channel as the third weight, and take the average value of the summation result to obtain the overall brightness value of each pixel in the first image.
[0111] The first, second, and third weights are all 1.
[0112] The image processing unit 502 is specifically used to: for each pixel in the second image, sum the brightness values of the R channel, G channel, and B channel respectively, using the weight of the brightness value of the R channel as the fourth weight, the weight of the brightness value of the G channel as the fifth weight, and the weight of the brightness value of the B channel as the sixth weight, and take the average of the summation results to obtain the overall brightness value of each pixel in the second image.
[0113] The fourth, fifth, and sixth weights are all 1.
[0114] The image processing unit 502 is specifically used to: subtract a first threshold from the overall brightness value of each pixel in the first image to obtain the alpha channel opacity value of each pixel in the first image; and subtract the overall brightness value of each pixel in the second image from 255, and then subtract the second threshold to obtain the alpha channel opacity value of each pixel in the second image.
[0115] The image processing unit 502 is specifically used to: subtract the overall brightness value of each pixel in the first image from 255, and then subtract the first threshold to obtain the alpha channel opacity value of each pixel in the first image; and subtract the second threshold from the overall brightness value of each pixel in the second image to obtain the alpha channel opacity value of each pixel in the second image.
[0116] The image processing unit 502 is further configured to: before calculating the alpha channel opacity value of each pixel in the first image based on the first threshold and the overall brightness value of each pixel in the first image, sum the overall brightness values of at least two pixels in the first image and take the average value to obtain the first threshold; and before calculating the alpha channel opacity value of each pixel in the second image based on the second threshold and the overall brightness value of each pixel in the second image, sum the overall brightness values of at least two pixels in the second image and take the average value to obtain the second threshold.
[0117] In an exemplary embodiment, this disclosure also provides an image decryption apparatus, which can be used to implement the image decryption method as described in the foregoing embodiments. Figure 6 This is a schematic diagram illustrating the composition of an image decryption apparatus provided in an embodiment of this disclosure. Figure 6 As shown, the device may include: an acquisition unit 601 and an image decryption unit 602.
[0118] The acquisition unit 601 is used to acquire the RGBA four-color space matrix information of the encrypted image through the flood filling algorithm. The encrypted image is the image decryption method according to the foregoing embodiment, or the image decryption device according to the foregoing embodiment, which is the image obtained by encrypting the first image with a second image having obfuscation information.
[0119] The image decryption unit 602 is used to create a grayscale image with an overall brightness value of 0 or 255 for each pixel; based on the overall brightness value of each pixel in the second image, the RGBA four-color space matrix information of the encrypted image is written into the grayscale image to obtain the decrypted first image.
[0120] According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.
[0121] In an exemplary embodiment, an electronic device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform an image encryption method or an image decryption method as described in the above embodiments. The electronic device may be the aforementioned computer or server, or a terminal device.
[0122] In an exemplary embodiment, the readable storage medium may be a non-transitory computer-readable storage medium storing computer instructions for causing a computer to execute the image encryption method or the image decryption method described in the above embodiments.
[0123] In an exemplary embodiment, the computer program product includes a computer program that, when executed by a processor, implements the image encryption method or the image decryption method described in the above embodiments.
[0124] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.
[0125] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.
Claims
1. An image encryption method, the method comprising: Obtain a first image to be encrypted and a second image with obfuscation information, wherein the first image and the second image have the same width and height; The RGB three-color space matrix information of the first image and the RGB three-color space matrix information of the second image are obtained by using a flood filling algorithm; Based on the RGB three-color space matrix information of the first image, calculate the overall brightness value of each pixel in the first image; The alpha channel opacity value of each pixel in the first image is calculated based on the first threshold and the overall brightness value of each pixel in the first image. Based on the RGB three-color space matrix information of the first image and the alpha channel opacity value of each pixel in the first image, the four-color space matrix information of the first image with alpha channel is obtained. Based on the RGB three-color space matrix information of the second image, calculate the overall brightness value of each pixel in the second image; Based on the second threshold and the overall brightness value of each pixel in the second image, the alpha channel opacity value of each pixel in the second image is calculated. Based on the RGB three-color space matrix information of the second image and the alpha channel opacity value of each pixel in the second image, the four-color space matrix information of the second image with alpha channel is obtained; Create a completely transparent image with an alpha channel of 0. The width of the transparent image is the same as the width of the first image, and the height of the transparent image is the same as the height of the first image. After writing the four-color space matrix information of the first image with an alpha channel to the pure transparent image using the flood filling algorithm, the four-color space matrix information of the second image with an alpha channel is then written to the pure transparent image to obtain an encrypted image after encrypting the first image.
2. The method according to claim 1, wherein calculating the overall brightness value of each pixel in the first image based on the RGB three-color space matrix information of the first image includes: For each pixel in the first image, the brightness values of the R channel, G channel, and B channel are summed, with the weight of the R channel brightness value as the first weight, the weight of the G channel brightness value as the second weight, and the weight of the B channel brightness value as the third weight. The average of the summation results is then used to obtain the overall brightness value of each pixel in the first image.
3. The method according to claim 2, wherein the first weight, the second weight, and the third weight are all 1.
4. The method according to claim 1, wherein calculating the overall brightness value of each pixel in the second image based on the RGB three-color space matrix information of the second image includes: For each pixel in the second image, the brightness values of the R channel, G channel, and B channel are summed, with the weight of the R channel brightness value as the fourth weight, the weight of the G channel brightness value as the fifth weight, and the weight of the B channel brightness value as the sixth weight. The average of the summation results is then used to obtain the overall brightness value of each pixel in the second image.
5. The method according to claim 4, wherein the fourth weight, the fifth weight, and the sixth weight are all 1.
6. The method according to claim 1, wherein calculating the alpha channel opacity value of each pixel in the first image based on a first threshold and the overall brightness value of each pixel in the first image comprises: The first threshold is subtracted from the overall brightness value of each pixel in the first image to obtain the alpha channel opacity value of each pixel in the first image. The step of calculating the alpha channel opacity value of each pixel in the second image based on the second threshold and the overall brightness value of each pixel in the second image includes: Subtract the overall brightness value of each pixel in the second image from 255, and then subtract the second threshold to obtain the alpha channel opacity value of each pixel in the second image.
7. The method according to claim 1, wherein calculating the alpha channel opacity value of each pixel in the first image based on a first threshold and the overall brightness value of each pixel in the first image comprises: Subtract the overall brightness value of each pixel in the first image from 255, and then subtract the first threshold to obtain the alpha channel opacity value of each pixel in the first image. The step of calculating the alpha channel opacity value of each pixel in the second image based on the second threshold and the overall brightness value of each pixel in the second image includes: The alpha channel opacity value of each pixel in the second image is obtained by subtracting the second threshold from the overall brightness value of each pixel in the second image.
8. The method according to any one of claims 1-7, wherein before calculating the alpha channel opacity value of each pixel in the first image based on a first threshold and the overall brightness value of each pixel in the first image, the method further comprises: The first threshold is obtained by summing the overall brightness values of at least two pixels in the first image and taking the average value. Before calculating the alpha channel opacity value of each pixel in the second image based on the second threshold and the overall brightness value of each pixel in the second image, the method further includes: The second threshold is obtained by summing the overall brightness values of at least two pixels in the second image and taking the average value.
9. An image decryption method, the method comprising: The RGBA four-color space matrix information of the encrypted image is obtained by using a flood filling algorithm. The encrypted image is an image obtained by encrypting the first image with a second image containing obfuscation information according to the image decryption method according to any one of claims 1-8. Create a grayscale image where the overall brightness value of each pixel is 0 or 255; Based on the overall brightness value of each pixel in the second image, the RGBA four-color space matrix information of the encrypted image is written into the grayscale image to obtain the decrypted first image.
10. An electronic device comprising: At least one processor; and a memory communicatively connected to the at least one processor; The memory stores instructions executable by the at least one processor, which, when executed by the at least one processor, enable the at least one processor to perform the method according to any one of claims 1-8, or the method according to claim 9.
Citation Information
Patent Citations
Advertisement pushing method and device, electronic equipment and storage medium
CN115131064A
Method and device for generating visual code using multi-level image
JP2003107995A
