필터 지우기
필터 지우기

how to confusion image by sin-cos map?

조회 수: 3 (최근 30일)
Arshub
Arshub 2021년 12월 10일
댓글: Voss 2021년 12월 10일
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);

채택된 답변

Voss
Voss 2021년 12월 10일
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
Arshub
Arshub 2021년 12월 10일
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 2021년 12월 10일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by