Method and apparatus for encrypting an image, method and apparatus for verifying an image, and system
By selecting and modifying specific pixel points in the image and using the encryption method of difference control, the problem of information loss after image encryption is solved, and an encrypted image processing that can be browsed and verified normally is achieved.
Patent Information
- Application Number
- CN202111599022.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-24
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2041-12-24
AI Technical Summary
Existing image encryption algorithms cause the encrypted images to lose a large amount of information and cannot be browsed normally.
The pixel points to be encrypted are selected from the image based on the pixel point selection rule, and the specified bit value of each pixel point is modified through the encryption rule so that the difference between the first pixel value and the second pixel value of each pixel point does not exceed the specified difference value.
It reduces the loss of image information during the encryption process, ensures that the encrypted image can be browsed normally, and passes verification and uses a specified algorithm to process it.
Smart Images

Figure CN114329539B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing, and particularly to a method for encrypting an image, a method for decrypting an image, an apparatus, and a system. Background Art
[0002] Currently, images can be encrypted. When a user uses the encrypted image, the encrypted image can be verified. After the verification passes, the encrypted image can be used on a specific device, or the encrypted image can be used through a specific algorithm.
[0003] However, the current algorithms for encrypting images greatly damage the integrity of the images, resulting in a large amount of image information being lost in the encrypted images and the encrypted images being unable to be viewed normally. Summary of the Invention
[0004] In order to avoid losing a large amount of image information when encrypting an image, resulting in the encrypted image being unable to be viewed normally, embodiments of this application provide a method for encrypting an image, a method for decrypting an image, an apparatus, and a system. The technical solutions are as follows:
[0005] On the one hand, this application provides a method for encrypting an image, the method including:
[0006] Based on a pixel point selection rule, select S pixel points to be encrypted from a first image, the first image including a first pixel value of each pixel point among the S pixel points, and S is an integer greater than 1;
[0007] Based on an encryption rule, respectively modify the value of a specified bit of each pixel point to the value corresponding to each pixel point indicated by the encryption rule, to obtain a second pixel value of each pixel point, and the difference between the first pixel value and the second pixel value of each pixel point does not exceed a specified difference;
[0008] In the first image, respectively replace the first pixel value of each pixel point with the second pixel value of each pixel point, to obtain a second image.
[0009] Optionally, the step of selecting S pixel points to be encrypted from a first image based on a pixel point selection rule includes:
[0010] Select S consecutive fields from the first image, the i-th field including a first sub-field and a second sub-field, the first sub-field including M bits, the second sub-field including N bits, i = 1, 2,..., S, and both M and N are integers greater than 1;
[0011] Select pixel points with abscissa x i and ordinate y i from the first image, xi The numerical value indicated by the first sub-field in the i-th field, y i The numerical value indicated by the second sub-field in the i-th field.
[0012] Optionally, the selecting of S pixel points to be encrypted from the first image according to the pixel point selection rule includes:
[0013] Dividing the first image based on M and N to obtain a plurality of image blocks, where the width and height of each image block are M and N respectively, and both M and N are integers greater than 1;
[0014] Obtaining the length of the pixel value interval corresponding to each image block, and selecting one image block from the plurality of image blocks as the target image block based on the length of the pixel value interval of each pixel block, where the length of the pixel value interval corresponding to the target image block is the difference between the maximum pixel value and the minimum pixel value in the target image block;
[0015] Selecting S pixel points from the target image block.
[0016] Optionally, the method further includes:
[0017] Obtaining the size information of the first image, and obtaining M and N based on the size information.
[0018] Optionally, the obtaining of M and N based on the size information includes:
[0019] Calculating the value of 2 M closest to the image width and the value of 2 N closest to the image height to obtain M and N, where the image width and the image height are the width and height of the first image respectively.
[0020] Optionally, the selecting of S pixel points to be encrypted from the first image according to the pixel point selection rule includes:
[0021] Determining a target graphic based on a graphic generation rule, where the target graphic is the graphic indicated by the graphic generation rule, the positional relationship between the target graphic and the first image is the positional relationship indicated by the graphic generation rule, the target graphic includes S specified positions, and there are S pixel points in the first image that correspond one-to-one to the S specified positions;
[0022] Selecting the pixel points corresponding to the S specified positions from the first image to obtain the S pixel points.
[0023] Optionally, the encryption rule is used to indicate specified information, and the specified information includes information required for processing the second image. Based on the encryption rule, modifying the value of the specified bit of each pixel point to the value corresponding to each pixel point defined by the encryption rule includes:
[0024] Based on the encryption rule, modifying the bit value of the lowest bit of each of the X pixel points to the value corresponding to each of the X pixel points indicated by the encryption rule to obtain the second pixel value of each of the X pixel points. The X pixel points are the 1st to Xth pixel points, and X is an integer greater than 1 and less than S;
[0025] Setting Y bits to indicate the specified information, where the Y bits include the lowest bit of each of the Y pixel points to obtain the second pixel value of each of the Y pixel points. The Y pixel points are the (X + 1)th to Sth pixel points.
[0026] Optionally, based on the encryption rule, modifying the bit value of the lowest bit of each of the X pixel points to the value corresponding to each of the X pixel points indicated by the encryption rule includes:
[0027] Performing the following steps for each of the X pixel points: adding the abscissa and ordinate of the pixel point to obtain an accumulated value;
[0028] When the accumulated value is even, setting the bit value of the lowest bit of the pixel point to a first bit value to obtain the second pixel value of the pixel point; or when the accumulated value is odd, setting the bit value of the lowest bit of the pixel point to a second bit value to obtain the second pixel value of the pixel point.
[0029] Optionally, the encryption rule is further used to indicate the encryption type and the encryption information corresponding to the encryption type.
[0030] Based on the encryption rule, modifying the bit value of the lowest bit of each of the X pixel points to the value corresponding to each of the X pixel points indicated by the encryption rule includes:
[0031] Setting Z bits to indicate the encryption type, where the Z bits include the lowest bit of each of the Z pixel points. The Z pixel points include the 1st to Zth pixel points, and Z is an integer greater than 1 and less than X, to obtain the second pixel value of each of the Z pixel points;
[0032] Set X-Z bits to indicate the encryption information corresponding to the encryption type. The X-Z bits include the least significant bit of each of the X-Z pixel points, and the X-Z pixel points include the (Z + 1)-th to X-th pixel points, so as to obtain the second pixel value of each of the X-Z pixel points.
[0033] On the other hand, the present application provides a method for verifying an image. The method includes:
[0034] Based on a pixel point selection rule, select S pixel points to be encrypted from a second image. The second image includes the second pixel value of each of the S pixel points. S is an integer greater than 1, and the second image is an encrypted image.
[0035] Based on an encryption rule, modify the value of a specified bit in each of the pixel points to the value corresponding to each of the pixel points indicated by the encryption rule, so as to obtain the third pixel value of each of the pixel points.
[0036] When the second pixel value of each of the pixel points is equal to the third pixel value of each of the pixel points, the verification of the second image passes.
[0037] Optionally, the step of selecting S pixel points to be encrypted from the second image based on the pixel point selection rule includes:
[0038] Select S consecutive fields from the second image. The i-th field includes a first sub-field and a second sub-field. The first sub-field includes M bits, and the second sub-field includes N bits, where i = 1, 2,..., S, and both M and N are integers greater than 1.
[0039] Select a pixel point from the second image with an abscissa of x i and an ordinate of y i . x i is the value indicated by the first sub-field in the i-th field, and y i is the value indicated by the second sub-field in the i-th field.
[0040] Optionally, the step of selecting S pixel points to be encrypted from the second image based on the pixel point selection rule includes:
[0041] Based on M and N, divide the second image to obtain a plurality of image blocks. The width and height of each image block are M and N respectively, and both M and N are integers greater than 1.
[0042] Obtain the length of the pixel value interval corresponding to each of the image blocks, and select one image block from the multiple image blocks as the target image block based on the length of the pixel value interval of each pixel block, where the length of the pixel value interval corresponding to the target image block is the difference between the maximum pixel value and the minimum pixel value in the target image block;
[0043] Select S pixel points from the target image block.
[0044] Optionally, the method further includes:
[0045] Obtain the size information of the second image, and obtain M and N based on the size information.
[0046] Optionally, the obtaining M and N based on the size information includes:
[0047] Calculate the value closest to 2 M of the image width and the value closest to 2 N of the image height to obtain M and N, where the image width and the image height are the width and height of the second image respectively.
[0048] Optionally, the selecting S pixel points to be encrypted from the second image based on the pixel point selection rule includes:
[0049] Based on the graphic generation rule, determine the target graphic, where the target graphic is the graphic indicated by the graphic generation rule, and the positional relationship between the target graphic and the second image is the positional relationship indicated by the graphic generation rule. The target graphic includes S specified positions, and there are S pixel points in the second image that correspond one-to-one to the S specified positions;
[0050] Select the pixel points corresponding to the S specified positions from the second image to obtain the S pixel points.
[0051] Optionally, the encryption rule is used to indicate specified information, where the specified information includes the information required for processing the second image. Based on the encryption rule, modifying the value of the specified bit in each pixel point to the value corresponding to each pixel point indicated by the encryption rule includes:
[0052] Based on the encryption rule, modify the bit value of the lowest bit of each of the X pixel points to the value corresponding to each of the X pixel points indicated by the encryption rule to obtain the third pixel value of each of the X pixel points, where the X pixel points are the first to X pixel points, and X is an integer greater than 1 and less than S;
[0053] Set Y bits to indicate the specified information, where the Y bits include the least significant bit of each of the Y pixel points, so as to obtain the third pixel value of each of the Y pixel points, and the Y pixel points are the (X + 1)-th to S-th pixel points.
[0054] Optionally, based on the encryption rule, modifying the bit value of the least significant bit of each of the X pixel points to the value corresponding to each of the X pixel points indicated by the encryption rule includes:
[0055] Performing the following steps for each of the X pixel points: adding the abscissa and ordinate of the pixel point to obtain an accumulated value;
[0056] When the accumulated value is even, setting the least significant bit value of the pixel point to a first bit value to obtain the second pixel value of the pixel point; or, when the accumulated value is odd, setting the least significant bit value of the pixel point to a second bit value to obtain the second pixel value of the pixel point.
[0057] Optionally, the encryption rule is further used to indicate the encryption type and the encryption information corresponding to the encryption type.
[0058] Based on the encryption rule, modifying the bit value of the least significant bit of each of the X pixel points to the value corresponding to each of the X pixel points indicated by the encryption rule includes:
[0059] Setting Z bits to indicate the encryption type, where the Z bits include the least significant bit of each of the Z pixel points, and the Z pixel points include the 1st to Z-th pixel points, and Z is an integer greater than 1 and less than X, so as to obtain the second pixel value of each of the Z pixel points;
[0060] Setting X - Z bits to indicate the encryption information, where the X - Z bits include the least significant bit of each of the X - Z pixel points, and the X - Z pixel points include the (Z + 1)-th to X-th pixel points, so as to obtain the second pixel value of each of the X - Z pixel points.
[0061] Optionally, the method further includes:
[0062] When the verification of the second image passes, processing the second image based on the specified information.
[0063] On the other hand, the present application provides an apparatus for encrypting an image, and the apparatus includes:
[0064] A selection module, configured to select S pixels to be encrypted from a first image based on a pixel selection rule, where the first image includes a first pixel value of each of the S pixels, and S is an integer greater than 1;
[0065] A modification module, configured to modify the value of a specified bit of each pixel to the value corresponding to each pixel indicated by the encryption rule based on the encryption rule, to obtain a second pixel value of each pixel, and the difference between the first pixel value and the second pixel value of each pixel does not exceed a specified difference;
[0066] A replacement module, configured to replace the first pixel value of each pixel with the second pixel value of each pixel in the first image, to obtain a second image.
[0067] Optionally, the selection module is configured to:
[0068] Select S consecutive fields from the first image, where the i-th field includes a first sub-field and a second sub-field, the first sub-field includes M bits, the second sub-field includes N bits, i = 1, 2,..., S, and both M and N are integers greater than 1;
[0069] Select a pixel with abscissa x i and ordinate y i from the first image, where x i is the value indicated by the first sub-field in the i-th field, and y i is the value indicated by the second sub-field in the i-th field.
[0070] Optionally, the selection module is configured to:
[0071] Divide the first image based on M and N to obtain a plurality of image blocks, where the width and height of each image block are M and N respectively, and both M and N are integers greater than 1;
[0072] Obtain the pixel value interval length corresponding to each image block, and select an image block as a target image block from the plurality of image blocks based on the pixel value interval length of each pixel block, where the pixel value interval length corresponding to the target image block is the difference between the maximum pixel value and the minimum pixel value in the target image block;
[0073] Select S pixels from the target image block.
[0074] Optionally, the apparatus further includes:
[0075] An acquisition module, configured to acquire size information of the first image, and acquire M and N based on the size information.
[0076] Optionally, the obtaining module is configured to:
[0077] Calculate the value closest to 2 times the image width M and the value closest to 2 times the image height N to obtain M and N, where the image width and the image height are the width and height of the first image respectively.
[0078] Optionally, the selection module is configured to:
[0079] Based on the graphic generation rule, determine the target graphic, where the target graphic is the graphic indicated by the graphic generation rule, and the positional relationship between the target graphic and the first image is the positional relationship indicated by the graphic generation rule. The target graphic includes S specified positions, and there are S pixel points in the first image that correspond one-to-one to the S specified positions;
[0080] Select the pixel points corresponding to the S specified positions from the first image to obtain the S pixel points.
[0081] Optionally, the encryption rule is used to indicate specified information, where the specified information includes the information required for processing the second image. The modification module is configured to:
[0082] Based on the encryption rule, modify the least significant bit value of each of the X pixel points to the value corresponding to each of the X pixel points indicated by the encryption rule, to obtain the second pixel value of each of the X pixel points. The X pixel points are the 1st to Xth pixel points, and X is an integer greater than 1 and less than S;
[0083] Set Y bits to indicate the specified information, where the Y bits include the least significant bit of each of the Y pixel points, to obtain the second pixel value of each of the Y pixel points. The Y pixel points are the (X + 1)th to Sth pixel points.
[0084] Optionally, the modification module is configured to:
[0085] For each of the X pixel points, perform the following steps: add the abscissa and ordinate of the pixel point to obtain an accumulated value;
[0086] When the accumulated value is even, set the least significant bit value of the pixel point to the first bit value to obtain the second pixel value of the pixel point; or, when the accumulated value is odd, set the least significant bit value of the pixel point to the second bit value to obtain the second pixel value of the pixel point.
[0087] Optionally, the encryption rule is further configured to indicate an encryption type and encryption information corresponding to the encryption type. The modification module is configured to:
[0088] Set Z bits to indicate the encryption type, where the Z bits include one least significant bit of each of the Z pixel points. The Z pixel points include the first to Zth pixel points, and Z is an integer greater than 1 and less than X, so as to obtain a second pixel value of each of the Z pixel points;
[0089] Set X - Z bits to indicate the encryption information corresponding to the encryption type, where the X - Z bits include one least significant bit of each of the X - Z pixel points. The X - Z pixel points include the (Z + 1)th to Xth pixel points, so as to obtain a second pixel value of each of the X - Z pixel points.
[0090] On the other hand, the present application provides a device for verifying an image. The device includes:
[0091] A selection module, configured to select S pixel points to be encrypted from a second image based on a pixel point selection rule. The second image includes a second pixel value of each of the S pixel points, and S is an integer greater than 1. The second image is an encrypted image;
[0092] A modification module, configured to modify the value of a specified bit in each of the pixel points to the value corresponding to each of the pixel points indicated by the encryption rule based on the encryption rule, so as to obtain a third pixel value of each of the pixel points;
[0093] A verification module, configured to pass the verification of the second image when the second pixel value of each of the pixel points is equal to the third pixel value of each of the pixel points.
[0094] Optionally, the selection module is configured to:
[0095] Select S consecutive fields from the second image. The ith field includes a first sub - field and a second sub - field. The first sub - field includes M bits, and the second sub - field includes N bits, where i = 1, 2, …, S, and both M and N are integers greater than 1;
[0096] Select a pixel point from the second image with an abscissa of x i and an ordinate of y i , where x i is the value indicated by the first sub - field in the ith field, and y i is the value indicated by the second sub - field in the ith field.
[0097] Optionally, the selection module is configured to:
[0098] Divide the second image based on M and N to obtain a plurality of image blocks, where the width and height of each image block are M and N respectively, and both M and N are integers greater than 1;
[0099] Obtain the length of the pixel value interval corresponding to each image block, and select one image block from the plurality of image blocks as the target image block based on the length of the pixel value interval of each pixel block. The length of the pixel value interval corresponding to the target image block is the difference between the maximum pixel value and the minimum pixel value in the target image block;
[0100] Select S pixel points from the target image block.
[0101] Optionally, the apparatus further includes:
[0102] An acquisition module, configured to acquire the size information of the second image, and acquire M and N based on the size information.
[0103] Optionally, the acquisition module is configured to:
[0104] Calculate the value closest to 2 M of the image width and the value closest to 2 N of the image height to obtain M and N, where the image width and the image height are the width and height of the second image respectively.
[0105] Optionally, the selection module is configured to:
[0106] Determine a target graphic based on a graphic generation rule. The target graphic is the graphic indicated by the graphic generation rule, and the positional relationship between the target graphic and the second image is the positional relationship indicated by the graphic generation rule. The target graphic includes S specified positions, and there are S pixel points in the second image that correspond one-to-one to the S specified positions;
[0107] Select the pixel points corresponding to the S specified positions from the second image to obtain the S pixel points.
[0108] Optionally, the encryption rule is used to indicate specified information, and the specified information includes information required for processing the second image. The modification module is configured to:
[0109] Based on the encryption rule, modify the bit value of the lowest bit of each of the X pixel points to the value corresponding to each of the X pixel points indicated by the encryption rule, to obtain the third pixel value of each of the X pixel points. The X pixel points are the first to X pixel points, and X is an integer greater than 1 and less than S;
[0110] Set Y bits to indicate the specified information, where the Y bits include the least significant bit of each of the Y pixel points, so as to obtain the third pixel value of each of the Y pixel points, and the Y pixel points are the (X + 1)-th to S-th pixel points.
[0111] Optionally, the modification module is configured to:
[0112] For each of the X pixel points, perform the following steps: add the abscissa and ordinate of the pixel point to obtain an accumulated value;
[0113] When the accumulated value is even, set the least significant bit value of the pixel point to a first bit value to obtain the second pixel value of the pixel point; or, when the accumulated value is odd, set the least significant bit value of the pixel point to a second bit value to obtain the second pixel value of the pixel point.
[0114] Optionally, the encryption rule is further used to indicate an encryption type and encryption information corresponding to the encryption type.
[0115] The modification module is configured to:
[0116] Set Z bits to indicate the encryption type, where the Z bits include the least significant bit of each of the Z pixel points, and the Z pixel points include the 1st to Z-th pixel points, and Z is an integer greater than 1 and less than X, so as to obtain the second pixel value of each of the Z pixel points;
[0117] Set X - Z bits to indicate the encryption information, where the X - Z bits include the least significant bit of each of the X - Z pixel points, and the X - Z pixel points include the (Z + 1)-th to X-th pixel points, so as to obtain the second pixel value of each of the X - Z pixel points.
[0118] Optionally, the device further includes:
[0119] A processing module, configured to process the second image based on the specified information when the verification of the second image passes.
[0120] On the other hand, the present application provides an electronic device, including: a processor and a memory. Wherein, the processor and the memory can be connected through a bus system. The memory is used to store programs, instructions or codes, and the processor is used to execute the programs, instructions or codes in the memory to complete the above method for encrypting an image and / or the method for verifying an image.
[0121] On the other hand, the present application provides a computer program product, which includes a computer program stored in a computer-readable storage medium, and the computer program is loaded by a processor to implement the above method for encrypting an image and / or the method for verifying an image.
[0122] On the other hand, the present application provides a non-volatile computer-readable storage medium for storing a computer program, and the computer program is loaded by a processor to execute instructions for implementing the above method for encrypting an image and / or the method for verifying an image.
[0123] On the other hand, the present application provides a system for verifying an image, and the system includes the device for encrypting an image and the device for verifying an image as described above.
[0124] The technical solutions provided by the embodiments of the present application may include the following beneficial effects:
[0125] Since, based on the pixel selection rule, S pixels are selected from the first image, and based on the encryption rule, the value of the specified bit of each pixel is respectively modified to the value corresponding to each pixel indicated by the encryption rule to obtain the second pixel value of each pixel, and the first pixel value of each pixel in the first image is respectively replaced with the second pixel value of each pixel to encrypt the first image and obtain the second image. Since the difference between the first pixel value and the second pixel value of each pixel is not more than the specified difference, the modification range of each pixel is small, and the image information lost during the encryption of the first image is greatly reduced, ensuring that the encrypted second image is still a normal image and can be normally browsed.
[0126] When verifying the second image, since, based on the pixel selection rule, S pixels are selected from the second image, and based on the encryption rule, the value of the specified bit in each pixel is respectively modified to the value corresponding to each pixel indicated by the encryption rule to obtain the third pixel value of each pixel. The second pixel value of each pixel is obtained from the second image. When the second pixel value and the first pixel value of each pixel are equal, the verification of the second image passes, and then the second image is processed using a specified algorithm. Among them, the above encryption method is deployed in the first device, the above verification method is deployed in the second device, and the specified algorithm for processing the second image is also deployed in the second device. In the second device, the above verification method is bound to the specified algorithm, and the second device uses the specified algorithm to process the second image only after the verification of the second image passes. And the first device uses the above encryption method to encrypt and obtain the second image, and the second device can use the above verification method to pass the verification of the second image, so that the specified algorithm is used to process the second image output by the first device, avoiding the specified algorithm being used to process images output by other devices, thereby avoiding economic losses caused by the theft of the specified algorithm.
[0127] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and do not limit the present application. Brief Description of the Drawings
[0128] The accompanying drawings herein are incorporated into and constitute a part of this specification, showing embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application.
[0129] Figure 1 is a schematic diagram of a network architecture provided by an embodiment of the present application;
[0130] Figure 2 is a flowchart of a method for encrypting an image provided by an embodiment of the present application;
[0131] Figure 3 is a schematic diagram of selecting S fields provided by an embodiment of the present application;
[0132] Figure 4 is a schematic diagram of dividing an image block provided by an embodiment of the present application;
[0133] Figure 5 is a schematic diagram of a first graphic provided by an embodiment of the present application;
[0134] Figure 6 is a flowchart of a method for verifying an image provided by an embodiment of the present application;
[0135] Figure 7 is a schematic diagram of the structure of a device for encrypting an image provided by an embodiment of the present application;
[0136] Figure 8 is a schematic diagram of the structure of a device for verifying an image provided by an embodiment of the present application;
[0137] Figure 9 is a schematic diagram of the structure of an electronic device provided by an embodiment of the present application.
[0138] Through the above accompanying drawings, specific embodiments of the present application have been shown, and there will be more detailed descriptions hereinafter. These accompanying drawings and the textual descriptions are not intended to limit the scope of the concept of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. Detailed Embodiments
[0139] Exemplary embodiments will be described in detail herein, and examples thereof are shown in the accompanying drawings. When the following description refers to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. On the contrary, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0140] Referring to Figure 1 , an embodiment of the present application provides a network architecture, including:
[0141] A first device and a second device, where the first device communicates with the second device. The first device is configured to obtain a first image, where the first image is an image to be encrypted, and encrypt the first image to obtain a second image.
[0142] The second device obtains the second image, verifies the second image, and processes the second image using a specified algorithm after the verification passes.
[0143] The specified algorithm includes one or more of a barcode recognition algorithm and an optical character recognition (OCR) algorithm, etc.
[0144] Wherein, the encryption method on the first device corresponds to the verification method on the second device, and the verification method is used to verify the image encrypted by the encryption method. On the second device, the specified algorithm is bound to the verification method. In this way, the first device encrypts the first image to obtain the second image, and the second device verifies the second image.
[0145] Wherein, after the verification passes, it means that: the second image is an image encrypted using the encryption method corresponding to the verification method. And the encryption method is located on the first device, so the second image is the image output by the first device. Therefore, the second device processes the second image using the specified algorithm bound to the verification method, that is, it is ensured that the second device processes the image output by the first device using the specified algorithm.
[0146] For example, the specified algorithm and the first device belong to the same manufacturer. Since the specified algorithm on the second device is bound to the verification method, the first device encrypts the first image obtained by the first device using the encryption method corresponding to the verification method, and sends the encrypted second image to the second device. The second device verifies the second image using the verification method corresponding to the encryption method, and uses the specified algorithm bound to the verification method to process the second image after the verification passes. So that the specified algorithm in the second device processes the second image output by the first device, thus avoiding economic losses caused by others bypassing the first device and stealing the specified algorithm to process images that are not output by the first device.
[0147] Optionally, the first device may be a camera, a mobile phone, a computer, etc., and the second device may be a computer, etc.
[0148] See Figure 2 , an embodiment of the present application provides a method for encrypting an image. This method is applied to Figure 1 the network architecture shown in
[0149] Step 201: Obtain the size information of the first image. The size information includes the image width and the image height, and obtain M and N based on this size information.
[0150] The image width and the image height are respectively the width and height of the first image.
[0151] The first image is saved in the form of a file. The file storing the first image includes the attribute information of the first image. The attribute information includes the image height and the image width of the first image. Therefore, read the image width and the image height of the first image from the attribute information of the first image.
[0152] In step 201, the operation of obtaining M and N is: calculate the value of 2 M closest to the image width and the value of 2 N closest to the image height to obtain M and N.
[0153] For example, assume that the image width is 1026 and the image height is 1036. When M is taken as 10, 2 M = 1024, which is closest to the image width 1026. When N is taken as 10, 2 N = 1024, which is closest to the image height 1036. So the values of M and N are both 10.
[0154] Optionally, M and N are specified values.
[0155] Step 202: Select S pixel points to be encrypted from the first image based on the pixel point selection rule. The first image includes the first pixel value of each of the S pixel points, and S is an integer greater than 1.
[0156] In step 202, S pixel points can be selected through the following three pixel point selection rules. The pixel point selection rule used in step 202 is one of the three pixel point selection rules. The three pixel point selection rules are respectively:
[0157] Pixel selection rule 1: Select S consecutive fields from the first image. The i-th field includes a first sub-field and a second sub-field. The first sub-field includes M bits, and the second sub-field includes N bits, where i = 1, 2,..., S, and both M and N are integers greater than 1. Select from the first image pixels with abscissa x i and ordinate y i where x i is the value indicated by the first sub-field in the i-th field, and y i is the value indicated by the second sub-field in the i-th field.
[0158] Optionally, select S consecutive fields from the starting position, middle position, or other specified positions of the first image.
[0159] Optionally, the starting position of the selected field is a position agreed upon by the first device or the second device. Alternatively, the starting position of the selected field is a position determined by the first device. For example, the first device randomly determines a position in the first image as the starting position, such as the first device determines the starting position of the first pixel in the third row of the first image as the starting position. If the starting position of the selected field is determined by the first device, the first device also sends the starting position of the selected field to the second device.
[0160] Optionally, the i-th field includes M + N bits, the first sub-field is the first M bits of the i-th field, and the second sub-field is the last N bits of the i-th field.
[0161] Among them, each pixel in the first image includes multiple bits, so each row of the first image includes consecutive multiple bits. The bits in the i-th field may be the bits in a certain pixel in the first image, or may be the bits in several pixels, etc.
[0162] Among them, if the selected pixel is a pixel in these S fields, discard the selected pixel and obtain the (S + 1)-th field from the first image. Based on the abscissa indicated by the first sub-field and the ordinate indicated by the second sub-field included in the (S + 1)-th field, select the corresponding pixel from the first image.
[0163] Since the pixel value of the selected pixel is modified, to ensure that the second device for verifying the image can select the same pixel as the first device, if the selected pixel is a pixel in these S fields, discard the selected pixel to ensure that the first device and the second device can select the same pixel.
[0164] Among them, the first sub-field includes M bits, and the value of each bit is 1 or 0. For example, assume that M = 10, the first sub-field is 0000001100, and the value indicated by the first sub-field is 12. Similarly, the second sub-field includes N bits, and the value of each bit is 1 or 0. For example, assume that N = 10, the second sub-field is 0000001001, and the value indicated by the second sub-field is 9.
[0165] For example, refer to Figure 3 the first image shown. Both M and N are 10, so each of the S fields includes 20 bits. Obtain consecutive S fields from the starting position of the first image. The first field includes consecutive M + N bits. The first M bits of the first field are the first sub-field, and the last N bits of the first field are the second sub-field. The value indicated by the first sub-field in the first field is the abscissa x1, and the value indicated by the second sub-field in the first field is the ordinate y1. Based on the abscissa x1 and the ordinate y1, read the corresponding pixel point from the first image to obtain the first pixel point.
[0166] The second field includes consecutive M + N bits. The first M bits of the second field are the first sub-field, and the last N bits of the second field are the second sub-field. The value indicated by the first sub-field in the second field is the abscissa x2, and the value indicated by the second sub-field in the second field is the ordinate y2. Based on the abscissa x2 and the ordinate y2, read the corresponding pixel point from the first image to obtain the second pixel point.
[0167] The third field includes consecutive M + N bits. The first M bits of the third field are the first sub-field, and the last N bits of the third field are the second sub-field. The value indicated by the first sub-field in the third field is the abscissa x3, and the value indicated by the second sub-field in the third field is the ordinate y3. Based on the abscissa x3 and the ordinate y3, read the corresponding pixel point from the first image to obtain the third pixel point.
[0168] And so on. The S-th field includes consecutive M + N bits. The first M bits of the S-th field are the first sub-field, and the last N bits of the S-th field are the second sub-field. The value indicated by the first sub-field in the S-th field is the abscissa x S , and the value indicated by the second sub-field in the S-th field is the ordinate y S . Based on the abscissa x S and the ordinate y S , read the corresponding pixel point from the first image to obtain the S-th pixel point.
[0169] Pixel selection rule 2: Based on M and N, divide the first image into multiple image blocks, where both M and N are integers greater than 1. Obtain the length of the pixel value interval corresponding to each image block. Select one image block as the target image block based on the length of the pixel value interval of each image block, and select S pixels from the target image block.
[0170] Among them, the length of the pixel value interval of the target image block is the difference between the maximum pixel value and the minimum pixel value in the target image block.
[0171] Optionally, select S pixels from the starting position of the target image block. The S pixels are consecutive S pixels in the target image block, or the interval between any two adjacent pixels among the S pixels is equal.
[0172] Optionally, the image block with the minimum pixel value interval length can be selected as the target image block, or the image block with the maximum pixel value interval length can be selected as the target image block, or the image block with the intermediate value of the pixel value interval length can be selected as the target image block, etc.
[0173] For any one of the multiple divided image blocks, the width of the image block is M, and the height of the image block is N.
[0174] See Figure 4 , based on the width M and height N of the image block, divide the first image into multiple image blocks. Suppose the number of image blocks is 9. For the first image block, select the maximum pixel value and the minimum pixel value from the pixel values of each pixel included in the first image block, and calculate the difference between the maximum pixel value and the minimum pixel value to obtain the length of the pixel value interval corresponding to the first image block, which is supposed to be 10. For the second image block, select the maximum pixel value and the minimum pixel value from the pixel values of each pixel included in the second image block, and calculate the difference between the maximum pixel value and the minimum pixel value to obtain the length of the pixel value interval corresponding to the second image block, which is supposed to be 8...., for the ninth image block, select the maximum pixel value and the minimum pixel value from the pixel values of each pixel included in the ninth image block, and calculate the difference between the maximum pixel value and the minimum pixel value to obtain the length of the pixel value interval corresponding to the ninth image block, which is supposed to be 20.
[0175] See Figure 4 , suppose the length of the pixel value interval of the fourth image block is 2, which is the image block with the minimum pixel value interval length among the nine image blocks. Select consecutive S pixels from the fourth image block, that is, select the first pixel to the Sth pixel from the fourth image block.
[0176] Pixel selection rule 3: Based on the graphic generation rule, determine the target graphic. The target graphic is the graphic indicated by this graphic generation rule, and the positional relationship between the target graphic and the first image is the positional relationship indicated by this graphic generation rule. The target graphic includes S specified positions, and there are S pixel points in the first image that correspond one-to-one to these S specified positions; select the pixel points corresponding to these S specified positions from the first image to obtain the S pixel points.
[0177] Pre-set multiple graphic generation rules, and each graphic generation rule indicates a graphic, which includes S specified positions.
[0178] Optionally, in pixel selection rule 3, select a graphic generation rule from the pre-set multiple graphic generation rules as the graphic generation rule used in step 202. Based on the image width and image height of the first image, generate a target graphic through this graphic generation rule. Based on the positional relationship between the first image and the target graphic indicated by the graphic generation rule, set the target graphic to float in the first image, and each position in the target graphic corresponds to a pixel point in the first image. Based on the S specified positions in the first graphic, obtain S pixel points from the first image.
[0179] For example, see Figure 5 , assuming that the graphic indicated by the selected graphic generation rule is a quadrilateral, for the two diagonals of the target graphic, one diagonal is in the horizontal direction and the other diagonal is in the vertical direction. The S specified positions in the target graphic include the four vertices and the midpoints of the four sides of the first graphic, that is, S = 8.
[0180] See Figure 5 , so based on the width and height of the first image, generate a target graphic in the first image through the selected graphic generation rule, that is, generate a quadrilateral. Assuming that the graphic generation rule indicates the positional relationship between the first image and the target graphic as: the midpoints of the four sides of the first image are the four vertices of the target graphic, and the target graphic floats on the first image. Based on this positional relationship, set the target graphic to float on the first image, and based on the eight specified positions in the target graphic, obtain eight pixel points from the first image.
[0181] Step 203: Based on the encryption rule, modify the value of the specified bit of each of the S pixel points to the value corresponding to each of these pixel points indicated by this encryption rule to obtain the second pixel value of each of these pixel points.
[0182] Among them, the difference between the first pixel value and the second pixel value of each of the S pixel points does not exceed the specified difference.
[0183] In step 203, the encryption rule is used to indicate specified information, which includes the information required for processing the second image. For example, the specified information includes the processing method for processing the second image or the algorithm identifier of a specified algorithm, etc.
[0184] In step 203, based on the encryption rule, the least significant bit value of each of the X pixel points among the X pixel points is respectively modified to the value corresponding to each of the X pixel points indicated by the encryption rule, to obtain the second pixel value of each of the X pixel points. The X pixel points include the 1st to Xth pixel points, and X is an integer greater than 1 and less than S; Y bits are set to indicate the specified information. The Y bits include the least significant bit of each of the Y pixel points, so as to obtain the second pixel value of each of the Y pixel points. The Y pixel points include the (X + 1)th to Sth pixel points.
[0185] Optionally, X and Y are respectively specified values, or the value of Y is determined based on the data volume of the specified information. Wherein, X + Y = S.
[0186] For any one of the S pixel points, the pixel point includes eight bits or 16 bits, etc. For example, assume that the pixel point includes eight bits, and the eight bits are 00000001, and the least significant bit value of the pixel point is "1".
[0187] For example, S = 8, X = 4, Y = 4. That is, 8 pixel points are selected in step 102, and the 1st to 4th pixel points are the first 4 pixel points of the 8 pixel points. The least significant bit value of each of the first 4 pixel points is modified to obtain the second pixel value of each of the first 4 pixel points. The 5th to 8th pixel points are the last 4 pixel points of the 8 pixel points. The least significant bit is selected from each of the last 4 pixel points to obtain four bits, and the four bits are used to indicate the algorithm identifier of the processing algorithm for processing the second image. The processing algorithm includes barcode recognition or OCR, etc.
[0188] Optionally, for the operation of modifying the least significant bit value of each of the X pixel points based on the encryption rule. In the embodiments of the present application, the following two encryption rules are provided. The encryption rule may be one of the two encryption rules, and the two encryption rules are respectively:
[0189] Encryption rule 1: For each pixel point included in the X pixel points, the abscissa and ordinate of the pixel point are added to obtain an accumulated value; when the accumulated value is even, the least significant bit value of the pixel point is set to the first bit value, and when the accumulated value is odd, the least significant bit value of the pixel point is set to the second bit value, to obtain the second pixel value of the pixel point.
[0190] Optionally, the first bit value is 1 and the second bit value is 0; or, the first bit value is 0 and the second bit value is 1.
[0191] Encryption rule 2, which is also used to indicate the encryption type and the encryption information corresponding to the encryption type. Set Z bits to indicate the encryption type, where the Z bits include the least significant bit of each of the Z pixel points, and the Z pixel points include the first to Z pixel points, and Z is an integer greater than 1 and less than X, so as to obtain the second pixel value of each of the Z pixel points. Set X - Z bits to indicate the encryption information corresponding to the encryption type, where the X - Z bits include the least significant bit of each of the X - Z pixel points, and the X - Z pixel points include the (Z + 1)th to Xth pixel points, so as to obtain the second pixel value of each of the X - Z pixel points.
[0192] Wherein, the encryption type and the encryption information corresponding to the encryption type are preset information.
[0193] Step 204: In the first image, replace the first pixel value of each pixel point with the second pixel value of each pixel point to obtain a second image.
[0194] For each pixel point in the first image, the difference between the first pixel value and the second pixel value corresponding to each pixel point does not exceed a specified difference. Compared with the first image, the image information lost in the second image is reduced, and the integrity of the second image is avoided from being damaged, so as to ensure that the second image can be normally browsed.
[0195] Optionally, the first device sends the second image to the second device. When the pixel point selection rule 3 is used to select S pixel points, the first device also sends the identifier of the graphic generation rule to the second device.
[0196] Optionally, the first device also sends the identifier of the selected pixel point selection rule to the second device. And / or, send the identifier of the encryption rule.
[0197] Optionally, the pixel point selection rule and / or the encryption rule are pre-agreed between the first device and the second device.
[0198] In the embodiments of the present application, since S pixel points are selected from the first image, only the least significant bit of each of the S pixel points is modified to encrypt the first image. Since only the least significant bit of each pixel point is modified, the modification amplitude of each pixel point is small, so that the difference between the first pixel value and the second pixel value of each pixel point is small and does not exceed the specified difference, greatly reducing the image information lost when encrypting the first image and ensuring that the encrypted first image is still a normal image and can be normally browsed.
[0199] See Figure 6 , an embodiment of the present application provides a method for verifying an image. This method is applied to Figure 1 the network architecture shown in the figure. The execution subject of this method can be the second device in this network architecture, including:
[0200] Step 601: Obtain the size information of the second image. This size information includes the image width and image height of the second image. Based on this size information, obtain M and N.
[0201] The second image is saved in the form of a file. The file storing the second image includes the attribute information of the second image. This attribute information includes the image height and image width of the second image. Therefore, read the image width and image height of the second image from the attribute information of the second image.
[0202] In step 601, calculate the value of 2 M closest to the image width and the value of 2 N closest to the image height to obtain M and N.
[0203] Step 602: Based on the pixel point selection rule, select S pixel points to be encrypted from the second image. The second image includes the second pixel value of each pixel point among the S pixel points. S is an integer greater than 1.
[0204] This pixel point selection rule is pre-agreed by the first device and the second device. Alternatively, the second device receives the identifier of this pixel point selection rule sent by the first device and determines this pixel point selection rule based on this identifier.
[0205] In step 602, S pixel points can be selected through three pixel point selection rules. This pixel point selection rule is one of the three. The three pixel point selection rules are respectively:
[0206] Pixel point selection rule 1: Select S consecutive fields from the second image. The i-th field includes a first sub-field and a second sub-field. The first sub-field includes M bits, and the second sub-field includes N bits, where i = 1, 2,..., S, and both M and N are integers greater than 1; select the pixel point with the abscissa of x i and the ordinate of y i . x i is the value indicated by the first sub-field in the i-th field, and y i is the value indicated by the second sub-field in the i-th field.
[0207] Optionally, select S consecutive fields from the starting position, the middle position or other specified positions of the second image.
[0208] Optionally, the starting position of the selection field is the position agreed upon by the first device or the second device. Alternatively, the starting position of the selection field is the position determined by the first device, and the second device receives the starting position of the selection field sent by the first device.
[0209] Wherein, if the selected pixel point is a pixel point in the S fields, discard the selected pixel point and obtain the (S + 1)-th field from the second image. Based on the abscissa indicated by the first sub-field and the ordinate indicated by the second sub-field included in the (S + 1)-th field, select the corresponding pixel point from the second image.
[0210] Pixel point selection rule 2: Based on M and N, divide the second image to obtain a plurality of image blocks, the width and height of each image block are M and N respectively, and both M and N are integers greater than 1. Obtain the length of the pixel value interval corresponding to each image block. Select an image block as the target image block based on the length of the pixel value interval of each image block, and select S pixel points from the target image block, where the S pixel points are S consecutive pixel points, or the interval between any two adjacent pixel points among the S pixel points is equal.
[0211] Pixel point selection rule 3: Based on the graphic generation rule, determine the target graphic, the target graphic is the graphic indicated by the graphic generation rule, the positional relationship between the target graphic and the first image is the positional relationship indicated by the graphic generation rule, the target graphic includes S specified positions, and there are S pixel points in the first image that correspond one-to-one to the S specified positions; select the pixel points corresponding to the S specified positions from the second image to obtain S pixel points.
[0212] In the case of adopting pixel point selection rule 3, the second device receives the identifier of the graphic generation rule and determines the graphic generation rule based on the identifier.
[0213] Step 603: Based on the encryption rule, modify the value of the specified bit of each pixel point among the S pixel points to the value corresponding to each pixel point indicated by the encryption rule to obtain the third pixel value of each pixel point.
[0214] The encryption rule is used to indicate specified information, and the specified information includes the information required for processing the second image. For example, the specified information includes the processing method for processing the second image or the algorithm identifier of the processing algorithm, etc.
[0215] In step 603, based on the encryption rule, the least significant bit value of each of the X pixel points is respectively modified to the value corresponding to each of the X pixel points indicated by the encryption rule, to obtain the third pixel value of each of the X pixel points. The X pixel points are the 1st to Xth pixel points, and X is an integer greater than 1; Y bits are set to indicate the specified information. The Y bits include the least significant bit of each of the Y pixel points, so as to obtain the third pixel value of each of the Y pixel points. The Y pixel points are the (X + 1)th to Sth pixel points.
[0216] Optionally, for the encryption rule, in step 603, the encryption rule can be a method pre-agreed by the first device and the second device. Alternatively, the second device receives the identifier of the encryption rule and determines the encryption rule based on the identifier.
[0217] Optionally, in the embodiments of the present application, the following two encryption rules are provided. The encryption rule is one of the two encryption rules, and the two encryption rules are respectively:
[0218] Encryption rule 1: For each of the X pixel points included, the abscissa and ordinate of the pixel point are added to obtain an accumulated value. When the accumulated value is even, the least significant bit value of the pixel point is set to the first bit value, and when the accumulated value is odd, the least significant bit value of the pixel point is set to the second bit value, to obtain the third pixel value of the pixel point.
[0219] Encryption rule 2. Encryption rule 2 is also used to indicate the encryption type and the encryption information corresponding to the encryption type. Z bits are set to indicate the encryption type. The Z bits include the least significant bit of each of the Z pixel points. The Z pixel points include the 1st to Zth pixel points, and Z is an integer greater than 1 and less than X, so as to obtain the third pixel value of each of the Z pixel points. (X - Z) bits are set to indicate the encryption information corresponding to the encryption type. The (X - Z) bits include the least significant bit of each of the (X - Z) pixel points. The (X - Z) pixel points include the (Z + 1)th to Xth pixel points, so as to obtain the third pixel value of each of the (X - Z) pixel points.
[0220] Step 604: When the second pixel value of each of the S pixel points is respectively equal to the third pixel value of each of the pixel points, the second image passes the verification.
[0221] For each of the S pixel points, the second pixel value of each of the pixel points is read from the second image.
[0222] When the verification of the second image passes, the second image is processed based on the specified information. For example, the specified information is the algorithm identifier of a specified algorithm, so the specified algorithm is used to process the second image.
[0223] In the embodiments of the present application, since S pixel points are selected from the second image, only the least significant bit of each of the S pixel points is modified to obtain the third pixel value of each pixel point. The second pixel value of each pixel point is obtained from the second image. When the second pixel value of each pixel point is equal to the first pixel value, the verification of the second image passes, and the specified algorithm is used to process the second image. Thereby, using the specified algorithm to process the second image output by the first device avoids the specified algorithm being used to process images output by other devices, that is, avoids the specified algorithm being stolen. In addition, since only the least significant bit of each pixel point is modified when encrypting the first image, the modification amplitude of each pixel point is small, greatly reducing the image information lost when encrypting the first image, and ensuring that the encrypted first image is still a normal image and can be normally browsed.
[0224] The following is an embodiment of the apparatus of the present application, which can be used to execute the method embodiment of the present application. For details not disclosed in the embodiment of the apparatus of the present application, please refer to the method embodiment of the present application.
[0225] See Figure 7 , an embodiment of the present application provides an apparatus 700 for encrypting an image. The apparatus 700 can be deployed on Figure 1 or Figure 2 the first device in the embodiment shown, and includes:
[0226] A selection module 701, configured to select S pixel points to be encrypted from the first image based on a pixel point selection rule. The first image includes the first pixel value of each of the S pixel points, and S is an integer greater than 1;
[0227] A modification module 702, configured to modify the value of the specified bit of each pixel point to the corresponding value of each pixel point indicated by the encryption rule based on the encryption rule, to obtain the second pixel value of each pixel point. The difference between the first pixel value and the second pixel value of each pixel point does not exceed the specified difference;
[0228] A replacement module 703, configured to replace the first pixel value of each pixel point with the second pixel value of each pixel point in the first image to obtain a second image.
[0229] Optionally, the selection module 701 is configured to:
[0230] Select S consecutive fields from the first image. The i-th field includes a first sub-field and a second sub-field. The first sub-field includes M bits, and the second sub-field includes N bits, where i = 1, 2, …, S, and both M and N are integers greater than 1.
[0231] Select a pixel point with abscissa x i and ordinate y i from the first image. x i is the value indicated by the first sub-field in the i-th field, and y i is the value indicated by the second sub-field in the i-th field.
[0232] Optionally, the selection module 701 is used for:
[0233] Partition the first image based on M and N to obtain a plurality of image blocks. The width and height of each image block are M and N respectively, and both M and N are integers greater than 1.
[0234] Obtain the length of the pixel value interval corresponding to each image block, and select an image block as the target image block from the plurality of image blocks based on the length of the pixel value interval of each pixel block. The length of the pixel value interval corresponding to the target image block is the difference between the maximum pixel value and the minimum pixel value in the target image block.
[0235] Select S pixel points from the target image block.
[0236] Optionally, the S pixel points are S consecutive pixel points, or the interval between any two adjacent pixel points among the S pixel points is equal.
[0237] Optionally, the apparatus 700 further includes:
[0238] An acquisition module for acquiring the size information of the first image and obtaining M and N based on the size information.
[0239] Optionally, the acquisition module is used for:
[0240] Calculate the value closest to 2 M of the image width and the value closest to 2 N of the image height to obtain M and N. The image width and image height are the width and height of the first image respectively.
[0241] Optionally, the selection module 701 is used for:
[0242] Determine a target graphic based on a graphic generation rule. The target graphic is the graphic indicated by the graphic generation rule. The positional relationship between the target graphic and the first image is the positional relationship indicated by the graphic generation rule. The target graphic includes S specified positions, and there are S pixel points in the first image that correspond one-to-one to the S specified positions.
[0243] Select the pixel points corresponding to the S specified positions from the first image to obtain S pixel points.
[0244] Optionally, the encryption rule is used to indicate specified information, and the specified information includes the information required for processing the second image; the modification module 702 is configured to:
[0245] Based on the encryption rule, modify the least significant bit value of each of the X pixel points to the value corresponding to each of the X pixel points indicated by the encryption rule, to obtain the second pixel value of each of the X pixel points, where the X pixel points are the first to X pixel points, and X is an integer greater than 1 and less than S;
[0246] Set Y bits to indicate the specified information, where the Y bits include the least significant bit of each of the Y pixel points, to obtain the second pixel value of each of the Y pixel points, where the Y pixel points are the X + 1 to S pixel points.
[0247] Optionally, the modification module 702 is configured to:
[0248] For each of the X pixel points, perform the following steps: add the abscissa and ordinate of the pixel point to obtain an accumulated value;
[0249] When the accumulated value is even, set the least significant bit value of the pixel point to the first bit value to obtain the second pixel value of the pixel point; or, when the accumulated value is odd, set the least significant bit value of the pixel point to the second bit value to obtain the second pixel value of the pixel point.
[0250] Optionally, the encryption rule is further used to indicate the encryption type and the encryption information corresponding to the encryption type, and the modification module 702 is configured to:
[0251] Set Z bits to indicate the encryption type, where the Z bits include the least significant bit of each of the Z pixel points, and the Z pixel points include the first to Z pixel points, and Z is an integer greater than 1 and less than X, to obtain the second pixel value of each of the Z pixel points;
[0252] Set X - Z bits to indicate the encryption information corresponding to the encryption type, where the X - Z bits include the least significant bit of each of the X - Z pixel points, and the X - Z pixel points include the Z + 1 to X pixel points, to obtain the second pixel value of each of the X - Z pixel points.
[0253] In the embodiment of the present application, since the selection module selects S pixel points from the first image, and the modification module only modifies the least significant bit of each of the S pixel points to encrypt the first image. Since only the least significant bit of each pixel point is modified, the modification range of each pixel point is small, greatly reducing the image information lost when encrypting the first image, ensuring that the encrypted first image is still a normal image and can be viewed normally.
[0254] See Figure 8 , the embodiment of the present application provides a device 800 for verifying an image. The device 800 can be deployed on Figure 1 or Figure 6 the second device in the embodiment shown, and the device 800 includes:
[0255] A selection module 801, configured to select S pixel points to be encrypted from the second image based on a pixel point selection rule. The second image includes the second pixel value of each of the S pixel points. S is an integer greater than 1, and the second image is an encrypted image;
[0256] A modification module 802, configured to respectively modify the value of a specified bit in each of the pixel points to the value corresponding to each of the pixel points indicated by the encryption rule to obtain the third pixel value of each of the pixel points;
[0257] A verification module 803, configured to pass the verification of the second image when the second pixel value of each of the pixel points is equal to the third pixel value of each of the pixel points.
[0258] Optionally, the selection module 801 is configured to:
[0259] Select S consecutive fields from the second image. The i-th field includes a first sub-field and a second sub-field. The first sub-field includes M bits, and the second sub-field includes N bits. i = 1, 2,..., S, and both M and N are integers greater than 1;
[0260] Select a pixel point with abscissa x i and ordinate y i from the second image. x i is the value indicated by the first sub-field in the i-th field, and y i is the value indicated by the second sub-field in the i-th field.
[0261] Optionally, the selection module 801 is configured to:
[0262] Divide the second image based on M and N to obtain a plurality of image blocks. The width and height of each image block are M and N respectively, and both M and N are integers greater than 1;
[0263] Obtain the length of the pixel value interval corresponding to each image block, and select an image block from multiple image blocks as the target image block based on the length of the pixel value interval of each pixel block. The length of the pixel value interval corresponding to the target image block is the difference between the maximum pixel value and the minimum pixel value in the target image block;
[0264] Select S pixel points from the target image block.
[0265] Optionally, the device further includes:
[0266] An acquisition module, configured to obtain the size information of the second image, and obtain M and N based on the size information.
[0267] Optionally, the acquisition module is configured to:
[0268] Calculate the value closest to 2 M of the image width and the value closest to 2 N of the image height to obtain M and N, where the image width and the image height are the width and height of the second image respectively.
[0269] Optionally, the selection module 801 is configured to:
[0270] Based on the graphic generation rule, determine the target graphic. The target graphic is the graphic indicated by the graphic generation rule, and the positional relationship between the target graphic and the second image is the positional relationship indicated by the graphic generation rule. The target graphic includes S specified positions, and there are S pixel points in the second image that correspond one-to-one to the S specified positions;
[0271] Select the pixel points corresponding to the S specified positions from the second image to obtain S pixel points.
[0272] Optionally, the encryption rule is used to indicate the specified information, and the modification module 802 is configured to:
[0273] Based on the encryption rule, modify the bit value of the lowest bit of each of the X pixel points to the value corresponding to each of the X pixel points indicated by the encryption rule to obtain the third pixel value of each of the X pixel points. The X pixel points are the first to X pixel points, and X is an integer greater than 1 and less than S;
[0274] Set Y bits to indicate the specified information. The Y bits include the lowest bit of each of the Y pixel points to obtain the third pixel value of each of the Y pixel points. The Y pixel points are the X + 1 to S pixel points.
[0275] Optionally, the modification module 802 is configured to:
[0276] For each of the X pixels, perform the following steps: Add the abscissa and ordinate of the pixel to obtain an accumulated value;
[0277] When the accumulated value is even, set the least significant bit value of the pixel to the first bit value to obtain the second pixel value of the pixel; or, when the accumulated value is odd, set the least significant bit value of the pixel to the second bit value to obtain the second pixel value of the pixel.
[0278] Optionally, the encryption rule is also used to indicate the encryption type and the encryption information corresponding to the encryption type.
[0279] The modification module 802 is used for:
[0280] Set Z bits to indicate the encryption type. The Z bits include the least significant bit of each of the Z pixels. The Z pixels include the first to Z pixels, where Z is an integer greater than 1 and less than X, to obtain the second pixel value of each of the Z pixels;
[0281] Set X-Z bits to indicate the encryption information. The X-Z bits include the least significant bit of each of the X-Z pixels. The X-Z pixels include the (Z + 1)th to Xth pixels, to obtain the second pixel value of each of the X-Z pixels.
[0282] Optionally, the device 800 further includes:
[0283] A processing module, configured to process the second image based on specified information when the verification of the second image passes.
[0284] In the embodiments of the present application, since the selection module selects S pixels from the second image, the acquisition module only modifies the least significant bit of each of the S pixels to obtain the third pixel value of each pixel. The second pixel value of each pixel is obtained from the second image. When the second pixel value of each pixel is equal to the first pixel value, the verification module passes the verification of the second image, and the second image is processed using a specified algorithm. Thus, using the specified algorithm to process the second image output by the first device avoids using the specified algorithm to process images output by other devices, that is, avoids the theft of the specified algorithm.
[0285] Regarding the device in the above embodiments, the specific manners in which each module performs operations have been described in detail in the embodiments related to the method, and will not be elaborated here.
[0286] Figure 9The structural block diagram of an electronic device 900 provided by an exemplary embodiment of the present application is shown. The electronic device 900 may be the above-mentioned first device or second device. And the electronic device 900 may be a portable mobile terminal, such as: a smart phone, a tablet computer, an MP3 player (Moving Picture Experts Group Audio Layer III), an MP4 (Moving Picture Experts Group Audio Layer IV) player, a laptop computer or a desktop computer. The electronic device 900 may also be referred to by other names such as user equipment, portable terminal, laptop terminal, desktop terminal, etc.
[0287] Generally, the electronic device 900 includes: a processor 901 and a memory 902.
[0288] The processor 901 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 901 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), PLA (Programmable Logic Array). The processor 901 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the wake state, also known as the CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 901 may be integrated with a GPU (Graphics Processing Unit), and the GPU is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 901 may also include an AI (Artificial Intelligence) processor, and the AI processor is used to process computational operations related to machine learning.
[0289] The memory 902 may include one or more computer-readable storage media, which may be non-transitory. The memory 902 may also include high-speed random access memory, as well as non-volatile memory, such as one or more disk storage devices and flash storage devices. In some embodiments, the non-transitory computer-readable storage media in the memory 902 is used to store at least one instruction for being executed by the processor 901 to implement the method for encrypting an image or the method for verifying an image provided in the method embodiments of the present application.
[0290] In some embodiments, the electronic device 900 may further optionally include: a peripheral device interface 903 and at least one peripheral device. The processor 901, the memory 902, and the peripheral device interface 903 may be connected through a bus or signal lines. Each peripheral device may be connected to the peripheral device interface 903 through a bus, signal lines, or a circuit board. Specifically, the peripheral device includes at least one of: a radio frequency circuit 904, a display screen 905, a camera assembly 906, an audio circuit 907, a positioning assembly 908, and a power supply 909.
[0291] The peripheral device interface 903 may be used to connect at least one peripheral device related to I / O (Input / Output) to the processor 901 and the memory 902. In some embodiments, the processor 901, the memory 902, and the peripheral device interface 903 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 901, the memory 902, and the peripheral device interface 903 may be implemented on a separate chip or circuit board, and the present embodiment does not limit this.
[0292] The radio frequency circuit 904 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The radio frequency circuit 904 communicates with a communication network and other communication devices through electromagnetic signals. The radio frequency circuit 904 converts an electrical signal into an electromagnetic signal for transmission, or converts a received electromagnetic signal into an electrical signal. Optionally, the radio frequency circuit 904 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a subscriber identity module card, and so on. The radio frequency circuit 904 may communicate with other terminals through at least one wireless communication protocol. The wireless communication protocol includes but is not limited to: the World Wide Web, a metropolitan area network, an intranet, generations of mobile communication networks (2G, 3G, 4G, and 5G), a wireless local area network, and / or a WiFi (Wireless Fidelity) network. In some embodiments, the radio frequency circuit 904 may further include a circuit related to NFC (Near Field Communication), and the present application does not limit this.
[0293] The display screen 905 is used to display the UI (User Interface). The UI may include graphics, text, icons, videos, and any combination thereof. When the display screen 905 is a touch display screen, the display screen 905 also has the ability to collect touch signals on or above the surface of the display screen 905. The touch signals can be input to the processor 901 as control signals for processing. At this time, the display screen 905 can also be used to provide virtual buttons and / or a virtual keyboard, also known as soft buttons and / or a soft keyboard. In some embodiments, there may be one display screen 905, which is disposed on the front panel of the electronic device 900; in other embodiments, there may be at least two display screens 905, which are respectively disposed on different surfaces of the electronic device 900 or are in a folding design; in other embodiments, the display screen 905 may be a flexible display screen, which is disposed on the curved surface or the folding surface of the electronic device 900. Even, the display screen 905 can also be set to an irregular non-rectangular shape, that is, a special-shaped screen. The display screen 905 can be prepared from materials such as LCD (Liquid Crystal Display) and OLED (Organic Light-Emitting Diode).
[0294] The camera module 906 is used to capture images or videos. Optionally, the camera module 906 includes a front camera and a rear camera. Generally, the front camera is disposed on the front panel of the terminal, and the rear camera is disposed on the back of the terminal. In some embodiments, there are at least two rear cameras, which are any one of a main camera, a depth-of-field camera, a wide-angle camera, and a telephoto camera, so as to implement the function of background blurring by fusing the main camera and the depth-of-field camera, the function of panoramic shooting by fusing the main camera and the wide-angle camera, and the VR (Virtual Reality) shooting function or other fusion shooting functions. In some embodiments, the camera module 906 may further include a flash. The flash can be a single-color-temperature flash or a two-color-temperature flash. The two-color-temperature flash refers to a combination of a warm-light flash and a cold-light flash, which can be used for light compensation under different color temperatures.
[0295] The audio circuit 907 may include a microphone and a speaker. The microphone is used to collect sound waves of the user and the environment, and convert the sound waves into electrical signals for input to the processor 901 for processing, or input to the radio frequency circuit 904 to achieve voice communication. For the purpose of stereo collection or noise reduction, there may be multiple microphones, which are respectively arranged at different parts of the electronic device 900. The microphone may also be an array microphone or an omnidirectional collection microphone. The speaker is used to convert the electrical signal from the processor 901 or the radio frequency circuit 904 into sound waves. The speaker may be a traditional thin film speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can not only convert the electrical signal into audible sound waves for humans, but also convert the electrical signal into inaudible sound waves for humans for uses such as ranging. In some embodiments, the audio circuit 907 may further include a headphone jack.
[0296] The positioning component 908 is used to locate the current geographical location of the electronic device 900 to achieve navigation or LBS (Location Based Service). The positioning component 908 may be a positioning component based on the GPS (Global Positioning System) of the United States, the Beidou system of China, or the Galileo system of Russia.
[0297] The power supply 909 is used to supply power to each component in the electronic device 900. The power supply 909 may be alternating current, direct current, a disposable battery, or a rechargeable battery. When the power supply 909 includes a rechargeable battery, the rechargeable battery may be a wired rechargeable battery or a wireless rechargeable battery. A wired rechargeable battery is a battery charged through a wired line, and a wireless rechargeable battery is a battery charged through a wireless coil. The rechargeable battery can also be used to support fast charging technology.
[0298] In some embodiments, the electronic device 900 further includes one or more sensors 910. The one or more sensors 910 include but are not limited to: an acceleration sensor 911, a gyroscope sensor 912, a pressure sensor 913, a fingerprint sensor 914, an optical sensor 915, and a proximity sensor 916.
[0299] The acceleration sensor 911 can detect the magnitude of acceleration on the three coordinate axes of the coordinate system established with the electronic device 900. For example, the acceleration sensor 911 can be used to detect the components of the gravitational acceleration on the three coordinate axes. The processor 901 can control the display screen 905 to display the user interface in a landscape view or a portrait view according to the gravitational acceleration signal collected by the acceleration sensor 911. The acceleration sensor 911 can also be used for collecting game or user movement data.
[0300] The gyroscope sensor 912 can detect the body orientation and rotation angle of the electronic device 900. The gyroscope sensor 912 can cooperate with the acceleration sensor 911 to collect the 3D actions of the user on the electronic device 900. Based on the data collected by the gyroscope sensor 912, the processor 901 can implement the following functions: motion sensing (such as changing the UI according to the user's tilting operation), image stabilization during shooting, game control, and inertial navigation.
[0301] The pressure sensor 913 can be disposed on the side frame of the electronic device 900 and / or the lower layer of the display screen 905. When the pressure sensor 913 is disposed on the side frame of the electronic device 900, it can detect the holding signal of the user on the electronic device 900, and the processor 901 can perform left / right hand recognition or shortcut operations based on the holding signal collected by the pressure sensor 913. When the pressure sensor 913 is disposed on the lower layer of the display screen 905, the processor 901 can control the operable controls on the UI interface according to the pressure operation of the user on the display screen 905. The operable controls include at least one of button controls, scroll bar controls, icon controls, and menu controls.
[0302] The fingerprint sensor 914 is used to collect the fingerprint of the user. The processor 901 can identify the user's identity based on the fingerprint collected by the fingerprint sensor 914, or the fingerprint sensor 914 can identify the user's identity based on the collected fingerprint. When the identified user identity is a trusted identity, the processor 901 authorizes the user to perform relevant sensitive operations, and the sensitive operations include unlocking the screen, viewing encrypted information, downloading software, making payments, and changing settings, etc. The fingerprint sensor 914 can be disposed on the front, back, or side of the electronic device 900. When there are physical buttons or manufacturer logos on the electronic device 900, the fingerprint sensor 914 can be integrated with the physical buttons or manufacturer logos.
[0303] The optical sensor 915 is used to collect the ambient light intensity. In one embodiment, the processor 901 can control the display brightness of the display screen 905 according to the ambient light intensity collected by the optical sensor 915. Specifically, when the ambient light intensity is high, the display brightness of the display screen 905 is increased; when the ambient light intensity is low, the display brightness of the display screen 905 is decreased. In another embodiment, the processor 901 can also dynamically adjust the shooting parameters of the camera module 906 according to the ambient light intensity collected by the optical sensor 915.
[0304] The proximity sensor 916, also known as a distance sensor, is typically disposed on the front panel of the electronic device 900. The proximity sensor 916 is used to collect the distance between the user and the front of the electronic device 900. In one embodiment, when the proximity sensor 916 detects that the distance between the user and the front of the electronic device 900 is gradually decreasing, the processor 901 controls the display screen 905 to switch from the lit state to the off state; when the proximity sensor 916 detects that the distance between the user and the front of the electronic device 900 is gradually increasing, the processor 901 controls the display screen 905 to switch from the off state to the lit state.
[0305] Those skilled in the art can understand that Figure 9 the structure shown in does not constitute a limitation on the electronic device 900, and it may include more or fewer components than shown in the figure, or combine some components, or adopt a different component arrangement.
[0306] After considering the specification and practicing the application disclosed herein, those skilled in the art will readily conceive of other embodiments of the present application. The present application is intended to cover any variations, uses, or adaptations of the present application, which follow the general principles of the present application and include well-known common general knowledge or conventional technical means in the technical field not disclosed in the present application. The specification and embodiments are only regarded as exemplary, and the true scope and spirit of the present application are pointed out by the following claims.
[0307] It should be understood that the present application is not limited to the exact structure already described and shown in the drawings, and various modifications and changes can be made without departing from its scope. The scope of the present application is only limited by the appended claims.
Claims
1. A method for encrypting an image, characterized in that, The method includes: Based on a pixel point selection rule, select S pixel points to be encrypted from a first image, where the first image includes a first pixel value of each of the S pixel points, and S is an integer greater than 1; Based on an encryption rule, modify the least significant bit value of each of the X pixel points to the value corresponding to each of the X pixel points indicated by the encryption rule, to obtain a second pixel value of each of the X pixel points, where the X pixel points are the 1st to Xth pixel points, and X is an integer greater than 1 and less than S; Set Y bits to indicate specified information, where the Y bits include the least significant bit of each of the Y pixel points, to obtain a second pixel value of each of the Y pixel points, where the Y pixel points are the (X + 1)th to Sth pixel points, and obtain the second pixel value of each pixel point, and the difference between the first pixel value and the second pixel value of each pixel point does not exceed a specified difference; In the first image, replace the first pixel value of each pixel point with the second pixel value of each pixel point to obtain a second image; Wherein, the encryption rule is used to indicate the specified information, and the specified information includes a processing method for processing the second image or an algorithm identifier of a specified algorithm.
2. The method according to claim 1, wherein The step of selecting S pixel points to be encrypted from the first image based on the pixel point selection rule includes: Select S consecutive fields from the first image, where the i-th field includes a first sub-field and a second sub-field, the first sub-field includes M bits, the second sub-field includes N bits, i = 1, 2,..., S, and both M and N are integers greater than 1; Select a pixel point with abscissa x from the first image i and ordinate y i , where x i is the value indicated by the first sub-field in the i-th field, and y i is the value indicated by the second sub-field in the i-th field.
3. The method according to claim 1, wherein The step of selecting S pixel points to be encrypted from the first image based on the pixel point selection rule includes: Based on M and N, divide the first image to obtain a plurality of image blocks, where the width and height of each image block are M and N respectively, and both M and N are integers greater than 1; Obtain the pixel value interval length corresponding to each image block, and select an image block as a target image block from the plurality of image blocks based on the pixel value interval length of each pixel block, where the pixel value interval length corresponding to the target image block is the difference between the maximum pixel value and the minimum pixel value in the target image block; Select S pixel points from the target image block.
4. The method according to claim 3, wherein The method further includes: Obtain the size information of the first image, and obtain M and N based on the size information.
5. The method according to claim 4, wherein The step of obtaining M and N based on the size information includes: Calculate the value closest to 2 times the image width M and the value closest to 2 times the image height N to obtain M and N, where the image width and the image height are the width and height of the first image, respectively.
6. The method according to claim 1, wherein The step of selecting S pixel points to be encrypted from the first image based on the pixel point selection rule includes: Based on a graphic generation rule, determine a target graphic, where the target graphic is the graphic indicated by the graphic generation rule, the positional relationship between the target graphic and the first image is the positional relationship indicated by the graphic generation rule, the target graphic includes S specified positions, and there are S pixel points in the first image that correspond one-to-one to the S specified positions; Select the pixel points corresponding to the S specified positions from the first image to obtain the S pixel points.
7. The method according to claim 1, wherein Based on the encryption rule, modifying the bit value of the least significant bit of each of the X pixel points to the value corresponding to each of the X pixel points indicated by the encryption rule includes: Performing the following steps for each of the X pixel points: adding the abscissa and ordinate of the pixel point to obtain an accumulated value; When the accumulated value is even, setting the bit value of the least significant bit of the pixel point to a first bit value to obtain a second pixel value of the pixel point; or, when the accumulated value is odd, setting the bit value of the least significant bit of the pixel point to a second bit value to obtain a second pixel value of the pixel point.
8. The method according to claim 1, wherein The encryption rule is further used to indicate an encryption type and encryption information corresponding to the encryption type, Based on the encryption rule, modifying the bit value of the least significant bit of each of the X pixel points to the value corresponding to each of the X pixel points indicated by the encryption rule includes: Setting Z bits to indicate the encryption type, where the Z bits include the least significant bit of each of the Z pixel points, and the Z pixel points include the 1st to Zth pixel points, and Z is an integer greater than 1 and less than X, to obtain a second pixel value of each of the Z pixel points; Setting X-Z bits to indicate the encryption information, where the X-Z bits include the least significant bit of each of the X-Z pixel points, and the X-Z pixel points include the (Z + 1)th to Xth pixel points, to obtain a second pixel value of each of the X-Z pixel points.
9. The method according to claim 8, characterized in that, The method further includes: Based on a pixel point selection rule, selecting S pixel points to be encrypted from a second image, where the second image includes the second pixel value of each of the S pixel points, S is an integer greater than 1, and the second image is an encrypted image obtained from a first image based on the encryption rule; Based on the encryption rule, modifying the bit value of the least significant bit of each of the X pixel points to the value corresponding to each of the X pixel points indicated by the encryption rule to obtain a third pixel value of each of the X pixel points, where the X pixel points are the 1st to Xth pixel points, and X is an integer greater than 1 and less than S; Setting Y bits to indicate specified information, where the Y bits include the least significant bit of each of the Y pixel points, to obtain a third pixel value of each of the Y pixel points, and the Y pixel points are the (X + 1)th to Sth pixel points, to obtain a third pixel value of each pixel point; When the second pixel value of each pixel point is equal to the third pixel value of each pixel point respectively, the verification of the second image passes; Wherein, the encryption rule is used to indicate the specified information, and the specified information includes a processing method for processing the second image or an algorithm identifier of a specified algorithm.
10. The method according to claim 9, characterized in that, The method further includes: When the verification of the second image passes, processing the second image based on the specified information.
11. An apparatus for encrypting an image, characterized in that, The device includes: A selection module, configured to select S pixels to be encrypted from a first image based on a pixel selection rule, where the first image includes a first pixel value of each of the S pixels, and S is an integer greater than 1; A modification module, configured to, based on an encryption rule, modify the bit value of the least significant bit of each of the X pixels to the value corresponding to each of the X pixels indicated by the encryption rule, to obtain a second pixel value of each of the X pixels, where the X pixels are the first to X pixels, and X is an integer greater than 1 and less than S; set Y bits to indicate specified information, where the Y bits include the least significant bit of each of the Y pixels, to obtain a second pixel value of each of the Y pixels, where the Y pixels are the (X + 1)-th to S-th pixels, to obtain the second pixel value of each pixel, and the difference between the first pixel value and the second pixel value of each pixel does not exceed a specified difference; A replacement module, configured to replace the first pixel value of each pixel in the first image with the second pixel value of each pixel, to obtain a second image; Wherein, the encryption rule is used to indicate the specified information, and the specified information includes a processing method for processing the second image or an algorithm identifier of a specified algorithm.
12. The apparatus according to claim 11, wherein The selection module is further configured to select S pixels to be encrypted from a second image based on a pixel selection rule, where the second image includes a second pixel value of each of the S pixels, S is an integer greater than 1, and the second image is an encrypted image obtained from the first image based on an encryption rule; The modification module is further configured to, based on the encryption rule, modify the bit value of the least significant bit of each of the X pixels to the value corresponding to each of the X pixels indicated by the encryption rule, to obtain a third pixel value of each of the X pixels, where the X pixels are the first to X pixels, and X is an integer greater than 1 and less than S; set Y bits to indicate specified information, where the Y bits include the least significant bit of each of the Y pixels, to obtain a third pixel value of each of the Y pixels, where the Y pixels are the (X + 1)-th to S-th pixels, to obtain the third pixel value of each pixel; The apparatus further includes: a verification module, configured to pass the verification of the second image when the second pixel value of each pixel is equal to the third pixel value of each pixel; Wherein, the encryption rule is used to indicate the specified information, and the specified information includes a processing method for processing the second image or an algorithm identifier of a specified algorithm.
13. A system for verifying an image, characterized in that, The system includes the apparatus according to claim 11 and the apparatus according to claim 12.
Citation Information
Patent Citations
Image processing method, image verification method and device
CN109657487A
Processing method, electronic equipment and processing device
CN113094723A