1
1
#include < stdio.h>
2
+ #include < bits/stdc++.h>
2
3
#include < opencv2/opencv.hpp>
3
4
4
5
using namespace cv ;
5
6
using namespace std ;
6
7
7
8
const int MAX=1e4 +79 ;
9
+ bool flag[513 ][513 ];
8
10
9
11
int main ()
10
12
{
11
- Mat image;
12
- double x[ 102 ] ;
13
- double u; // u is the control parameter for chaotic map,also known as population rate
13
+ Mat image;
14
+ vector<pair< double , int >> x ;
15
+ double u= 3.94 ,hold,temp; // u is the control parameter for chaotic map,also known as population rate
14
16
15
- image = imread ( " Image.jpg" , 1 );
17
+ image = imread ( " Image/sample_image_grey .jpg" , 1 );
16
18
if ( !image.data )
17
19
{
18
- cout<<" No image data \n " ;
19
- return -1 ;
20
+ cout<<" No image data \n " ;
21
+ return -1 ;
20
22
}
21
- // Applying Logistic map
22
- u=3.94 ; // It is the condition for logistic map
23
- x[0 ]=0.4 ; // Base condition for logistic map
24
- for (int i = 1 ; i <= 100 ; ++i)
25
- x[i]=u*x[i-1 ]*(1 -x[i-1 ]);
26
- sort (x,x+100 );
27
-
28
- // reading image pixel
23
+
24
+ x.push_back ({0.4 ,0 });
25
+ memset (flag ,false ,sizeof (flag));
26
+
27
+ for (int i = 1 ; i <= 511 ; ++i){
28
+ temp=x[i-1 ].first ;
29
+ hold=u*temp*(1 -temp);
30
+ x.push_back ({hold,i});
31
+ }
32
+ sort (x.begin (), x.end ());
33
+
29
34
int i=1 ;
30
35
int l;
31
36
37
+ imshow (" Shubham@shaurya" , image);
38
+ waitKey (0 );
39
+
40
+ i=0 ;
41
+ int holds[4 ];
32
42
for (int r = 0 ; r < image.rows ; ++r) {
33
- for (int c = 0 ; c < image.cols ; ++c) {
34
- if (i>100 ){
35
- i=1 ;
36
- }
37
- l=x[i]*MAX;
38
- l=l%255 ;
39
- // cout << "Pixel at position (x, y) : (" << c << ", " << r << ") =";
40
- image.at <Vec3b>(r,c)[0 ]=image.at <Vec3b>(r,c)[0 ]^l;
41
- image.at <Vec3b>(r,c)[1 ]=image.at <Vec3b>(r,c)[1 ]^l;
42
- image.at <Vec3b>(r,c)[2 ]=image.at <Vec3b>(r,c)[2 ]^l;
43
- i++;
44
- }
43
+ for (int c = 0 ; c < image.cols ; ++c) {
44
+ if (i>511 )
45
+ i=0 ;
46
+ int temps= x[i].second ;
47
+
48
+ holds[0 ]= image.at <Vec3b>(r,temps)[0 ];
49
+ image.at <Vec3b>(r,temps)[0 ]=image.at <Vec3b>(r,c)[0 ];
50
+ image.at <Vec3b>(r,c)[0 ]=holds[0 ];
51
+
52
+ holds[1 ]= image.at <Vec3b>(r,temps)[1 ];
53
+ image.at <Vec3b>(r,temps)[1 ]=image.at <Vec3b>(r,c)[1 ];
54
+ image.at <Vec3b>(r,c)[1 ]=holds[1 ];
55
+
56
+
57
+ holds[2 ]= image.at <Vec3b>(r,temps)[2 ];
58
+ image.at <Vec3b>(r,temps)[2 ]=image.at <Vec3b>(r,c)[2 ];
59
+ image.at <Vec3b>(r,c)[2 ]=holds[2 ];
60
+
61
+ i++;
62
+ }
45
63
}
46
-
47
- imwrite (" encryptedImage.jpg" ,image);
64
+
65
+ for (int r = 0 ; r < image.rows ; ++r) {
66
+ for (int c = 0 ; c < image.cols ; ++c) {
67
+ if (i>100 ){
68
+ i=1 ;
69
+ }
70
+ l=x[i].first *MAX;
71
+ l=l%255 ;
72
+ image.at <Vec3b>(r,c)[0 ]=image.at <Vec3b>(r,c)[0 ]^l;
73
+ image.at <Vec3b>(r,c)[1 ]=image.at <Vec3b>(r,c)[1 ]^l;
74
+ image.at <Vec3b>(r,c)[2 ]=image.at <Vec3b>(r,c)[2 ]^l;
75
+ i++;
76
+ }
77
+ }
78
+
79
+
80
+ imwrite (" Image/encrypted_image.jpg" ,image);
81
+ imshow (" Shubham@shaurya" , image);
82
+ waitKey (0 );
83
+
84
+ i=1 ;
85
+ for (int r = 0 ; r < image.rows ; ++r) {
86
+ for (int c = 0 ; c < image.cols ; ++c) {
87
+ if (i>100 ){
88
+ i=1 ;
89
+ }
90
+ l=x[i].first *MAX;
91
+ l=l%255 ;
92
+ image.at <Vec3b>(r,c)[0 ]=image.at <Vec3b>(r,c)[0 ]^l;
93
+ image.at <Vec3b>(r,c)[1 ]=image.at <Vec3b>(r,c)[1 ]^l;
94
+ image.at <Vec3b>(r,c)[2 ]=image.at <Vec3b>(r,c)[2 ]^l;
95
+ i++;
96
+ }
97
+ }
98
+
99
+ i=511 ;
100
+ for (int r = image.rows -1 ; r >= 0 ; --r) {
101
+ for (int c = image.cols -1 ; c >= 0 ; --c) {
102
+ if (i<0 )
103
+ i=511 ;
104
+ int temps= x[i].second ;
105
+
106
+ holds[0 ]= image.at <Vec3b>(r,temps)[0 ];
107
+ image.at <Vec3b>(r,temps)[0 ]=image.at <Vec3b>(r,c)[0 ];
108
+ image.at <Vec3b>(r,c)[0 ]=holds[0 ];
109
+
110
+ holds[1 ]= image.at <Vec3b>(r,temps)[1 ];
111
+ image.at <Vec3b>(r,temps)[1 ]=image.at <Vec3b>(r,c)[1 ];
112
+ image.at <Vec3b>(r,c)[1 ]=holds[1 ];
113
+
114
+
115
+ holds[2 ]= image.at <Vec3b>(r,temps)[2 ];
116
+ image.at <Vec3b>(r,temps)[2 ]=image.at <Vec3b>(r,c)[2 ];
117
+ image.at <Vec3b>(r,c)[2 ]=holds[2 ];
118
+
119
+ i--;
120
+ }
121
+ }
122
+
48
123
namedWindow (" Shubham@shaurya" , WINDOW_AUTOSIZE );
49
124
imshow (" Shubham@shaurya" , image);
50
125
waitKey (0 );
51
126
52
127
return 0 ;
53
- }
128
+ }
0 commit comments