运行后显示索引超出边界要怎么解决呀,有人教教我吗
clc;
clear;
% 读取原始图像
I = imread('lena.bmp');
I = rgb2gray(I);
% 将图像进行小波变换
[cA, cH, cV, cD] = dwt2(I, 'haar');
% 将小波系数进行FFT变换
fft_cA = fft2(cA);
fft_cH = fft2(cH);
fft_cV = fft2(cV);
fft_cD = fft2(cD);
% 生成随机的数字水印
watermark = randi([0 1], 1, 64);
% 将数字水印嵌入到小波系数中
alpha = 0.1;
for i = 1:8
for j = 1:8
block = fft_cA((i-1)*64+1:i*64, (j-1)*64+1:j*64);
block(33:64) = block(33:64) + alpha * watermark((i-1)*8+j);
fft_cA((i-1)*64+1:i*64, (j-1)*64+1:j*64) = block;
end
end
% 将嵌入了数字水印的小波系数进行逆FFT变换
idwt_cA = ifft2(fft_cA);
idwt_cH = ifft2(fft_cH);
idwt_cV = ifft2(fft_cV);
idwt_cD = ifft2(fft_cD);
% 将逆变换后的小波系数合并成一张图像
I_watermark = idwt2(idwt_cA, idwt_cH, idwt_cV, idwt_cD, 'haar');
% 显示原始图像和带有数字水印的图像
figure;
subplot(1, 2, 1);imshow(I);
title('Original Image');
subplot(1, 2, 2);
imshow(I_watermark);
title('Watermarked Image');
% 从带有数字水印的图像中提取出数字水印
extracted_watermark = zeros(1, 64);
for i = 1:8
for j = 1:8
block = fft_cA((i-1)*64+1:i*64, (j-1)*64+1:j*64);
extracted_watermark((i-1)*8+j) = abs(corr2(block(33:64), watermark((i-1)*8+j)));
end
end
% 显示提取出的数字水印
figure;
subplot(1, 2, 1);
imshow(I_watermark);
title('Watermarked Image');
subplot(1, 2, 2);
bar(extracted_watermark);
title('Extracted Watermark');