为什么实行Jsteg隐写算法后感觉图像没什么变化?

weixin_43613566 2020-05-09 04:01:01
clc
clear all;
close all;

%messagename=input('Enter message file name with extension:','s');
covername='1.jpg';
messagename='message.txt';
stegomessagename='stego.txt';
cover=imread(covername);

sz=size(cover);
rows=sz(1,1);
cols=sz(1,2);
colors=max(max(cover));

fd=fopen(messagename,'r');
message=fgetl(fd);
%message='hello world';
messagelength=length(message);

%figure(1),imshow(cover);title('OriginalImage(CoverImage)');
message=uint8(message);
coverzero = cover;

cover=rgb2gray(cover);

blocksize=8;
quant_multiple=1;
DCT_quantizer=...
[16 11 10 16 24 40 51 61;...
12 12 14 19 26 58 60 55;...
14 13 16 24 40 57 6 956;...
14 17 22 29 51 87 80 62;...
18 22 37 56 68 109 103 77;...
24 35 55 64 81 104 113 92;...
49 64 78 87 103 121 120 101;...
72 92 95 98 112 100 103 99];

figure(2);imshow(coverzero);
title('OriginalImage');

pad_cols=(1-(cols/blocksize-floor(cols/blocksize)))*blocksize;
if pad_cols==blocksize,pad_cols=0;
end
pad_rows=(1-(rows/blocksize-floor(rows/blocksize)))*blocksize;
if pad_rows==blocksize , pad_rows=0;
end

for extra_cols=1:pad_cols
coverzero(1:rows,cols+extra_cols)=coverzero(1:rows,cols);
end
cols=cols+pad_cols;%coverzeroisnowpad_colswider
for extra_rows=1:pad_rows
coverzero(rows+extra_rows,1:cols)=coverzero(rows,1:cols);
end

rows= rows+pad_rows;

for row=1 :blocksize:rows
for col= 1: blocksize :cols
DCT_matrix=coverzero(row:row+blocksize-1,col:col+blocksize-1);
DCT_matrix=dct2(DCT_matrix); %quantizeit(levelsstoredinDCT_quantizermatrix):
%DCT_matrix=floor(DCT_matrix...
% ./(DCT_quantizer(1:blocksize,1:blocksize)*quant_multiple)+0.5);
DCT_matrix_test=(DCT_matrix./(DCT_quantizer(1:blocksize,1:blocksize)* quant_multiple));
DCT_matrix=round(DCT_matrix./(DCT_quantizer(1:blocksize,1:blocksize)* quant_multiple));
%DCT_matrix=round(DCT_matrix);
%placeitintothecompressed-imagematrix:
jpeg_img_test(row:row+blocksize-1,col:col+blocksize-1)=DCT_matrix_test;
jpeg_img(row:row+blocksize-1,col:col+blocksize-1)=DCT_matrix;
end
end

%DCT figures
figure(3);hist(jpeg_img);
figure(4);imshow(jpeg_img);

bitlength=1;
orijpeg=jpeg_img;
for i=1:messagelength
for imbed=1:8
messageshift=bitshift(message(i),8-imbed);
showmess=uint8(messageshift);
showmess=bitshift(showmess,-7);
messagebit(bitlength)=showmess;
bitlength=bitlength+1;
end
end

%embedding JSteg
i=1;
for row=1:rows
for col=1:cols
x=jpeg_img(row,col);
if (x~=0) && (x~=1)
r=mod(x,2);
if r==0
if messagebit(i)==1
x=x+1;
end
else
if messagebit(i)==0
x=x-1;
end
end
i=i+1;
end
jpeg_img(row,col)=x;
if i==bitlength
break;
end
end
if i==bitlength
break;
end
end
%jsteg hist
figure(5);hist(jpeg_img);
orijpeg=orijpeg-jpeg_img;
%Reconstructing Image

recon_img= coverzero-coverzero;

for row=1:blocksize:rows
for col=1:blocksize:cols
IDCT_matrix=jpeg_img(row:row+blocksize-1,col:col+blocksize-1);
IDCT_matrix=round(idct2(IDCT_matrix.*(DCT_quantizer(1:blocksize,1:blocksize)*quant_multiple)));
recon_img(row:row+blocksize-1,col:col+blocksize-1)=IDCT_matrix;
end
end

endrows=rows-pad_rows;
cols=cols-pad_cols;
recon_img=recon_img(1:rows,1:cols);

figure(6);imshow(recon_img);

pad_cols=(1-(cols/blocksize-floor(cols/blocksize)))*blocksize;
if pad_cols==blocksize,pad_cols=0;end
pad_rows=(1-(rows/blocksize-floor(rows/blocksize)))*blocksize;
if pad_rows==blocksize,pad_rows=0;end

for extra_cols=1:pad_cols
recon_img(1:rows,cols+extra_cols)=recon_img(1:rows,cols);
end

cols=cols + pad_cols;

for extra_rows=1:pad_rows
recon_img(rows+extra_rows,1:cols)=recon_img(rows,1:cols);
end

rows=rows+pad_rows;

%coverzeroisnowpad_rowstaller

jpeg_img=jpeg_img-jpeg_img;

for row=1:blocksize:rows
for col=1:blocksize:cols
DCT_matrix=recon_img(row:row+blocksize-1,col:col+blocksize-1);
DCT_matrix=dct2(DCT_matrix); %quantizeit(levelsstoredinDCT_quantizermatrix):%DCT_matrix=floor(DCT_matrix...% ./(DCT_quantizer(1:blocksize,1:blocksize)* quant_multiple)+0.5);
DCT_matrix=round(DCT_matrix./(DCT_quantizer(1:blocksize,1:blocksize)* quant_multiple));
%DCT_matrix=round(DCT_matrix);
%placeitintothecompressed-imagematrix:jpeg_img(row:row+blocksize-1,col:col+blocksize-1)=DCT_matrix;
jpeg_img(row:row+blocksize-1,col:col+blocksize-1)=DCT_matrix;
end
end

stego=jpeg_img;

figure(7);imshow(stego);
figure(8);hist(stego);

stegoindex=1;
imbed=1;
messagechar=0;
messageindex=1;
for row=1:rows
for col=1:cols
stegomessage = stego(row,col);
if (stegomessage~=0) && (stegomessage~=1)
r=mod(stegomessage,2);
if(r==0)
showmess=0;
else
showmess=1;
end

showmess=uint8(showmess);
showmess=bitshift(showmess,(imbed-1));
messagechar=uint8(messagechar+showmess);

stegoindex = stegoindex + 1;

imbed = imbed +1;
if(imbed==9)
messagestring(messageindex)=messagechar;
messageindex=messageindex+1;
messagechar=0;
imbed=1;
end
end
if(stegoindex==messagelength*8+1)
break;
end
end
if(stegoindex==messagelength*8+1)
break;
end
end

disp(messagestring);
messagestringlength=length(messagestring);
stegostring=char(zeros(1,messagestringlength));
for i=1:messagestringlength
stegostring(i)=char(messagestring(i));
end

fd1=fopen(stegomessagename,'w+');
fwrite(fd1,stegostring,'char');
...全文
143 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Erice 2021-05-06
  • 打赏
  • 举报
回复
可能与DCT本身特性有关系。高频分量 记载着图像里的细节部分。低频分量代表亮度,灰度等。人眼对高频敏感。所以这个隐写方法,针对的低频,通过人眼来感官可能短时无法区分。说的不对请见谅

19,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧