Logistic map algorithm for image scrambling

asked 2014-09-03 04:43:44 -0500

Mahavir gravatar image

hello , i have written code for image scrambling using logistic map. the code is given below. Similar algortihm works well in MATLAB but in OPENCV i am getting original image as it is. not a scrambled one. How to resolve the problem?

                    #include <opencv2\highgui\highgui.hpp>
            #include <opencv2\core\core.hpp>
            #include <opencv2\core\mat.hpp>
            #include <opencv2\imgproc\imgproc.hpp>
            #include<iostream>
            #include<math.h>
            #include<conio.h>
            using namespace std;
            using namespace cv;

            class image
            {
            public:
                Mat im,im1,im2,cs,im_enc;
                int getim();

            };

            int image::getim()
            {
               im=imread("logo1.jpg",0);

                if (im.empty()) 

                {
                  cout << "Error : Image cannot be loaded..!!" << endl;
                  return -1;
                }

                         im1=Mat::zeros(im.rows,im.cols,CV_8U);
                         threshold(im,im1,128,255,1);
                         cs=Mat::zeros(im.rows,im.cols,CV_8U);
                        im_enc=Mat::zeros(im.rows,im.cols,CV_8U);
                        float x_new,x_old=0.7;

                for(int rc=1;rc<im1.rows+1;rc++)
                {
                    for(int cc=1;cc<im1.cols+1;cc++)
                    {
                        for(int iter=1;iter<rc*cc+1;iter++)
                        {

                            x_new=x_old*4*(1-x_old);   //Logistic map
                            x_old=x_new;

                        }

                        if(x_old>=0.5)
                            cs.at<uchar>(rc,cc)=255;
                        else
                            cs.at<uchar>(rc,cc)=0;


                    }
                }

                bitwise_xor(im1,cs,im_enc,noArray());
                waitKey(4000);
                cout<<""<<im_enc;
                namedWindow("Scrambled Image",CV_WINDOW_AUTOSIZE);
                imshow("Scrambled Image",im_enc);
                waitKey(0);
                return 0;

            }

            int main()
            {
                image my;
                my.getim();
                return 0;
            }
edit retag flag offensive close merge delete

Comments

1

it scrambles nicely here.

image description

image description

btw, rc<im1.rows+1 will overflow. (consider running a debug build, to get proper exceptions thrown)

berak gravatar imageberak ( 2014-09-03 06:20:50 -0500 )edit
1

why not start your iterations at 0 [which is standard everywhere besides matlab ...] and run to the length of the image. That will remove the error presented to you by @berak and make sure you will not run into buffer overflow problems ...

StevenPuttemans gravatar imageStevenPuttemans ( 2014-09-03 06:37:22 -0500 )edit
1

oohh, right. did not even see it was starting with 1. ;)

berak gravatar imageberak ( 2014-09-03 06:48:36 -0500 )edit

It is a classical mistake when people switch code from matlab to opencv! I even have this in the things not to forget section for my students :P

StevenPuttemans gravatar imageStevenPuttemans ( 2014-09-03 07:35:55 -0500 )edit

Thanks a lot Berak sir and Steven Sir for useful comments..

Mahavir gravatar imageMahavir ( 2014-09-04 02:06:00 -0500 )edit
1

@Mahavir, just out of curiosity, what are you doing with the output ?

berak gravatar imageberak ( 2014-09-04 02:08:04 -0500 )edit

One guess could be he is making a scrambler-descrambler setup to make sure noone without the tool can see the true content of the image.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-09-04 03:00:58 -0500 )edit
1

poor man's encryption ;)

berak gravatar imageberak ( 2014-09-04 03:09:53 -0500 )edit
2

@ berak Sir, i wanted to do scrambling of watermark b4 insertion in host image.

Mahavir gravatar imageMahavir ( 2014-09-09 01:52:24 -0500 )edit