1
- #include < stdio .h>
1
+ #include < bits/stdc++ .h>
2
2
#include < opencv2/opencv.hpp>
3
3
4
4
using namespace cv ;
5
5
using namespace std ;
6
6
7
7
const int MAX=1e4 +79 ;
8
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
+ */
15
+
9
16
int main ()
10
17
{
11
- Mat image;
12
- double x[102 ];
13
- double u; // u is the control parameter for chaotic map,also known as population rate
14
-
15
- image = imread ( " encryptedImage.jpg" , 1 );
16
- if ( !image.data )
17
- {
18
- cout<<" No image data \n " ;
19
- return -1 ;
18
+ Mat image;
19
+ int i,l;
20
+ double u=3.94 ;
21
+ vector<pair<double ,int >> x;
22
+ Vec<unsigned char , 3 > pixel;
23
+
24
+ image = imread (" Image/encrypted_image.jpg" , 0 );
25
+ if ( !image.data )
26
+ {
27
+ cout<<" No image data \n " ;
28
+ return -1 ;
29
+ }
30
+
31
+ x.push_back ({0.4 ,0 });
32
+
33
+
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
+ }
39
+
40
+ sort (x.begin (), x.end ());
41
+
42
+ imshow (" Decrepted image" , image);
43
+ waitKey (0 );
44
+
45
+ i=1 ;
46
+ for (int r = 0 ; r < image.rows ; ++r) {
47
+ for (int c = 0 ; c < image.cols ; ++c) {
48
+ if (i>100 ){
49
+ i=1 ;
50
+ }
51
+ l=x[i].first *MAX;
52
+ l=l%255 ;
53
+ image.at <Vec3b>(r,c)[0 ]=image.at <Vec3b>(r,c)[0 ]^l;
54
+ image.at <Vec3b>(r,c)[1 ]=image.at <Vec3b>(r,c)[1 ]^l;
55
+ image.at <Vec3b>(r,c)[2 ]=image.at <Vec3b>(r,c)[2 ]^l;
56
+ i++;
20
57
}
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
29
- int i=1 ;
30
- int l;
31
-
32
- 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
- }
45
- }
46
- namedWindow (" Shubham@shaurya" , WINDOW_AUTOSIZE );
47
- imshow (" Shubham@shaurya" , image);
48
- waitKey (0 );
49
-
50
- return 0 ;
58
+ }
59
+
60
+ i=511 ;
61
+ for (int r = image.rows -1 ; r >= 0 ; --r) {
62
+ for (int c = image.cols -1 ; c >= 0 ; --c) {
63
+ if (i<0 )
64
+ i=511 ;
65
+ int temps= x[i].second ;
66
+
67
+ pixel= image.at <Vec3b>(r,temps);
68
+ image.at <Vec3b>(r,temps)=image.at <Vec3b>(r,c);
69
+ image.at <Vec3b>(r,c)=pixel;
70
+
71
+ i--;
72
+ }
73
+ }
74
+
75
+ namedWindow (" Original_image" , WINDOW_AUTOSIZE );
76
+ imshow (" Original_image" , image);
77
+ waitKey (0 );
78
+
79
+ return 0 ;
80
+
51
81
}
0 commit comments