Ask Your Question
1

Anold Transform

asked 2015-02-02 04:11:36 -0600

Mahavir gravatar image

updated 2015-02-07 04:20:27 -0600

Hello every one, I have written code for image scrambling and inverse scrambling using Arnold transform. Inputs: 1. number of iterations for scrambling is any arbitary number between 0 and period of Arnold transform for the given size=enciter. 2. 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;
            }

image description

edit retag flag offensive close merge delete

Comments

1

since you do a modulo anyway, might as well add (a multiple) of 128

int i1=(128 + 2*j - i)%128;
int j1=(128 + i - j)%128;
berak gravatar imageberak ( 2015-02-02 04:41:38 -0600 )edit
1

hi @Mahavir, with your latest edit, the question somehow got lost.

what's the problem with in now ?

berak gravatar imageberak ( 2015-02-07 04:23:08 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2015-02-07 05:18:21 -0600

Mahavir gravatar image

updated 2015-02-14 13:00:42 -0600

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 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 ...
(more)
edit flag offensive delete link more

Comments

ah, ok, nice ;)

berak gravatar imageberak ( 2015-02-07 05:24:50 -0600 )edit

Nice one! next time you can pull people you mention to the topic by adding an @ in front of their name! Might consider adding this transform into the repository through a PR? Or maybe make a tutorial based on encoding/decoding?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-02-16 08:46:53 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-02-02 04:11:36 -0600

Seen: 1,512 times

Last updated: Feb 14 '15