0

我对原始图像和加密图像之间的峰值信噪比 (PSNR) 感到困惑。据我所知,PSNR 值越高意味着图像质量越好。我试图测试和计算 PSNR 值。我在文本隐写术上使用了 LSB 技术。

  1. 我尝试将 100 个字符嵌入到图像中。结果为 69.9696 dB。
  2. 我尝试将 5 个字符嵌入到图像中。结果为 68 dB。

现在,我的想法是:

  • 应该更多的字符嵌入到图像中,产生更少的 PSNR 值,还是更少的字符嵌入到图像中,产生高的 PSNR 值?

  • 更多的字符嵌入,意味着对像素的更多操作。那么,PSNR 值会变小吗?

任何人都可以告诉我或纠正我的错误吗?

------附加编码------

Str = 'after this, I tried calculate the PSNR value with original image and stego image. 100 character which is read from file is embedded into image, higher PSNR value. 5 character, less PSNR value.';%many character
%Str = 'a';   %one character 

Str=uint8(Str);    %converting to 8 bit numbers for proper calculation
fprintf('%d ', Str);
fprintf('\n');
stringLength = length(Str);


x=imread('lena.bmp');   %reading the image file
x=uint8(x);                %conversion to 8 bit
[x_row,x_col]=size(x);


numPixelsInImage = numel(x);
bitsPerLetter = 7;  % For ASCII, this is 7.
numPixelsNeededForString = stringLength * bitsPerLetter;

binaryAsciiString = dec2bin(Str)'
whos binaryAsciiString
binaryAsciiString = binaryAsciiString(:)'

 stegoImage = x;
 stegoImage(1:numPixelsInImage) = bitset(stegoImage(1:numPixelsInImage), 1, 0);
 oneIndexes = find(binaryAsciiString == '1'); 
 stegoImage(oneIndexes) = bitset(stegoImage(oneIndexes), 1, 1);



 imwrite(uint8(stegoImage),'stego123.bmp') 

fprintf('\nPSNR: %9.7f dB\n\n', psnr(x,stegoImage));

在此之后,我尝试用原始图像和隐秘图像计算 PSNR 值。从文件中读取的 100 个字符嵌入到图像中,PSNR 值更高。5 个字符,少 PSNR 值。

这就是为什么我感到困惑。

---这是我的 PSNR 代码---

function [PSNR,mse]=psnr(X,Y)
% function [PSNR,mse]=psnr(X,Y)
% Peak signal to noise ratio of the difference between images and the
%mean square error
% If the second input Y is missing then the PSNR and MSE of X itself
% becomes the output (as if Y=0).
if nargin<2, D=X;
else
if any(size(X)~=size(Y)), error('The input size is not equal to each other!'); end
D=X-Y;
end
mse=sum(D(:).*D(:))/prod(size(X));
PSNR=10*log10(255^2/mse);

我只是调用 PSNR 的函数并打印原始图像和隐写图像的 PSNR 值。

莉娜原始bmp

我嵌入的许多字符,我得到 51.1687256 dB。我嵌入的一个字符,我得到 51.1578686 dB。

能告诉我为什么吗?

4

1 回答 1

0

pnsr你的函数有错误。两个输入都是uint8,这限制了 0-255 范围内的所有值。这可能是一个问题D=X-Y

>> uint8(0) - uint8(1)
0
>> double(0) - double(1)
-1

更改为D = double(X) - double(Y)将为您提供长字符串和 1 字母字符串的正确值,分别为 51.1576 dB 和 51.1578 dB。

但是,您的算法不是最理想的。在嵌入位之前,您将每个像素的 LSB 设置为 0。您可以有效地修改多达 262144 像素,而您的消息要短得多。这大大降低了 PSNR,并解释了为什么 7 位和 1536 位长的消息的值如此相似。相反,您应该只修改嵌入消息所需的最小像素数,方法是使用numPixelsNeededForString. 或者更紧凑,

cover = imread('lena512.png');
Str = 'after this, I tried calculate the PSNR value with original image and stego image. 100 character which is read from file is embedded into image, higher PSNR value. 5 character, less PSNR value.';
%Str = Str(1:1);

bits = dec2bin(Str, 7)';
bits = bits(:);

stego = cover;
stego(1:numel(bits)) = bitset(stego(1:numel(bits)), 1, str2num(bits)');

psnr(cover, stego)

这样做将为您提供 73.9530 dB 的长字符串和 95.3265 dB 的 1 字母字符串的 PSNR。

于 2016-11-03T11:58:35.577 回答