image = imread('baboon.bmp');
hide_image = image;
hide_image = double(hide_image);
image_size = size(image);
if numel(image_size)>2
['this is a rgb photo']
else
['this is not a rgb photo']
fclose('all');
end
image_1 = hide_image(:,:,1);
message = fopen('message.txt', 'r');
[msg, msg_len] = fread(message, 'ubit1');
[m, n] = size(image_1);
p = 0;
[row, col] = randinterval(image_1, msg_len, 1996);
for i = 1:msg_len
image_1(row(i), col(i)) = image_1(row(i), col(i)) - mod(image_1(row(i), col(i)), 2) + msg(p, 1);
if p == msg_len
break;
end
end
function [row,col]=randinterval(matrix,count,key)
%计算间隔的位数
[m,n]=size(matrix);
interval1=floor(m*n/count)+1;
interval2= interval1-2;
if interval2==0
error('载体大小不能将秘密信息隐藏进去!');
end
%生成随机序列
rand('seed',key);
a=rand(1,count);
%计算row和col
r=1;
c=1;
row(1,1)=r;
col(1,1)=c;
for i=2:count
if a(i)>=0.5
c=c+interval1;
else
c=c+ interval2;
end
if c>n
r=r+1;
if r>m
error('载体大小不能将秘密信息隐藏进去!');
end
c=mod(c,n);
if c==0
c=1;
end
end
end
row(1,i)=r;
col(1,i)=c;
end
报错信息
位置 1 处的索引无效。数组索引必须为正整数或逻辑值。
出错 work (line 20)
image_1(row(i), col(i)) = image_1(row(i), col(i)) -
mod(image_1(row(i), col(i)), 2) + msg(p, 1);