1 | initial version |
@ berak sir, Sir I hv posted this code for other users. I have implemented arnold transform..I hv no questions in this regard...I am correcting my self by writing code in answer instead in question..
2 | No.2 Revision |
@ berak sir, Sir I hv posted this code for other users. I have implemented arnold transform..I hv no questions in this regard...I am correcting my self by writing code in answer instead in question..
code for image scrambling and inverse scrambling using Arnold transform.
Inputs:
number of iterations for scrambling is any arbitary number between 0 and period of Arnold transform for the given size=enciter.
number of iterations for inverse scrambling=>deciter = period-enciter. for 128x128 image period of arnold transform is 96. Refer relevant pepper of arnold tranform for periods of different sizes .
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\core\core.hpp>
#include <opencv2\core\mat.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include<opencv2\features2d\features2d.hpp>
#include<iostream>
#include<math.h>
#include<conio.h>
using namespace std;
using namespace cv;
class image
{
public:
Mat im,im1,im2,im3,cs,im_enc,frame;
int getim();
};
int image::getim()
{
im=imread("Caption.png",0);
if (im.empty())
{
cout << "Error : Image cannot be loaded..!!" << endl;
return -1;
}
resize(im,im,Size(128,128),0.0,0.0,1);
imshow("Input Image",im);
Mat temp=Mat::zeros(im.size(),im.type());
double m=im.rows,x,x1,y,y1;
int enciter=50;
int deciter=96-enciter;
for(int iter=0;iter<enciter;iter++)
{
for(double i=0;i<m;i++)
{
for(double j=0;j<m;j++)
{
x=fmod((i+j),m);
y=fmod((i+2*j),m);
temp.at<uchar>(x,y)=im.at<uchar>(i,j);
}
}
temp.copyTo(im);
temp=Mat::zeros(im.size(),im.type());
}
imshow("Scrambled Image",im);
for(int iter=0;iter<deciter;iter++)
{
for(double i=0;i<m;i++)
{
for(double j=0;j<m;j++)
{
x=fmod((i+j),m);
y=fmod((i+2*j),m);
temp.at<uchar>(x,y)=im.at<uchar>(i,j);
}
}
temp.copyTo(im);
temp=Mat::zeros(im.size(),im.type());
}
imshow("Inverse Scrambled Image",im);
waitKey(0);
return 0;
}
int main()
{
image my;
my.getim();
return 0;
}
3 | No.3 Revision |
@ berak sir,
Sir I hv posted this code for other users. Hello Everyone,
I have implemented written an adaptive algorithm for arnold transform..I hv no questions in this regard...I am correcting my self by writing code in answer instead in question..
code for transform. Here we have to give only order of image scrambling from 2 to 128 and inverse scrambling using Arnold transform.
Inputs:
number of iterations for scrambling is any arbitary number between 0 and algorithm calculates respective period of Arnold transform for the given size=enciter.
number of iterations for inverse scrambling=>deciter = period-enciter.
for 128x128 image period of arnold transform is 96.
Refer relevant pepper of arnold tranform for AT, encryption and decryption iterations.
I have calculated periods of different sizes .AT for 2 to 128 image size and stored in .csv file
Order of image: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
Respective Period of AT : 12 12 12 10 12 16 12 12 30 10 12 14 24 20 12 18 12 18 38 36 56 60 40 48 44 45 60 48 48 36 56 150 36 42 54 36 40 48 36 42 58 60 60 45 48 48 70 60 68 36 48 120 35 36 74 114 100 36 40 84 39 60 108 60 84 48 90 132 56 60 44 60 56 48 60 48 90 48 98 60 60 150
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\core\core.hpp>
#include <opencv2\core\mat.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include<opencv2\features2d\features2d.hpp>
#include<iostream>
#include<math.h>
#include<conio.h>
#include<fstream>
#include<sstream>
#include<string>
using namespace std;
using namespace cv;
char filename[80];
class image
{
public:
Mat im,im1,im2,im3,cs,im_enc,frame;
im,vect_look,temp;
int period,enciter,deciter,wmr;
double m,x,x1,y,y1;
int getim();
};
int image::getim()
{
im=imread("Caption.png",0);
threshold(im,im,128,255,THRESH_BINARY);
if (im.empty())
{
cout << "Error : Image cannot be loaded..!!" << endl;
return -1;
}
resize(im,im,Size(128,128),0.0,0.0,1);
cout<<"\nEnter the order of image between 2 to 128 for resizing";
cin>>wmr;
resize(im.clone(),im,Size(wmr,wmr),0.0,0.0,1);
imshow("Input Resized Image",im);
Mat temp=Mat::zeros(im.size(),im.type());
double m=im.rows,x,x1,y,y1;
int enciter=50;
int deciter=96-enciter;
// Reading CSV file which contains periods of Arnold Transform for given order of image
ifstream inputfile("periods of AT.csv");
string current_line;
vector< vector<int> > all_data;
while(getline(inputfile, current_line))
{
vector<int> values;
stringstream temp(current_line);
string single_value;
while(getline(temp,single_value,','))
{
values.push_back(atoi(single_value.c_str()));
}
all_data.push_back(values);
}
// Copying values from vector to matrix
vect_look = Mat::zeros((int)all_data.size(), (int)all_data[0].size(), CV_8UC1);
for(int rows = 0; rows < (int)all_data.size(); rows++)
{
for(int cols= 0; cols< (int)all_data[0].size(); cols++)
{
vect_look.at<uchar>(rows,cols) = all_data[rows][cols];
}
}
for(int look_count=0;look_count<vect_look.cols;look_count++)
{
if(vect_look.at<uchar>(0,look_count)==wmr)
{
period=vect_look.at<uchar>(1,look_count);
break;
}
}
// Assign values to encryption and decryption iterations
cout<<"\n\nPeriod of Arnold Transform for order "<<wmr<<"="<<period;
enciter=floor(double(period/2))-5;
deciter=period-enciter;
for(int iter=0;iter<enciter;iter++)
{
for(double i=0;i<m;i++)
i=0;i<wmr;i++)
{
for(double j=0;j<m;j++)
j=0;j<wmr;j++)
{
x=fmod((i+j),m);
y=fmod((i+2*j),m);
x=fmod((i+j),wmr);
y=fmod((i+2*j),wmr);
temp.at<uchar>(x,y)=im.at<uchar>(i,j);
}
}
temp.copyTo(im);
temp=Mat::zeros(im.size(),im.type());
}
imshow("Scrambled Image",im);
for(int iter=0;iter<deciter;iter++)
{
for(double i=0;i<m;i++)
i=0;i<wmr;i++)
{
for(double j=0;j<m;j++)
j=0;j<wmr;j++)
{
x=fmod((i+j),m);
y=fmod((i+2*j),m);
x=fmod((i+j),wmr);
y=fmod((i+2*j),wmr);
temp.at<uchar>(x,y)=im.at<uchar>(i,j);
}
}
temp.copyTo(im);
temp=Mat::zeros(im.size(),im.type());
}
imshow("Inverse Scrambled Image",im);
waitKey(0);
return 0;
}
int main()
{
image my;
my.getim();
return 0;
}
4 | No.4 Revision |
Hello Everyone,
I have written an adaptive algorithm for arnold transform. Here we have to give only order of image from 2 to 128 100 and algorithm calculates respective period of AT, encryption and decryption iterations.
I have calculated periods of AT for 2 to 128 100 image size and stored in .csv file
Order of image: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
Respective Period of AT : 12 12 12 10 12 16 12 12 30 10 12 14 24 20 12 18 12 18 38 36 56 60 40 48 44 45 60 48 48 36 56 150 36 42 54 36 40 48 36 42 58 60 60 45 48 48 70 60 68 36 48 120 35 36 74 114 100 36 40 84 39 60 108 60 84 48 90 132 56 60 44 60 56 48 60 48 90 48 98 60 60 150
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\core\core.hpp>
#include <opencv2\core\mat.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include<opencv2\features2d\features2d.hpp>
#include<iostream>
#include<math.h>
#include<conio.h>
#include<fstream>
#include<sstream>
#include<string>
using namespace std;
using namespace cv;
char filename[80];
class image
{
public:
Mat im,vect_look,temp;
int period,enciter,deciter,wmr;
double m,x,x1,y,y1;
int getim();
};
int image::getim()
{
im=imread("Caption.png",0);
threshold(im,im,128,255,THRESH_BINARY);
if (im.empty())
{
cout << "Error : Image cannot be loaded..!!" << endl;
return -1;
}
cout<<"\nEnter the order of image between 2 to 128 for resizing";
cin>>wmr;
resize(im.clone(),im,Size(wmr,wmr),0.0,0.0,1);
imshow("Input Resized Image",im);
temp=Mat::zeros(im.size(),im.type());
// Reading CSV file which contains periods of Arnold Transform for given order of image
ifstream inputfile("periods of AT.csv");
string current_line;
vector< vector<int> > all_data;
while(getline(inputfile, current_line))
{
vector<int> values;
stringstream temp(current_line);
string single_value;
while(getline(temp,single_value,','))
{
values.push_back(atoi(single_value.c_str()));
}
all_data.push_back(values);
}
// Copying values from vector to matrix
vect_look = Mat::zeros((int)all_data.size(), (int)all_data[0].size(), CV_8UC1);
for(int rows = 0; rows < (int)all_data.size(); rows++)
{
for(int cols= 0; cols< (int)all_data[0].size(); cols++)
{
vect_look.at<uchar>(rows,cols) = all_data[rows][cols];
}
}
for(int look_count=0;look_count<vect_look.cols;look_count++)
{
if(vect_look.at<uchar>(0,look_count)==wmr)
{
period=vect_look.at<uchar>(1,look_count);
break;
}
}
// Assign values to encryption and decryption iterations
cout<<"\n\nPeriod of Arnold Transform for order "<<wmr<<"="<<period;
enciter=floor(double(period/2))-5;
deciter=period-enciter;
for(int iter=0;iter<enciter;iter++)
{
for(double i=0;i<wmr;i++)
{
for(double j=0;j<wmr;j++)
{
x=fmod((i+j),wmr);
y=fmod((i+2*j),wmr);
temp.at<uchar>(x,y)=im.at<uchar>(i,j);
}
}
temp.copyTo(im);
temp=Mat::zeros(im.size(),im.type());
}
imshow("Scrambled Image",im);
for(int iter=0;iter<deciter;iter++)
{
for(double i=0;i<wmr;i++)
{
for(double j=0;j<wmr;j++)
{
x=fmod((i+j),wmr);
y=fmod((i+2*j),wmr);
temp.at<uchar>(x,y)=im.at<uchar>(i,j);
}
}
temp.copyTo(im);
temp=Mat::zeros(im.size(),im.type());
}
imshow("Inverse Scrambled Image",im);
waitKey(0);
return 0;
}
int main()
{
image my;
my.getim();
return 0;
}
5 | No.5 Revision |
Hello Everyone,
I have written an adaptive algorithm for arnold transform. Here we have to give only order of image from 2 to 100 and algorithm calculates respective period of AT, encryption and decryption iterations.
I have calculated periods of AT for 2 to 100 image size and stored in .csv filefile.
I am very much thankful to StevenPuttemans for his help for 'reading .csv file part'.
Order of image: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
Respective Period of AT : 12 12 12 10 12 16 12 12 30 10 12 14 24 20 12 18 12 18 38 36 56 60 40 48 44 45 60 48 48 36 56 150 36 42 54 36 40 48 36 42 58 60 60 45 48 48 70 60 68 36 48 120 35 36 74 114 100 36 40 84 39 60 108 60 84 48 90 132 56 60 44 60 56 48 60 48 90 48 98 60 60 150
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\core\core.hpp>
#include <opencv2\core\mat.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include<opencv2\features2d\features2d.hpp>
#include<iostream>
#include<math.h>
#include<conio.h>
#include<fstream>
#include<sstream>
#include<string>
using namespace std;
using namespace cv;
char filename[80];
class image
{
public:
Mat im,vect_look,temp;
int period,enciter,deciter,wmr;
double m,x,x1,y,y1;
int getim();
};
int image::getim()
{
im=imread("Caption.png",0);
threshold(im,im,128,255,THRESH_BINARY);
if (im.empty())
{
cout << "Error : Image cannot be loaded..!!" << endl;
return -1;
}
cout<<"\nEnter the order of image between 2 to 128 for resizing";
cin>>wmr;
resize(im.clone(),im,Size(wmr,wmr),0.0,0.0,1);
imshow("Input Resized Image",im);
temp=Mat::zeros(im.size(),im.type());
// Reading CSV file which contains periods of Arnold Transform for given order of image
ifstream inputfile("periods of AT.csv");
string current_line;
vector< vector<int> > all_data;
while(getline(inputfile, current_line))
{
vector<int> values;
stringstream temp(current_line);
string single_value;
while(getline(temp,single_value,','))
{
values.push_back(atoi(single_value.c_str()));
}
all_data.push_back(values);
}
// Copying values from vector to matrix
vect_look = Mat::zeros((int)all_data.size(), (int)all_data[0].size(), CV_8UC1);
for(int rows = 0; rows < (int)all_data.size(); rows++)
{
for(int cols= 0; cols< (int)all_data[0].size(); cols++)
{
vect_look.at<uchar>(rows,cols) = all_data[rows][cols];
}
}
for(int look_count=0;look_count<vect_look.cols;look_count++)
{
if(vect_look.at<uchar>(0,look_count)==wmr)
{
period=vect_look.at<uchar>(1,look_count);
break;
}
}
// Assign values to encryption and decryption iterations
cout<<"\n\nPeriod of Arnold Transform for order "<<wmr<<"="<<period;
enciter=floor(double(period/2))-5;
deciter=period-enciter;
for(int iter=0;iter<enciter;iter++)
{
for(double i=0;i<wmr;i++)
{
for(double j=0;j<wmr;j++)
{
x=fmod((i+j),wmr);
y=fmod((i+2*j),wmr);
temp.at<uchar>(x,y)=im.at<uchar>(i,j);
}
}
temp.copyTo(im);
temp=Mat::zeros(im.size(),im.type());
}
imshow("Scrambled Image",im);
for(int iter=0;iter<deciter;iter++)
{
for(double i=0;i<wmr;i++)
{
for(double j=0;j<wmr;j++)
{
x=fmod((i+j),wmr);
y=fmod((i+2*j),wmr);
temp.at<uchar>(x,y)=im.at<uchar>(i,j);
}
}
temp.copyTo(im);
temp=Mat::zeros(im.size(),im.type());
}
imshow("Inverse Scrambled Image",im);
waitKey(0);
return 0;
}
int main()
{
image my;
my.getim();
return 0;
}
6 | No.6 Revision |
Hello Everyone,
I have written an adaptive algorithm for arnold transform. Here we have to give only order of image from 2 to 100 and algorithm calculates respective period of AT, encryption and decryption iterations.
I have calculated periods of AT for 2 to 100 image size and stored in .csv file.
I am very much thankful to StevenPuttemans for his help for in 'reading .csv file part'.
Order of image: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
Respective Period of AT : 12 12 12 10 12 16 12 12 30 10 12 14 24 20 12 18 12 18 38 36 56 60 40 48 44 45 60 48 48 36 56 150 36 42 54 36 40 48 36 42 58 60 60 45 48 48 70 60 68 36 48 120 35 36 74 114 100 36 40 84 39 60 108 60 84 48 90 132 56 60 44 60 56 48 60 48 90 48 98 60 60 150
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\core\core.hpp>
#include <opencv2\core\mat.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include<opencv2\features2d\features2d.hpp>
#include<iostream>
#include<math.h>
#include<conio.h>
#include<fstream>
#include<sstream>
#include<string>
using namespace std;
using namespace cv;
char filename[80];
class image
{
public:
Mat im,vect_look,temp;
int period,enciter,deciter,wmr;
double m,x,x1,y,y1;
int getim();
};
int image::getim()
{
im=imread("Caption.png",0);
threshold(im,im,128,255,THRESH_BINARY);
if (im.empty())
{
cout << "Error : Image cannot be loaded..!!" << endl;
return -1;
}
cout<<"\nEnter the order of image between 2 to 128 for resizing";
cin>>wmr;
resize(im.clone(),im,Size(wmr,wmr),0.0,0.0,1);
imshow("Input Resized Image",im);
temp=Mat::zeros(im.size(),im.type());
// Reading CSV file which contains periods of Arnold Transform for given order of image
ifstream inputfile("periods of AT.csv");
string current_line;
vector< vector<int> > all_data;
while(getline(inputfile, current_line))
{
vector<int> values;
stringstream temp(current_line);
string single_value;
while(getline(temp,single_value,','))
{
values.push_back(atoi(single_value.c_str()));
}
all_data.push_back(values);
}
// Copying values from vector to matrix
vect_look = Mat::zeros((int)all_data.size(), (int)all_data[0].size(), CV_8UC1);
for(int rows = 0; rows < (int)all_data.size(); rows++)
{
for(int cols= 0; cols< (int)all_data[0].size(); cols++)
{
vect_look.at<uchar>(rows,cols) = all_data[rows][cols];
}
}
for(int look_count=0;look_count<vect_look.cols;look_count++)
{
if(vect_look.at<uchar>(0,look_count)==wmr)
{
period=vect_look.at<uchar>(1,look_count);
break;
}
}
// Assign values to encryption and decryption iterations
cout<<"\n\nPeriod of Arnold Transform for order "<<wmr<<"="<<period;
enciter=floor(double(period/2))-5;
deciter=period-enciter;
for(int iter=0;iter<enciter;iter++)
{
for(double i=0;i<wmr;i++)
{
for(double j=0;j<wmr;j++)
{
x=fmod((i+j),wmr);
y=fmod((i+2*j),wmr);
temp.at<uchar>(x,y)=im.at<uchar>(i,j);
}
}
temp.copyTo(im);
temp=Mat::zeros(im.size(),im.type());
}
imshow("Scrambled Image",im);
for(int iter=0;iter<deciter;iter++)
{
for(double i=0;i<wmr;i++)
{
for(double j=0;j<wmr;j++)
{
x=fmod((i+j),wmr);
y=fmod((i+2*j),wmr);
temp.at<uchar>(x,y)=im.at<uchar>(i,j);
}
}
temp.copyTo(im);
temp=Mat::zeros(im.size(),im.type());
}
imshow("Inverse Scrambled Image",im);
waitKey(0);
return 0;
}
int main()
{
image my;
my.getim();
return 0;
}