function [ ste_cover,len_total] = lsbhide(input,file,output)
%读入图像矩阵
cover=imread(input);
ste_cover=cover;
ste_cover=double(ste_cover);
%将文本文件转换为二进制序列
f_id=fopen(file,'r');
[msg,len_total]=fread(f_id);
%判断嵌入信息是否过大
[m,n]=size(ste_cover);
if len_total>m*n
error('嵌入 信息量过大,请更换图像');
end
%p作为消息嵌入位数计数器
p=1;
for f2=1:n
for f1=1:m
ste_cover(f1,f2)=ste_cover(f1,f2)-mod(ste_cover(f1,f2),2)+msg(p,1);
if p==len_total
break;
end
p=p+1;
end
if p==len_total
break;
end
end
ste_cover=uint8(ste_cover);
imwrite(ste_cover,output);
%显示实验结果
subplot(1,2,1);imshow(cover);title('原始图像');
subplot(1,2,2);imshow(output);title('隐藏信息的图像');
LSB信息隐藏算法
最新推荐文章于 2022-11-04 15:58:24 发布