Index exceeds array bound help
古いコメントを表示
Hi everyone. I'm implementing image encoding with chaotic mapping with three keys for: bit permutation, row permutation, pixel permutation. I made a mistake: Index exceeds array bound. Please help me. Also, outside is the lock, I want to run the loop inside the command a number of times, how do I do? Thanks so much. This is my code:
clc;
clear variables;
c=imread('E:\_temp_matlab_R2018a_win64\bin\code_chaotic\kaola280.png');
[heigth,width,~]=size(c);
%HOAN VI BIT
%tao chuoi chaotic, sap xep de hoan vi diem anh theo thu tu sap xep cua
%chao
%tao khoa hoan vi tu ham chaotic
y=zeros(1,8);
% nhap cac gia tri khoi tao cho chaotic map
y(1)=0.6;
beta=3.7;
for i=2:8
y(i)=beta*y(i-1)*(1-y(i-1));
end
fprintf('\n chao:\n');
disp(y);
%sap xep chao
chaoswapp=y;
for i=1:7-1
for j=i+1:8
if chaoswapp(i)>chaoswapp(j)
temp=chaoswapp(i);
chaoswapp(i)=chaoswapp(j);
chaoswapp(j)=temp;
end
end
end
% % fprintf('\n chao:\n');
% % disp(y);
fprintf('\n chao sap xep:\n');
disp(chaoswapp);
% disp(chaoswapp);
%tao khoa hoan vi bit
key=zeros(1,8);
k=1;
t=1;
while k<=width
i=1;
while y(i)~=chaoswapp(k)
i=i+1;
end
key(t)=i;
t=t+1;
k=k+1;
end
fprintf('\n khoa hoan vi chao:\n');
disp(key);
% key=[3 5 1 7 2 8 4 6];%randperm(8);
n=24*width*heigth;
binary=zeros(1,n);
%chuyen anh ban dau sang dang nhi phan
k=1;
for i=1:heigth
for j=1:width
tmpr=dec2bin(c(i,j,1),8);
tmp=zeros(1,8);
for t=1:8
if tmpr(t)=='1'
tmp(t)=1;
end
end
for p=1:8
binary(k)=tmp(key(p));
k=k+1;
end
tmpg=dec2bin(c(i,j,2),8);
tmp=zeros(1,8);
for t=1:8
if tmpg(t)=='1'
tmp(t)=1;
end
end for p=1:8
binary(k)=tmp(key(p));
k=k+1;
end
tmpb=dec2bin(c(i,j,3),8);
tmp=zeros(1,8);
for t=1:8
if tmpb(t)=='1'
tmp(t)=1;
end
end for p=1:8
binary(k)=tmp(key(p));
k=k+1;
end
end
end%chuyen chuoi nhi phan da hoan vi ve thap phan
column=length(binary)/8;
binmatrix=zeros(8,column);
k=1;
for i=1:column
for j=1:8
binmatrix(j,i)=binary(k);
k=k+1;
end
end
%chuyen ma tran nhi phan thanh dang thap phan
binvalue=[128 64 32 16 8 4 2 1];
pixel=binvalue*binmatrix;%vector hang cac diem anh//////////////
%xay dung lai anh sau khi xao tron bang cach hoan vi
anhhoanvi=c;%zeros(heigth,width);
k=1;
for i=1:heigth
for j=1:width
anhhoanvi(i,j,1)=pixel(k);
k=k+1;
anhhoanvi(i,j,2)=pixel(k);
k=k+1;
anhhoanvi(i,j,3)=pixel(k);
k=k+1;
end
end
imwrite(anhhoanvi,'E:\_temp_matlab_R2018a_win64\bin\code_chaotic\hoanvibitkaola280.png');
%xong hoan vi bit
%HOAN VI CAC DIEM ANH THEO TUNG HANG
%tao chuoi chaotic, sap xep de hoan vi diem anh theo thu tu sap xep cua
%chao
%tao khoa hoan vi tu ham chaotic
x=zeros(1,width);
% nhap cac gia tri khoi tao cho chaotic map
x(1)=0.4;
lamda=3.7;
for i=2:width
x(i)=lamda*x(i-1)*(1-x(i-1));
end
fprintf('\n chao:\n');
disp(x);
%sap xep chao
chaoswap=x;
for i=1:width-1
for j=i+1:width
if chaoswap(i)>chaoswap(j)
temp=chaoswap(i);
chaoswap(i)=chaoswap(j);
chaoswap(j)=temp;
end
end
end
% % fprintf('\n chao:\n');
% % disp(x);
fprintf('\n chao sap xep:\n');
disp(chaoswap);
% disp(chaoswap);
%tao khoa hoan vi hang
key1=zeros(1,width);
k=1;
t=1;
while k<=width
i=1;
while x(i)~=chaoswap(k)
i=i+1;
end
key1(t)=i;
t=t+1;
k=k+1;
end
fprintf('\n khoa hoan vi chao:\n');
disp(key1);
%tao khoa nguoc hoan vi hang
key2=zeros(1,width);
for i=1:width
key2(key1(i))=i;
end
fprintf('\n khoa hoan vi nguoc cua chao:\n');
disp(key2);
% hoan vi cacs diem anh////////////////////
hoanvihang=anhhoanvi;
for i=1:heigth
for j=1:width
hoanvihang(i,j,1)=anhhoanvi(i,key1(j),1);
hoanvihang(i,j,2)=anhhoanvi(i,key1(j),2);
hoanvihang(i,j,3)=anhhoanvi(i,key1(j),3);
end
end
%imshow(hoanvihang);
imwrite(hoanvihang,'E:\_temp_matlab_R2018a_win64\bin\code_chaotic\hoanvihangkaola280.png');
%KET THUC HOAN VI HANG
%HOAN VI KHOI
b=cell(1,8);
k=1;
blockwidth=width/4;
blockheigth=heigth/2;
gridwidth=width/blockwidth;
gridheigth=heigth/blockheigth;
for i=1:gridheigth
for j=1:gridwidth
%toa do cua diem anh dau tien cua khoi con
cx=(i-1)*blockheigth+1;
cy=(j-1)*blockwidth+1;
%lay vi tri cua cac diem anh trong khoi
posx=cx:cx+blockheigth-1;
posy=cy:cy+blockwidth-1;
%tao khoi con
b{k}=hoanvihang(posx,posy); %de truy cap den tung phan tu cua cell, dung {}
k=k+1;
end
end
hoanvikhoi=b;
for i=1:8
hoanvikhoi{i}=b{key(i)};
end
%ghep khoi de chuyen ve anh
anhhoanvikhoi=hoanvihang;
k=1;
for i=1:gridheigth
for j=1:gridwidth
%toa do cua diem anh dau tien cua khoi con
cx=(i-1)*blockheigth+1;
cy=(j-1)*blockwidth+1;
%lay vi tri cua cac diem anh trong khoi
posx=cx:cx+blockheigth-1;
posy=cy:cy+blockwidth-1;
%tao khoi con
anhhoanvikhoi(posx,posy)=hoanvikhoi{k};
k=k+1;
end
end
imwrite(anhhoanvikhoi,'E:\_temp_matlab_R2018a_win64\bin\code_chaotic\hoanvikhoikaola280.png');
subplot(6,1,1); imhist(c(:,:,1)); subplot(6,1,3); imhist(c(:,:,2)); subplot(6,1,5); imhist(c(:,:,3));
% subplot(3,1,1); % imhist(anhhoanvi(:,:,1)); % subplot(3,1,2); % imhist(anhhoanvi(:,:,2)); % subplot(3,1,3); % imhist(anhhoanvi(:,:,3));
% subplot(3,2,1); % imhist(hoanvihang(:,:,1)); % subplot(3,2,2); % imhist(hoanvihang(:,:,2)); % subplot(3,2,3); % imhist(hoanvihang(:,:,3));
subplot(6,1,2);
imhist(anhhoanvikhoi(:,:,1));
subplot(6,1,4);
imhist(anhhoanvikhoi(:,:,2));
subplot(6,1,6);
imhist(anhhoanvikhoi(:,:,3));1 件のコメント
[MOVED from flags] Huong Hoang wrote: Hi Administrator. Please consider my question. Thank you.
@Huong Hoang: Please use flags only to inform admins and editors about inappropriate content like spam or rudeness. Trying to push the readers to prefer you question to others is not useful.
Please post the complete error message, such that it is clear, which line causes the error.
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Audio and Video Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!