how to confusion image by sin-cos map?

1 Ansicht (letzte 30 Tage)
Arshub
Arshub am 10 Dez. 2021
Kommentiert: Voss am 10 Dez. 2021
I try to implement algorithm in this paper:An efficient color image encryption scheme based on a matrix scrambling method and a new hybrid chaotic map.
This is my cod to implement confusion phase for the algorithm an i write cod for gray image only, please corret it.
in my cod i have two problem, firstly :Error in sc (line 26)
b(j+1)=rem(a(j+1),s);Error using rem :Arguments must be real.
secondly:Pos array have negative no, so should i use abs function to covert all values to positive value ?
close all;
clear all;
clc;
tic
timg = imread('lena_gray.jpg');
[row,col]=size(timg);
s=row*col;
tencr=reshape(timg,s,1);% 1 means 1 col to make matrix in one dim
x=nan(1,s+1); %<------------PREALLOCATE!!!
y=nan(1,s+1); %<------------PREALLOCATE!!!
Pos=nan(1,s+1); %<------------PREALLOCATE!!!
a=nan(1,s+1);
x(1)=.75;
z=.95;% initial value for cofusion
E=.78;% initial value for cofusion
u=1.58;% initial value for cofusion
D(1) = 0.98; % initial value for diffusion
G(1) = 0.96 ; % % initial value for diffusion
y(1)=u*x(1)*(1-x(1));% initial value
for j=1:s
r=(z/y(j))^(3/2);
x(j+1)=sin(r);
w=E*acos(x(j));
y(j+1)=cos(w);
a(j+1)=x(j+1)*(10^14);
b(j+1)=rem(a(j+1),126000);
Pos(j+1) = round (b(j+1));
%Pos(j+1) = round (rem(a(j+1),s));
disp(Pos);
end
%a=x(1,2:s+1)*(10^14);
%z=uint8( rem(a,256) );
%Pos=rem(a,s);
% Make all values in Pos array positive
%g=abs(Pos);
%disp(g);
%Start of Encryption
encrimg=[];
for m = 1:s
encrimg(m)=tencr(Pos(m));
end
ImageEncr=reshape(encrimg,row,col);% convert matrix to 2D
figure
imshow(ImageEncr)
%Start of Decryption
tdecr=reshape(ImageEncr,s,1);
decrimg=[];
for m = 1:s
decrimg(Pos(m))=tdecr(m);
end
ImageDecr=reshape(decrimg,row,col);
figure
imshow(ImageDecr);

Akzeptierte Antwort

Voss
Voss am 10 Dez. 2021
At some point in your for j=1:s loop, y(j+1) becomes negative, so in the next iteration r is complex. This is the source of the "Arguments must be real" error. I don't know how you might fix it.
Regarding the negative Pos question, you may consider using mod instead of rem so that a negative argument returns a positive remainder. I don't think doing abs is what you want, but it's hard to say for sure.
  2 Kommentare
Arshub
Arshub am 10 Dez. 2021
Thank you, yes in algorithm used mod operation, I was wrong about this, but there is still a problem "Arguments must be real" error.
Voss
Voss am 10 Dez. 2021
At some point in your for j=1:s loop, y(j+1) becomes negative, so in the next iteration r is complex. This is the source of the "Arguments must be real" error. I don't know how you might fix it.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2014a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by