how use parfor for image encryption
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi .....
I am trying to write this code in parallel but I couldn't do that :
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [layer_image] = Encryption_SBOX(layer_image,SBox)
[rows,cols,~] = size(layer_image);
%upperLeft
STARTblockImage1_rows=1;
STARTblockImage1_cols=1;
ENDblockImage1_rows=floor(rows/2);
ENDblockImage1_cols=floor(cols/2);
%upperRight
% STARTblockImage2_rows=1;
STARTblockImage2_cols=floor(cols/2);
% ENDblockImage2_rows=floor(rows/2);
% ENDblockImage2_cols=cols;
%lowerLeft
STARTblockImage3_rows=floor(rows/2);
% STARTblockImage3_cols=1;
% ENDblockImage3_rows=rows;
% ENDblockImage3_cols=floor(cols/2);
% lowerRight5
STARTblockImage4_rows=floor(rows/2);
STARTblockImage4_cols=floor(cols/2);
% ENDblockImage4_rows=rows;
% ENDblockImage4_cols=cols;
BZ=16; % block size
% flipfiop=0;
for i=STARTblockImage1_rows:BZ:ENDblockImage1_rows0
for j=STARTblockImage1_cols:BZ:ENDblockImage1_cols
iblock=i;
while(iblock<=i+BZ)&&(iblock<=ENDblockImage1_rows)
jblock=j;
while(jblock<=j+BZ)&&(jblock<=ENDblockImage1_cols)
%upperLeft
x = dec2bin(layer_image(iblock,jblock),8);
x = dec2bin(Temp1(i,j),8);
l = x(1, 1 : 4);
r = x(1, 5 : 8);
ld = bin2dec(l); % row
rd = bin2dec(r); % column
layer_image(iblock,jblock)=SBox(ld+1,rd+1);
% layer_image(iblock,jblock)=flipfiop;
upperRight
if ((jblock+STARTblockImage2_cols)<=cols)
x = dec2bin(layer_image(iblock,(jblock+STARTblockImage2_cols)),8);
l = x(1, 1 : 4);
r = x(1, 5 : 8);
ld = bin2dec(l); % row
rd = bin2dec(r); % column
layer_image(iblock,(jblock+STARTblockImage2_cols))=SBox(ld+1,rd+1);
else
disp(jblock+STARTblockImage2_cols);
end
%lowerLeft
x = dec2bin(layer_image(iblock+STARTblockImage3_rows,jblock),8);
l = x(1, 1 : 4);
r = x(1, 5 : 8);
ld = bin2dec(l); % row
rd = bin2dec(r); % column
layer_image(iblock+STARTblockImage3_rows,jblock)=SBox(ld+1,rd+1);
%lowerRight
x = dec2bin(layer_image(iblock+STARTblockImage4_rows,jblock+STARTblockImage4_cols),8);
l = x(1, 1 : 4);
r = x(1, 5 : 8);
ld = bin2dec(l); % row
rd = bin2dec(r); % column
layer_image(iblock+STARTblockImage4_rows,jblock+STARTblockImage4_cols)=SBox(ld+1,rd+1);
jblock=jblock+1;
end
iblock=iblock+1;
end
end
end
Réponses (1)
Walter Roberson
le 26 Juil 2020
Modifié(e) : Walter Roberson
le 26 Juil 2020
% layer_image(iblock,jblock)=flipfiop;
upperRight
You do not have any function or variable named upperRight
3 commentaires
Walter Roberson
le 28 Juil 2020
If you expect an RGB image then why are you using
Temp1=layer_image(1,floor(cols/2));
which would be for accessing a grayscale or colormap image?
Consider
Temp1=layer_image(1,floor(cols/2),:);
However, if you are only passing in one color pane at a time, then
[rows,cols,~] = size(layer_image);
confuses the issue -- it would not technically be wrong, but it would lead the reader to expect that there is a 3rd dimension.
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!