Disclosure of Invention
An object of the embodiments of the present application is to provide a method, an apparatus, a storage medium, and an electronic device for encrypting a multi-channel image, so as to obtain a ciphertext convenient to store and transmit on the premise of ensuring image security as much as possible.
In order to achieve the above object, embodiments of the present application are implemented as follows:
in a first aspect, an embodiment of the present application provides a multichannel image encryption method, including:
encoding a multichannel image to be encrypted into a quaternion matrix, wherein the multichannel image comprises four components which respectively correspond to a real component and three imaginary components of a quaternion; generating a chaotic phase mask according to the multi-channel image to be encrypted; performing quaternion transformation on the quaternion matrix by combining the chaotic phase mask; determining a real numerical value matrix according to the quaternion matrix after quaternion transformation, wherein the real numerical value matrix comprises a real part component and an imaginary part component of the quaternion matrix after quaternion transformation; and determining a ciphertext based on the real numerical matrix.
The chaotic phase mask is generated based on the multi-channel image to be encrypted, and the quaternion matrix of the multi-channel image to be encrypted is subjected to quaternion transformation, so that the reliability of image encryption can be effectively ensured. And based on the quaternion matrix after quaternion transformation, a real value matrix covering the real component and the imaginary component of the quaternion matrix after transformation is determined, and a ciphertext is determined based on the real value matrix, so that the reliability of image encryption can be further improved, the multichannel component of the multichannel image can be encoded into a whole, the transmission efficiency can be effectively improved, and the storage is convenient.
With reference to the first aspect, in a first possible implementation manner of the first aspect, the generating a chaotic phase mask according to the multi-channel image to be encrypted includes:
carrying out normalization processing on the multi-channel image to be encrypted, and calculating the variance of the normalized multi-channel image; and determining the chaotic phase mask according to the size and the variance of the multi-channel image to be encrypted.
By carrying out normalization processing on a multi-channel image to be encrypted, calculating the variance and combining the size of the multi-channel image, the chaotic phase mask is generated, and the reliability of image encryption can be improved.
With reference to the first aspect, in a second possible implementation manner of the first aspect, the performing quaternion transform on the quaternion matrix with reference to the chaotic phase mask includes:
encoding the quaternion matrix according to the chaotic phase mask; and carrying out quaternion Gyrator transformation on the coded quaternion matrix.
The quaternion matrix is coded by combining the chaotic phase mask, and quaternion Gyrator transformation is further carried out, so that the encryption reliability can be further improved, and the quaternion Gyrator transformation mode is adopted, so that the applicability is good and the efficiency is high.
With reference to the first aspect, in a third possible implementation manner of the first aspect, the determining a real value matrix according to a quaternion matrix after quaternion transformation includes:
extracting real and imaginary components of the quaternion matrix after quaternion transformation; determining a real matrix according to the extracted real component and imaginary component; and expanding the real matrix to determine the real numerical value matrix.
By extracting the real part component and the imaginary part component of the quaternion matrix after quaternion transformation, determining a real matrix according to the real component and expanding the real matrix to determine a real value matrix, the real part component and the imaginary part component of the quaternion matrix after quaternion transformation can be integrated in an integral real value matrix, and storage and transmission are facilitated.
With reference to the first aspect, or with reference to any one of the first to third possible implementation manners of the first aspect, in a fourth possible implementation manner of the first aspect, the determining a ciphertext based on the real-valued matrix includes:
performing Fourier transform on the real numerical matrix; and determining the ciphertext according to the real numerical matrix after Fourier transform.
By carrying out Fourier transform on the real numerical matrix, the reliability of image encryption can be improved, and the ciphertext is determined from the real numerical matrix, so that the ciphertext is real, and the ciphertext of the real numerical matrix is convenient to store and transmit.
With reference to the fourth possible implementation manner of the first aspect, in a fifth possible implementation manner of the first aspect, the determining the ciphertext according to the real value matrix after the fourier transform includes:
determining a coefficient matrix according to the coefficient of the real numerical value matrix after Fourier transform; determining a real component matrix and an imaginary component matrix corresponding to the coefficient matrix based on the coefficient matrix; and determining the ciphertext according to the real component matrix and the imaginary component matrix.
By determining the coefficient matrix corresponding to the real value matrix after Fourier transformation and determining the real component matrix and the imaginary component matrix, the ciphertext of the real value can be obtained, and the ciphertext is convenient to store and transmit.
With reference to the fifth possible implementation manner of the first aspect, in a sixth possible implementation manner of the first aspect, the determining a coefficient matrix according to the coefficients of the real value matrix after fourier transform includes:
determining real value matrix coefficients of the real value matrix after Fourier transformation; and setting partial coefficients in the real value matrix coefficients to be zero, and determining the coefficient matrix.
And setting part of coefficients in the real-value matrix coefficients to be zero to determine the coefficient matrix, so that the determined ciphertext has higher safety.
In a second aspect, an embodiment of the present application provides a multi-channel image encryption apparatus, including:
the image coding module is used for coding a multichannel image to be encrypted into a quaternion matrix, wherein the multichannel image comprises four components which respectively correspond to a real component and three imaginary components of a quaternion; the mask generation module is used for generating a chaotic phase mask according to the multi-channel image to be encrypted; the quaternion transformation module is used for carrying out quaternion transformation on the quaternion matrix by combining the chaotic phase mask; the real-value matrix module is used for determining a real-value matrix according to the quaternion matrix subjected to quaternion transformation, wherein the real-value matrix comprises a real part component and an imaginary part component of the quaternion matrix subjected to quaternion transformation; and the ciphertext determining module is used for determining the ciphertext based on the real numerical matrix.
In a third aspect, an embodiment of the present application provides a storage medium, where one or more programs are stored, and the one or more programs are executable by one or more processors to implement the steps of the multi-channel image encryption method according to the first aspect or any one of possible implementation manners of the first aspect.
In a fourth aspect, an embodiment of the present application provides an electronic device, including a memory and a processor, where the memory is configured to store information including program instructions, and the processor is configured to control execution of the program instructions, and the program instructions are loaded by the processor and executed to implement the steps of the multi-channel image encryption method according to the first aspect or any one of the possible implementations of the first aspect.
In order to make the aforementioned objects, features and advantages of the present application more comprehensible, preferred embodiments accompanied with figures are described in detail below.
Detailed Description
The technical solutions in the embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application.
In order to further improve transmission efficiency while ensuring security of image encryption, embodiments of the present application provide a multi-channel image encryption method.
Referring to fig. 1, fig. 1 is a flowchart of a multi-channel image encryption method according to an embodiment of the present disclosure, which may include step S10, step S20, step S30, step S40, and step S50.
Step S10: and encoding the multichannel image to be encrypted into a quaternion matrix, wherein the multichannel image comprises four components which respectively correspond to a real component and three imaginary components of a quaternion.
In this embodiment, when encrypting a multi-channel image, the multi-channel image to be encrypted may be encoded as a quaternion matrix. Specifically, each component of the multi-channel image can be taken as the real component and the imaginary component of the quaternion, respectively, i.e.:
fq(x,y)=fc,1(x,y)+ifc,2(x,y)+jfc,3(x,y)+kfc,4(x,y),
wherein f isq(x, y) denotes a quaternion matrix, fc,1(x, y) denotes the real component of the quaternion matrix, ifc,2(x, y) denotes the first imaginary component, jf, of the quaternion matrixc,3(x, y) denotes the second imaginary component of the quaternion matrix, kfc,4(x, y) denotes a third imaginary component representing a quaternion matrix, and subscripts (c,1), (c,2), (c,3), (c,4) denote a first channel component, a second channel component, a third channel component, and a fourth channel component of the multi-channel image, respectively.
Illustratively, an RGB (representing the three primary colors in general, R represents Red, G represents Green, and B represents Blue, Blue) color image may be taken as an example for verification, and specifically, the three color components of the color image may be taken as the three imaginary components of the quaternion matrix.
Of course, the manner adopted by the above example cannot be regarded as a limitation of the present application, and the multi-channel image encryption method provided in the embodiment of the present application may be applied to a four-channel image, and may also be applied to other components with more than four channels, where the components of four channels are selected from a plurality of channel components for implementation, and is not limited herein.
Step S20 may also be performed for the multichannel image to be encrypted.
Step S20: and generating a chaotic phase mask according to the multi-channel image to be encrypted.
In this embodiment, the multichannel image to be encrypted may be normalized, and the variance of the normalized multichannel image may be calculated, so as to determine the chaotic phase mask according to the size of the multichannel image to be encrypted and the calculated variance.
Specifically, the multi-channel image to be encrypted may be normalized, the variance of the normalized multi-channel image may be calculated, and the calculated variance may be used as the initial value S of the chaotic sequence0. Wherein, the chaotic sequence can be:
st+1=(3.57+st/4)·st·(1-st),
wherein S istIs the t-th sequence value in the chaotic sequence.
According to the initial value S of the chaotic sequence0The sequence can be generated:
S={st|t=1,2,…,NM+1},
where N × M represents the size of the image.
And, the first NM values of S may be adjusted to a matrix Z of size N M to construct the chaotic phase mask P, where NM represents a value (i.e., the product of N times M). Illustratively, the chaotic phase mask P may be constructed by:
wherein, mu1Is an arbitrary unit pure four element number, namely:
wherein, γ1、γ2、γ3Are all real numbers.
Therefore, the chaotic phase mask of the multi-channel image to be encrypted can be generated, and the reliability of image encryption can be improved.
It should be noted that the above method for generating the chaotic phase mask is only an exemplary method, and the values of the sequence values of the chaotic sequence, the values of the coefficients of the chaotic sequence, the calculation method of the chaotic sequence, and the like may be based on actual requirements, and should not be considered as limitations of the present application.
Determining a quaternion matrix fq(x, y) and the chaotic phase mask P, step S30 may be performed.
Step S30: and performing quaternion transformation on the quaternion matrix by combining the chaotic phase mask.
In this embodiment, the quaternion matrix may be encoded according to the chaotic phase mask, and the encoded quaternion matrix may be subjected to quaternion Gyrator transformation.
Specifically, a quaternion matrix is encoded according to a chaotic phase mask, and quaternion Gyrator transformation is performed, that is:
G=Gα{fq·P},
wherein, G represents a quaternion matrix after quaternion transformation, and the calculation formula of quaternion Gyrator transformation is as follows:
where μ is an arbitrary unit pure four-element number, (x, y) denotes a spatial coordinate, (u, v) denotes a frequency domain coordinate, and the angle α is S (NM + 1).
The quaternion matrix is coded by combining the chaotic phase mask, and quaternion Gyrator transformation is further carried out, so that the encryption reliability can be further improved, and the quaternion Gyrator transformation mode is adopted, so that the method is high in efficiency and good in applicability.
In the present embodiment, the example of conversion using a quaternion Gyrator is described, but the present invention is not limited to this. In some other implementations, other quaternion transformation methods may be used to improve the reliability of the encryption. Such as a quaternion Fourier transform method, a quaternion cosine transform method, etc., and thus should not be considered as limiting the present application herein.
After determining the quaternion matrix G after quaternion transformation, step S40 may be performed.
Step S40: and determining a real numerical value matrix according to the quaternion matrix after quaternion transformation, wherein the real numerical value matrix comprises a real part component and an imaginary part component of the quaternion matrix after quaternion transformation.
In this embodiment, the real component and the imaginary component of the quaternion matrix G after quaternion transformation may be extracted, and a real matrix may be determined according to the extracted real component and imaginary component, and the real matrix may be expanded to determine a real value matrix.
Specifically, the real and imaginary components of the quaternion matrix G may be extracted and combined to determine the real matrix G.
For example, the real component s (G), the first imaginary component x (G), the second imaginary component y (G), and the third imaginary component z (G) may be extracted from the quaternion matrix G, and s (G), x (G), y (G), and z (G) may be combined to determine the real matrix G. For example:
of course, this is an exemplary combination, and the row and column of the real component and each imaginary component is not limited thereto, and therefore, should not be considered as limiting the present application.
The real component and each imaginary component extracted from the quaternion matrix are combined into a real matrix, so that the real component and each imaginary component can be integrated together, and the storage and the transmission are convenient.
After the real matrix g is determined, in order to facilitate the operation on the real matrix g, the order of the real matrix g may be changed by performing zero padding expansion on the real matrix g, so as to obtain a real value matrix g' with a required order. Illustratively, a row and a column of zero vectors may be added before the first row and the first column of the matrix g, respectively, i.e.
Of course, the method of zero padding and extending here is only one of many optional methods, and a row and a column of zero vectors may be added after the second row and the second column of the matrix g, or a row of zero vectors may be added between the first row and the second row, and a column of zero vectors may be added between the first column and the second column, and the like, which is not limited here.
In addition, it should be noted that in some other optional implementation manners, after the real component, the first imaginary component, the second imaginary component, and the third imaginary component are extracted from the quaternion matrix, the real component, each imaginary component, and the matrix zero are combined to form a real value matrix of a required order, and it is not necessary to combine the real matrix and then expand the real value matrix, so as to save a program and improve the efficiency of the whole image encryption method.
In this embodiment, after the real value matrix is determined, step S50 may be performed.
Step S50: and determining a ciphertext based on the real numerical matrix.
In this embodiment, fourier transform may be performed on the real-valued matrix, and a ciphertext may be determined according to the real-valued matrix after fourier transform.
In particular, the real numerical matrix g' may be fourier transformed. Illustratively, a two-dimensional discrete Fourier transform may be employed, the calculation formula of which is:
wherein: (M, N) denotes frequency domain coordinates, (u, v) denotes frequency domain coordinates, and N '× M' denotes the size of the multichannel image to be encrypted.
Of course, the two-dimensional Discrete Fourier Transform is used here as an example only for convenience of explanation, and a Fourier Transform method having similar properties to this, for example, a three-parameter Discrete Fourier Transform, may be used. Therefore, the present application should not be considered as limited herein.
In this embodiment, the real-valued matrix coefficients of the real-valued matrix after fourier transform may be determined, and some of the coefficients of the real-valued matrix coefficients may be set to zero to determine the coefficient matrix.
Specifically, as can be seen from the property of fourier transform, the real-valued matrix coefficients of the real-valued matrix after fourier transform (i.e., the coefficients of the real-valued matrix) are in conjugate symmetry with respect to the origin. For example, the top left coefficient may be retained, and the remaining coefficients are set to 0 and recorded as the coefficient matrix D. And, the real and imaginary components of the coefficient matrix D can be extracted, and the matrix formed by the real and imaginary components can be denoted as D1And the matrix formed by its imaginary components can be denoted as D2。
For example, take 3 × 3 random matrix a (real-valued matrix) as an example:
after two-dimensional discrete Fourier transformation, the following can be obtained:
it can be seen that the matrix F is conjugate symmetric about the origin. Then, the coefficient matrix D corresponding to the matrix F, the matrix D formed by real part components1And a matrix D of imaginary components2Respectively as follows:
it should be noted that, the upper left coefficient of the real-valued matrix after fourier transform is taken as an example, which is only for convenience of illustration and should not be considered as a limitation of the present application, and the lower right coefficient, the lower left coefficient, and the like may also be taken, and are not limited herein.
The reliability of image encryption can be improved by carrying out Fourier transform on the real numerical matrix; determining a coefficient matrix corresponding to the real value matrix after Fourier transformation, and determining a real part component matrix and an imaginary part component matrix of the coefficient matrix, so that a ciphertext of the real value can be obtained, and the ciphertext is convenient to store and transmit; and setting partial coefficients in the real value matrix coefficients to be zero, and determining the coefficient matrix, wherein the ciphertext determined by the method has higher security.
In this embodiment, in order to further improve the security of the ciphertext and improve the convenience of storage and transmission, the determined coefficient matrix D and the matrix D composed of the partial quantity thereof may be subjected to1A matrix D formed by the imaginary components thereof2Further processing is carried out.
Illustratively, pair D, D may be paired as follows1、D2Processing is carried out to construct a new ciphertext matrix E:
the operation of the floud (·) represents the up-down inversion, and the flolr (·) represents the left-right inversion.
For example, for the matrix D, D in the above example1、D2By carrying out corresponding treatment, the following can be obtained:
by adopting the transformation mode to construct the new ciphertext matrix E, the security of the ciphertext can be further improved. The conversion method is not limited to this, and 1 or 2 inversions may be performed in addition to the conversion method, or the method of obtaining D may be employed1、D2Is divided by 2 and the inverted D is added1、D2The average of the sum of (1) is not limited herein.
The encryption method of the multi-channel image provided by the embodiment of the application is verified by a practical example with reference to fig. 2-4.
Referring to fig. 2-4, fig. 2 is a multi-channel image to be encrypted (the multi-channel image to be encrypted in fig. 2 is a gray scale image, and a color image is used in the actual verification process), and the size of each image is 256 × 256.
Fig. 3 shows the encryption result obtained after encrypting the three images in fig. 2 by using the encryption method for multi-channel images according to this embodiment. It can be seen that no meaningful information of the plaintext image can be extracted from the encryption result, thereby illustrating the effectiveness of the encryption method.
The result obtained after decrypting the encrypted image with the correct ciphertext is shown in fig. 4, which shows that the original plaintext image can be recovered with high quality. The decrypted image peak signal-to-noise ratios are 306.7519dB (decibel), 306.3338dB, 306.9864dB, respectively.
Referring to fig. 5, based on the same inventive concept, an embodiment of the present application further provides a multi-channel image encryption apparatus 10, including:
the image encoding module 11 is configured to encode a multi-channel image to be encrypted into a quaternion matrix, where the multi-channel image includes four components, which correspond to a real component and three imaginary components of a quaternion, respectively.
And the mask generating module 12 is configured to generate a chaotic phase mask according to the multi-channel image to be encrypted.
And a quaternion transformation module 13, configured to perform quaternion transformation on the quaternion matrix in combination with the chaotic phase mask.
And a real-valued matrix module 14, configured to determine a real-valued matrix according to the quaternion matrix after quaternion transformation, where the real-valued matrix includes a real component and an imaginary component of the quaternion matrix after quaternion transformation.
And the ciphertext determining module 15 is configured to determine a ciphertext based on the real value matrix.
In this embodiment, the mask generating module 12 is further configured to perform normalization processing on the multichannel image to be encrypted, and calculate a variance of the normalized multichannel image; and determining the chaotic phase mask according to the size and the variance of the multi-channel image to be encrypted.
In this embodiment, the quaternion transform module 13 is further configured to encode the quaternion matrix according to the chaotic phase mask; and carrying out quaternion Gyrator transformation on the coded quaternion matrix.
In this embodiment, the real-valued matrix module 14 is further configured to extract a real component and an imaginary component of the quaternion matrix after quaternion transformation; determining a real matrix according to the extracted real component and imaginary component; and expanding the real matrix to determine the real numerical value matrix.
In this embodiment, the ciphertext determining module 15 is further configured to perform fourier transform on the real value matrix; and determining the ciphertext according to the real numerical matrix after Fourier transform.
In this embodiment, the ciphertext determining module 15 is further configured to determine a coefficient matrix according to the coefficient of the real value matrix after the fourier transform; determining a real component matrix and an imaginary component matrix corresponding to the coefficient matrix based on the coefficient matrix; and determining the ciphertext according to the real component matrix and the imaginary component matrix.
In this embodiment, the ciphertext determining module 15 is further configured to determine a real value matrix coefficient of the real value matrix after the fourier transform; and setting partial coefficients in the real value matrix coefficients to be zero, and determining the coefficient matrix.
Embodiments of the present application also provide a storage medium storing one or more programs executable by one or more processors to implement the steps of the multi-channel image encryption method as described in the detailed description.
Referring to fig. 6, an embodiment of the present application further provides an electronic device 20, where the multi-channel image encryption apparatus 10 may be embedded in the electronic device 20, and the electronic device 20 may call the multi-channel image encryption apparatus 10 to execute a multi-channel image encryption method when running.
In this embodiment, the electronic device 20 may be a terminal, such as a smart phone, a tablet computer, a personal digital assistant, and the like; the electronic device 20 may also be a server, such as a network server, a cloud server, a server cluster, a data server, etc., and is not limited herein.
Illustratively, the electronic device 20 may include: a communication module 22 connected to the outside world via a network, one or more processors 24 for executing program instructions, a bus 23, and a different form of Memory 21, such as a magnetic disk, a ROM (Read-Only Memory), or a RAM (Random Access Memory), or any combination thereof.
Illustratively, the memory 21 has stored therein a program. The processor 24 may call and execute these programs from the memory 21 so that the multi-channel image encryption method can be performed by executing the programs. The processor 24 can implement encryption of the multi-channel image to be encrypted by executing the multi-channel image encryption method, so as to facilitate transmission and storage while ensuring the security of image encryption.
In summary, embodiments of the present application provide a method, an apparatus, a storage medium, and an electronic device for multi-channel image encryption, which can effectively ensure reliability of image encryption by generating a chaotic phase mask based on a multi-channel image to be encrypted and performing quaternion transformation. And based on the quaternion matrix after quaternion transformation, determining a real value matrix covering the real component and the imaginary component of the quaternion matrix after transformation, and determining a ciphertext based on the real value matrix, so that the reliability of image encryption can be further improved, the multi-channel component of the multi-channel image can be encoded into a whole, the transmission efficiency can be effectively improved, and the storage is convenient.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. The above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is merely a logical division, and there may be other divisions in actual implementation, and for example, a plurality of modules or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or modules through some communication interfaces, and may be in an electrical, mechanical or other form.
Furthermore, the functional modules in the embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
In this document, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions.
The above description is only an example of the present application and is not intended to limit the scope of the present application, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, improvement and the like made within the spirit and principle of the present application shall be included in the protection scope of the present application.