我正在从文件夹中选取图像。尺寸为128*128。为此,我使用以下代码行:
[FileName,PathName] = uigetfile('*.jpg','Select the Cover Image');
file = fullfile(PathName,FileName);
disp(['User selected : ', file]);
cover = imread(file);
%cover = double(cover);
if ndims(cover) ~= 3
msgbox('The cover image must be colour');
break;
end
figure(1);
subplot(1,2,1);
imshow(uint8(cover),[]);
title('Cover image');
%num specifies the number of Iterations for the Arnold Transform
num = input('\nEnter the value of num: ');
encrypted = arnold(cover,num);
imshow(encrypted);
功能arnold
如下:
function [ out ] = arnold( in, iter )
if (ndims(in) ~= 2)
error('Oly two dimensions allowed');
end
[m n] = size(in);
if (m ~= n)
error(['Arnold Transform is defined only for squares. ' ...
'Please complete empty rows or columns to make the square.']);
end
out = zeros(m);
n = n - 1;
for j=1:iter
for y=0:n
for x=0:n
p = [ 1 1 ; 1 2 ] * [ x ; y ];
out(mod(p(2), m)+1, mod(p(1), m)+1) = in(y+1, x+1);
end
end
in = out;
imwrite(uint8(in),'Enc.jpg');
end
end
我收到以下错误:
??? Error using ==> arnold at 9
Only two dimensions allowed
Error in ==> deepoo at 20
encrypted = arnold(cover,num);
有人可以解释 ndims 的目的吗?我有一点困惑。
如果ndims=3
,那么图像是彩色的吗?而如果ndims=2
,这是否意味着图像没有着色?