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