Filter löschen
Filter löschen

i am finding an error when i am executing the following code. kindly help me out?

2 Ansichten (letzte 30 Tage)
error in 91 line.
DWT - SVD Watermarking
function [psnr_values, psnr2dB_values] = dwt_svd()
% clear workspace
clear all;
close all;
clc;
%change directory
folder_name = uigetdir(pwd, 'Select Directory Where the .m Files Reside');
if ( folder_name ~= 0 )
if ( strcmp(pwd, folder_name) == 0 )
cd(folder_name);
end
else
return;
end
% read cover image & watermark logo
[cover_fname, cover_pthname] = ...
uigetfile('*.jpg; *.png; *.tif; *.bmp', 'Select the Cover Image');
if (cover_fname ~= 0)
cover_image = strcat(cover_pthname, cover_fname);
cover_image = double( rgb2gray( imread( cover_image ) ) );
cover_image = imresize(cover_image, [512 512], 'bilinear');
else
return;
end
[watermark_fname, watermark_pthname] = ...
uigetfile('*.jpg; *.png; *.tif; *.bmp', 'Select the Watermark Logo');
if (watermark_fname ~= 0)
watermark_logo = strcat(watermark_pthname, watermark_fname);
watermark_logo = double( im2bw( rgb2gray( imread( watermark_logo ) ) ) );
watermark_logo = imresize(watermark_logo, [512 512], 'bilinear');
else
return;
end
% Set constant variables
numOfKeys = 20;
gaussian_plot = true;
print_figures = false;
if (gaussian_plot == false)
secret_key = 3; % random secret key
watermarked_image = watermark_embedding(cover_image, watermark_logo, ...
secret_key, print_figures);
watermark_extraction(watermarked_image, watermark_logo, secret_key, ...
print_figures, true);
else
% Set function parameters to not print any plots and not to do any
% signature authentication
% print_figures = false;
% Pre-allocate matrices
psnr_values = zeros(1, numOfKeys);
psnr2dB_values = zeros(1, numOfKeys);
decoded_correct = zeros(1, numOfKeys);
decoded_wrong = zeros(1, numOfKeys);
% [m, n] = size(watermark_logo);
% correctWatermarkDiff = zeros(1, m*n);
wrongWatermarkDiff = zeros(1, length(watermark_logo));
for key = 1:numOfKeys
% Embedding with the right key
[watermarked_image, original_signature] = ...
watermark_embedding(cover_image, watermark_logo, key, print_figures);
watermarked_images_dir = strcat(pwd, '\watermarked_images\', num2str(key), '.png');
imwrite(uint8(watermarked_image), watermarked_images_dir, 'png');
% Transform the original watermrak (i.e. the original signature) to
% the interval [-1, 1]
original_signature(find(original_signature == 0)) = -1;
% Measure the degree of distortion of the original and the watermarked
% image using PSNR (dB)
psnr_values(key) = psnr(cover_image, watermarked_image);
psnr2dB_values(key) = pow2db(psnr_values(key));
% Detection with the right key, message_correct is actually the
% watermark_logo because in essence that's what I'm hidding in the
% cover image. Whereas the watermark_correct is actually the signature
% which helps in the detection of false acceptance and false
% rejection
[~, ~, recon_sig_corr, LL4, HH4] = ...
watermark_extraction(watermarked_image, watermark_logo, key, ...
print_figures, true);
% transform the watermark_correct(i.e. the reconstructed_signature)
% and the watermark_wrong(i.e. the wrong reconstructed signature)
% to the interval [-1, 1]
recon_sig_corr(find(recon_sig_corr == 0)) = -1;
LL4 = LL4(:)';
HH4 = HH4(:)';
LL4 = LL4 - mean(LL4);
HH4 = HH4 - mean(HH4);
comb_HH4_LL4 = [LL4 HH4];
% decoded_correct(key) = (abs(comb_HH4_LL4) * recon_sig_corr')/512^2;
% decoded_correct(key) = sum(comb_HH4_LL4 .* recon_sig_corr)/512^2;
% Detection with the wrong key
[~, watermark_wrong, recon_sig_wrng, LL4wr, HH4wr] = ...
watermark_extraction(watermarked_image, watermark_logo, key+11, ...
print_figures, false);
watermark_wrong(find(watermark_wrong == 0)) = -1;
LL4wr = LL4wr(:)';
HH4wr = HH4wr(:)';
LL4wr = LL4wr - mean(LL4wr);
HH4wr = HH4wr - mean(HH4wr);
combwr_HH4_LL4 = [LL4wr HH4wr];
% decoded_wrong(key) = (abs(combwr_HH4_LL4) * watermark_wrong')/512^2;
% decoded_wrong(key) = sum(watermark_wrong .* original_signature)/512;
% Keep track of the correlation between the watermark_correct and
% the watermark_wrong
correlation_correct = corrcoef(comb_HH4_LL4, recon_sig_corr);
decoded_correct(key) = correlation_correct(2, 1);
correlation_wrong = corrcoef(combwr_HH4_LL4, watermark_wrong);
decoded_wrong(key) = correlation_wrong(2, 1);
% Calculate the difference between the correct extracted watermarks and
% the original watermark and the wrong extracted watermarks and the orignal
% correctKeyWatermarkDiff(key, :) = watermark_wrong - original_signature;
wrongWatermarkDiff(key, :) = watermark_wrong - original_signature;
clear('watermark_correct', 'comb_HH4_LL4', 'watermark_wrong', ...
'combwr_HH4_LL4', 'original_signature', ...
'LL4', 'HH4', 'LL4wr', 'HH4wr');
% Clear workspace
clear('watermark_logo_row', 'watermark_logo_extracted_correct', ...
'watermark_logo_extracted_wrong', 'watermarked_image', ...
'watermark_correct', 'watermark_wrong', 'message_correct', ...
'message_wrong', 'watermarked_image');
end
meanOfDecodCorr = mean(decoded_correct);
stdOfDecodCorr = std(decoded_correct);
meanOfDecodWrng = mean(decoded_wrong);
stdOfDecodWrng = std(decoded_wrong);
gaussians(meanOfDecodCorr, stdOfDecodCorr, meanOfDecodWrng, stdOfDecodWrng);
[Pfa, Pfr] = PfaPfr(meanOfDecodCorr, stdOfDecodCorr, meanOfDecodWrng, stdOfDecodWrng, numOfKeys);
% Measure bit error rate, and plot against threshold T of pfa,
% where T = pfa/pfr. Or equivalently plot BER & E versus pfa
BER = BitErrorRate(wrongWatermarkDiff);
end
end
  2 Kommentare
chaitanya g p
chaitanya g p am 22 Apr. 2016
??? Error: File: dwt_svd.m Line: 91 Column: 11 Expression or statement is incorrect--possibly unbalanced (, {, or [.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 22 Apr. 2016
Bearbeitet: Jan am 22 Apr. 2016
Please read the message. It tells you the exact line (while we can only guess which is the line 91) and even the character, which is the problem: There is a parenthesis, brace or bracket, which is closed before another one was opened. I assume, this problem should be easy to fix.
Perhaps this is the offending line:
[~, ~, recon_sig_corr, LL4, HH4] = ...
If you use an older Matlab version <=R2009a, the "~" are not allowed. Replace this by:
[dummy, dummy, recon_sig_corr, LL4, HH4] = ...
If this is the problem, if appears in the line "[~, watermark_wrong, recon_sig_wrng, LL4wr, HH4wr] = ..." also.
PS. A clear all on the top of a function is a waste of time, energy and power. There is simply no reason for a brutal clearing of an empty workspace.
  4 Kommentare
chaitanya g p
chaitanya g p am 22 Apr. 2016
??? Undefined function or method 'decimalToBinaryVector' for input arguments of type 'double'.
Error in ==> signature_embedding at 51 binary_coefficients{p} = decimalToBinaryVector(integer_part(p), 16);
if true
%%Signature embedding algorithm
function LL_inv = signature_embedding(LL, signature, print_figures)
% 1. Using Haar wavelet, further decompose LL band to the 4th level.
[LL_1, HL_1, LH_1, HH_1] = dwt2(LL, 'haar'); % 1st step DWT
[LL_2, HL_2, LH_2, HH_2] = dwt2(LL_1, 'haar'); % 2nd step DWT
[LL_3, HL_3, LH_3, HH_3] = dwt2(LL_2, 'haar'); % 3rd step DWT
[LL_4, HL_4, LH_4, HH_4] = dwt2(LL_3, 'haar'); % 4rth step DWT
if (print_figures == true)
% Images coding.
cod_cA = wcodemat(LL_4);
cod_cH = wcodemat(HL_4);
cod_cV = wcodemat(LH_4);
cod_cD = wcodemat(HH_4);
dec2dim = [cod_cA, cod_cH; cod_cV, cod_cD];
% Plot 4-th step decomposition
figure;
image(dec2dim);
title('4-th step DWT decomposition');
clear('dec2dim', 'cod_cA', 'cod_cH', 'cod_cV', 'cod_cD');
end
% 1. choose all in total 512 coefficients from LL_4 & HH_4
% reshape them to row vectors of size 1x256
LL_4 = reshape(LL_4, 1, length(LL_4)^2);
HH_4 = reshape(HH_4, 1, length(HH_4)^2);
% concatenate the above row vectors into a larger row vector of size 1x512
combined_LL4_and_HH4_coef = [LL_4 HH_4];
% keep record of the index position of negatives to put back the sign in
% inverse process
negative_idxs = combined_LL4_and_HH4_coef(logical(combined_LL4_and_HH4_coef)) < 0;
% keep only the positive integer parts
% combined_LL4_and_HH4_coeff_posint = round( abs( combined_LL4_and_HH4_coef ) );
% separate the integer from the decimal fraction
combined_LL4_and_HH4_coeff_pos = abs(combined_LL4_and_HH4_coef);
integer_part = fix(combined_LL4_and_HH4_coeff_pos);
fraction_part = abs(combined_LL4_and_HH4_coeff_pos - integer_part);
% Convert the integer part into the binary code of L=16 bits.
binary_coefficients = {};
for p = 1:length(integer_part)
% binary_coefficients{p} = bitget( uint16( integer_part(p) ), 16:-1:1 );
binary_coefficients{p} = decimalToBinaryVector(integer_part(p), 16);
end
% 2. Replace the n-th bit (10th bit) position of the coefficient with
% signature bit
for m = 1:length(signature)
for n = 1:16
if (n == 10)
binary_coefficients{1, m}(n) = signature(m);
end
end
end
% and then convert the binary code to its decimal representation
bin2decimal = zeros(1, length(binary_coefficients));
for x = 1:length(binary_coefficients)
bin2decimal(x) = binaryVectorToDecimal(double(binary_coefficients{1, x}));
end
% reconstruct orignal array from integer and decimal fraction parts
% cmb_coef = integer_part + fraction_part;
bin2decimal = bin2decimal + fraction_part;
% put back the negative signs
bin2decimal(find(negative_idxs == 1)) = - bin2decimal(find(negative_idxs == 1));
% Clear workspace
clear('LL_1', 'LL_2', 'LL_3', 'LL_4', 'HH_4', 'combined_LL4_and_HH4_coef',...
'negative_idxs', 'combined_LL4_and_HH4_coeff_pos', 'integer_part',...
'fraction_part', 'binary_coefficients', 'signature');
% reshape the modified LL_4 & HH_4 sub-bands to their original size 16x16
% each
LL_4_modified = bin2decimal(1:256);
HH_4_modified = bin2decimal(257:end);
LL_4_modified = reshape(LL_4_modified, 16, 16);
HH_4_modified = reshape(HH_4_modified, 16, 16);
% Clear workspace
clear('bin2decimal');
% 3. Apply the inverse DWT with modified LL4 and HH4 band coefficients.
LL_3_inv = idwt2(LL_4_modified, HL_4, LH_4, HH_4_modified, 'haar');
LL_2_inv = idwt2(LL_3_inv, HL_3, LH_3, HH_3, 'haar');
LL_1_inv = idwt2(LL_2_inv, HL_2, LH_2, HH_2, 'haar');
LL_inv = idwt2(LL_1_inv, HL_1, LH_1, HH_1, 'haar');
% Clear workspace
clear('LL_1_inv', 'LL_2_inv', 'LL_3_inv', 'LL_4_modified', ...
'HL_1', 'HL_2', 'HL_3', 'HL_4', ...
'LH_1', 'LH_2', 'LH_3', 'LH_4', ...
'HH_1', 'HH_2', 'HH_3', 'HH_4_modified');
end
end
binary_coefficients{p} = decimalToBinaryVector(integer_part(p), 16); error here
Jan
Jan am 22 Apr. 2016
Bearbeitet: Jan am 22 Apr. 2016
The error "??? Undefined function or method 'decimalToBinaryVector'" means, that you do not have this function in your Matlab path. When such a message appears, asking an internet search engine is a good idea. This reveals, that this function belongs to the Data Acquisition Toolbox: http://www.mathworks.com/help/daq/ref/decimaltobinaryvector.html . Do you have this toolbox? You can write this function by your own easily. Look at dec2bin and omit the final conversion to a char.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Discrete Multiresolution Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by