How to solve the error in PSNR function?

7 vues (au cours des 30 derniers jours)
Bhavneet Sharma
Bhavneet Sharma le 28 Avr 2019
There is a problem in code of image watermarkin in which DCT technique is applied: it gave error in the PSNR function as:
Error using psnr
Too many input arguments.
Error in dct1_embed (line 112)
psnr=psnr(cover_object,watermarked_image,Nc,Mc);
Code is given below:
file_name='lena.png';
cover_object=double(imread(file_name));
% determine size of cover image
Mc=size(cover_object,1); %Height
Nc=size(cover_object,2); %Width
% determine maximum message size based on cover object, and blocksize
max_message=Mc*Nc/(blocksize^2);
% read in the message image
file_name='copyright2.png';
message=double(imread(file_name));
%Mm=size(message,1); %Height
%Nm=size(message,2); %Width
[rows, columns, numberOfColorChannels] = size(message);
% reshape the message to a vector
message=fix(reshape(message,rows*columns,numberOfColorChannels)/2);
message=message(1:2000);
% check that the message isn't too large for cover
if (length(message) > max_message)
error('Message too large to fit in Cover Object')
end
% pad the message out to the maximum message size with ones
message_pad=ones(1,max_message);
message_pad(1:length(message))=message;
% generate shell of watermarked image
watermarked_image=cover_object;
% process the image in blocks
% encodes such that (5,2) > (4,3) when message(kk)=0
% and that (5,2) < (4,3) when message(kk)=1
x=1;
y=1;
for (kk = 1:length(message_pad))
% transform block using DCT
dct_block=dct2(cover_object(y:y+blocksize-1,x:x+blocksize-1));
% if message bit is black, (5,2) > (4,3)
if (message_pad(kk) == 0)
% if (5,2) < (4,3) then we need to swap them
if (dct_block(5,2) < dct_block(4,3))
temp=dct_block(4,3);
dct_block(4,3)=dct_block(5,2);
dct_block(5,2)=temp;
end
% if message bit is white, (5,2) < (4,3)
elseif (message_pad(kk) == 1)
% if (5,2) > (4,3) then we need to swap them
if (dct_block(5,2) >= dct_block(4,3))
temp=dct_block(4,3);
dct_block(4,3)=dct_block(5,2);
dct_block(5,2)=temp;
end
end
% now we adjust the two values such that their difference >= k
if dct_block(5,2) > dct_block(4,3)
if dct_block(5,2) - dct_block(4,3) < k
dct_block(5,2)=dct_block(5,2)+(k/2);
dct_block(4,3)=dct_block(4,3)-(k/2);
end
else
if dct_block(4,3) - dct_block(5,2) < k
dct_block(4,3)=dct_block(4,3)+(k/2);
dct_block(5,2)=dct_block(5,2)-(k/2);
end
end
% transform block back into spatial domain
watermarked_image(y:y+blocksize-1,x:x+blocksize-1)=idct2(dct_block);
% move on to next block. At and of row move to next row
if (x+blocksize) >= Nc
x=1;
y=y+blocksize;
else
x=x+blocksize;
end
end
% convert to uint8 and write the watermarked image out to a file
watermarked_image_int=uint8(watermarked_image);
imwrite(watermarked_image_int,'dct1_watermarked.bmp','bmp');
% display processing time
elapsed_time=cputime-start_time;
% display psnr of watermarked image
psnr=psnr(cover_object,watermarked_image,Nc,Mc);
what will be the alternative of it means who to solve this problem?
  1 commentaire
marie lasz
marie lasz le 24 Déc 2019
Did you solve it?

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 24 Déc 2019
Just like the error message says, psnr() does not take that many input arguments. You passed in 4 and it can take only up to 3. Why are you passing in the image width and height??? It doesn't want those.
Here is the usage from the help:
Description
peaksnr = psnr(A,ref) calculates the peak signal-to-noise ratio for the image A, with the image ref as the reference.
peaksnr = psnr(A,ref,peakval) uses peakval as the peak signal value for calculating the peak signal-to-noise ratio for image A.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by