Matlab中的Arnold变换:索引越界(错误)

时间:2014-07-17 15:57:36

标签: image matlab image-processing

我正在为Arnold Transform编写matlab代码。我使用以下代码行:

clc;
clear all;
close all;

[FileName,PathName] = uigetfile('*.jpg','Select the Cover Image');
file = fullfile(PathName,FileName);
disp(['User selected : ', file]);
cover = imresize(imread(file),[128 128]);
cover = double(cover);
if ndims(cover) ~= 3
    msgbox('The cover image must be colour');
break;
end
figure;
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: ');
[m n] = size(cover);
out = zeros(m);
n = n - 1;
for j=1:num
    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) = cover(y+1, x+1);
           % newcover(row,col)=cover((mod(nrowp,rown)+1),(mod(ncolp,coln)+1));
        end
    end
    cover = out;
end

imshow(newcover)
figure(2)

但是,运行它时出现以下错误:

??? Attempted to access cover(129,1); index out of bounds because
size(cover)=[128,128,3].

Error in ==> main at 28
            out(mod(p(2), m)+1, mod(p(1), m)+1) = cover(y+1, x+1);

有人可以帮我解决一下吗?感谢。

1 个答案:

答案 0 :(得分:1)

尝试将您的size来电更改为三个维度的帐户:

[m n q] = size(cover);

然后看看这些值是什么。你现在应该有[128 128 3]。