how to confusion image by sin-cos map?

1 visualización (últimos 30 días)
Arshub
Arshub el 10 de Dic. de 2021
Comentada: Voss el 10 de Dic. de 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);

Respuesta aceptada

Voss
Voss el 10 de Dic. de 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 comentarios
Arshub
Arshub el 10 de Dic. de 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 el 10 de Dic. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Productos


Versión

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by