简体   繁体   中英

Arnold Transform In Matlab : index out of bounds (error)

I am writing matlab code for Arnold Transform. I am using the following lines of code :

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)

However, I am getting the following error on running it :

??? 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);

Can someone please help me to sort it out ?? thanks.

Try changing your size call to account for the three dimensions:

[m n q] = size(cover);

Then see what the values are. You should now have [128 128 3].

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM