PSNR of image in matlab
<p>I am confused with the Peak signal-to-noise ratio (PSNR) between original image and encrypted image. As i know, the higher PSNR value means the better image quality. I tried to test and calculate the PSNR value. I used LSB technique on the text steganography.</p>

<ol>
<li>I tried embed 100 character into an image. It results with 69.9696 dB.</li>
<li>I tried embed   5 character into an image. It results with 68 dB.</li>
</ol>

<p>Now, what I think in my mind is: </p>

<ul>
<li><p>Should more character embed into image, produce less PSNR value, or less character embed into image, produce high PSNR value?</p></li>
<li><p>More character embed, means more manipulation on the pixel. So, PSNR value become lesser?</p></li>
</ul>

<p>Anyone can tell me or correct me with my mistake?</p>

<p>------Attached Coding------</p>

<pre><code>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));
</code></pre>

<p>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.</p>

<p>That's why I get confused.</p>

<p>---HERE is my PSNR code---</p>

<pre><code>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&lt;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);
</code></pre>

<p>I just call the function of PSNR and print the PSNR value of original image and stego image.</p>

<p><a href="https://i.stack.imgur.com/VEGRL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VEGRL.png" alt="lena original bmp"></a></p>

<p>The many character I embed, I get  51.1687256 dB.
The one character I embed, I get 51.1578686 dB.</p>

<p>Can tell me why?</p>