我使用八度音来解密图像。我必须恢复隐藏在Carrier图像中的图像。我的代码只有在目标图像为黑白时才有效,我如何调整它以使它也能用于彩色。
I2 = imread('c:/df/output/stegoFlowers.png');
output_stream="";
data_size_s=""; %In bytes and as a string
k=1;
for i=1:rows(I2)
for j=1:columns(I2)
if (k<18) s=dec2bin(double(I2(i,j,1)),8); data_size_s=strcat(data_size_s,s(8)); k++; endif
if (k<18) s=dec2bin(double(I2(i,j,2)),8); data_size_s=strcat(data_size_s,s(8)); k++; endif
if (k<18) s=dec2bin(double(I2(i,j,3)),8); data_size_s=strcat(data_size_s,s(8)); k++; endif
end
end
%We pass the size of the target image from string to integer
target_rows=uint32(bin2dec(substr(data_size_s, 1,8)));
target_columns=uint32(bin2dec(substr(data_size_s,9,8)));
data_size_int=target_rows*target_columns; % Data Size in bytes as integer
%We read the output_stream from the stego image
total_data_size=(8*data_size_int)+16; % Total length of the output stream (header +target data)
k=1;
for i=1:rows(I2)
for j=1:columns(I2)
if (k<=(total_data_size)) s=dec2bin(double(I2(i,j,1)),8); output_stream=strcat(output_stream,s(8)); k++; endif
if (k<=(total_data_size)) s=dec2bin(double(I2(i,j,2)),8); output_stream=strcat(output_stream,s(8)); k++; endif
if (k<=(total_data_size)) s=dec2bin(double(I2(i,j,3)),8); output_stream=strcat(output_stream,s(8)); k++; endif
end
end
I3_rows=uint32(bin2dec(substr(output_stream,1,8)));
I3_columns=uint32(bin2dec(substr(output_stream,9,8)));
k=17;
I3=uint8(zeros(I3_rows,I3_columns,3));
total_data_size=(8*data_size_int)+16;
for i=1:I3_rows
for j=1:I3_columns
if (k<=total_data_size) I3(i,j,1)=uint8(bin2dec(substr(output_stream,k,8))); k=k+8; endif
if (k<=total_data_size) I3(i,j,2)=uint8(bin2dec(substr(output_stream,k,8))); k=k+8; endif
if (k<=total_data_size) I3(i,j,3)=uint8(bin2dec(substr(output_stream,k,8))); k=k+8; endif
end
end
%We show the hidden image.
imshow(I3);