Clear Filters
Clear Filters

What is the error in this code for HSV image watermarking?

1 view (last 30 days)
Dear Sir, The code for watermarking of a color image with four different color images is given below, using HSV color space. Kindly guide me the mistake i am making in this code. since the result is a black image with no features and a very low psnr.
% peppers image
org_img1= imread('lena.jpg');
org_img= rgb2hsv(org_img1);
figure;
imshow(org_img);
title('Original image');
% division imto blocks
img4x4 = mat2cell( org_img, size(org_img,1)/2 * ones(1,2), size(org_img,2)/2 * ones(1,2), size(org_img,3) );
%upper left
[h1_LL,h1_LH,h1_HL,h1_HH]=dwt2(img4x4{1,1},'haar');
img_1=h1_LL;
red_1=img_1(:,:,1);
green_1=img_1(:,:,2);
blue_1=img_1(:,:,3);
[U_img1r1,S_img1r1,V_img1r1]= svd(red_1);
[U_img1g1,S_img1g1,V_img1g1]= svd(green_1);
[U_img1b1,S_img1b1,V_img1b1]= svd(blue_1);
%watermark imagee
w1=imread('fruits.jpg');
wtr_img_1=imresize(w1, 1/2);
wtr_img1=rgb2hsv(wtr_img_1);
figure;
[w1_LL,w1_LH,w1_HL,w1_HH]=dwt2(wtr_img1,'haar');
img_wat1=w1_LL;
red1=img_wat1(:,:,1);
green1=img_wat1(:,:,2);
blue1=img_wat1(:,:,3);
[U_img1r2,S_img1r2,V_img1r2]= svd(red1);
[U_img1g2,S_img1g2,V_img1g2]= svd(green1);
[U_img1b2,S_img1b2,V_img1b2]= svd(blue1);
% watermarking by SVD
S_wimg1b=S_img1b1+(0.05*S_img1b2);
wimg1r = U_img1r1*S_img1r1*V_img1r1';
wimg1g = U_img1g1*S_img1g1*V_img1g1';
wimg1b = U_img1b1*S_wimg1b*V_img1b1';
wimg1=cat(3,wimg1r,wimg1g,wimg1b);
newimage1_LL=wimg1;
%output
rgb1=idwt2(newimage1_LL,h1_LH,h1_HL,h1_HH,'haar');
imwrite(uint8(rgb1),'Watermarked1.jpg');
img4x4{1,1} =rgb1;
% 2nd image
%upper right
[h2_LL,h2_LH,h2_HL,h2_HH]=dwt2(img4x4{1,2},'haar');
img_2=h2_LL;
red_2=img_2(:,:,1);
green_2=img_2(:,:,2);
blue_2=img_2(:,:,3);
[U_img2r1,S_img2r1,V_img2r1]= svd(red_2);
[U_img2g1,S_img2g1,V_img2g1]= svd(green_2);
[U_img2b1,S_img2b1,V_img2b1]= svd(blue_2);
%watermark image 2
w2=imread('Baboon.jpe');
wtr_img_2=imresize(w2, 1/2);
wtr_img2=rgb2hsv(wtr_img_2);
figure;
[w2_LL,w2_LH,w2_HL,w2_HH]=dwt2(wtr_img2,'haar');
img_wat2=w2_LL;
red2=img_wat2(:,:,1);
green2=img_wat2(:,:,2);
blue2=img_wat2(:,:,3);
[U_img2r2,S_img2r2,V_img2r2]= svd(red2);
[U_img2g2,S_img2g2,V_img2g2]= svd(green2);
[U_img2b2,S_img2b2,V_img2b2]= svd(blue2);
% PSNR calculation
% watermarking by SVD
S_wimg2b=S_img2b1+(0.05*S_img2b2);
wimg2r = U_img2r1*S_img2r1*V_img2r1';
wimg2g = U_img2g1*S_img2g1*V_img2g1';
wimg2b = U_img2b1*S_wimg2b*V_img2b1';
wimg2=cat(3,wimg2r,wimg2g,wimg2b);
newimage2_LL=wimg2;
%output
rgb2=idwt2(newimage2_LL,h2_LH,h2_HL,h2_HH,'haar');
imwrite(uint8(rgb2),'Watermarked2.jpg');
img4x4{1,2} = rgb2;
%3rd image
%lower left
[h3_LL,h3_LH,h3_HL,h3_HH]=dwt2(img4x4{2,1},'haar');
img_3=h3_LL;
red_3=img_3(:,:,1);
green_3=img_3(:,:,2);
blue_3=img_3(:,:,3);
[U_img3r1,S_img3r1,V_img3r1]= svd(red_3);
[U_img3g1,S_img3g1,V_img3g1]= svd(green_3);
[U_img3b1,S_img3b1,V_img3b1]= svd(blue_3);
%watermark image 3
w3=imread('peppers.jpg');
wtr_img_3=imresize(w3, 1/2);
wtr_img3=rgb2hsv(wtr_img_3);
figure;
[w3_LL,w3_LH,w3_HL,w3_HH]=dwt2(wtr_img3,'haar');
img_wat3=w3_LL;
red3=img_wat3(:,:,1);
green3=img_wat3(:,:,2);
blue3=img_wat3(:,:,3);
[U_img3r2,S_img3r2,V_img3r2]= svd(red3);
[U_img3g2,S_img3g2,V_img3g2]= svd(green3);
[U_img3b2,S_img3b2,V_img3b2]= svd(blue3);
% watermarking by SVD
S_wimg3b=S_img3b1+(0.05*S_img3b2);
wimg3r = U_img3r1*S_img3r1*V_img3r1';
wimg3g = U_img3g1*S_img3g1*V_img3g1';
wimg3b = U_img3b1*S_wimg3b*V_img3b1';
wimg3=cat(3,wimg3r,wimg3g,wimg3b);
newimage3_LL=wimg3;
%output
rgb3=idwt2(newimage3_LL,h3_LH,h3_HL,h3_HH,'haar');
imwrite(uint8(rgb3),'Watermarked3.jpg');
img4x4{2,1} = rgb3;
%4rth image
%lower right
[h4_LL,h4_LH,h4_HL,h4_HH]=dwt2(img4x4{2,2},'haar');
img_4=h4_LL;
red_4=img_4(:,:,1);
green_4=img_4(:,:,2);
blue_4=img_4(:,:,3);
[U_img4r1,S_img4r1,V_img4r1]= svd(red_4);
[U_img4g1,S_img4g1,V_img4g1]= svd(green_4);
[U_img4b1,S_img4b1,V_img4b1]= svd(blue_4);
%watermark image 4
w4=imread('F16.jpe');
wtr_img_4=imresize(w4, 1/2);
wtr_img4=rgb2hsv(wtr_img_4);
figure;
[w4_LL,w4_LH,w4_HL,w4_HH]=dwt2(wtr_img4,'haar');
img_wat4=w4_LL;
red4=img_wat4(:,:,1);
green4=img_wat4(:,:,2);
blue4=img_wat4(:,:,3);
[U_img4r2,S_img4r2,V_img4r2]= svd(red4);
[U_img4g2,S_img4g2,V_img4g2]= svd(green4);
[U_img4b2,S_img4b2,V_img4b2]= svd(blue4);
% watermarking by SVD
S_wimg4b=S_img4b1+(0.05*S_img4b2);
wimg4r = U_img4r1*S_img4r1*V_img4r1';
wimg4g = U_img4g1*S_img4g1*V_img4g1';
wimg4b = U_img4b1*S_wimg4b*V_img4b1';
wimg4=cat(3,wimg4r,wimg4g,wimg4b);
newimage4_LL=wimg4;
%output
rgb4=idwt2(newimage4_LL,h4_LH,h4_HL,h4_HH,'haar');
imwrite(uint8(rgb4),'Watermarked4.jpg');
img4x4{2,2} = rgb4;
%reconstruction of watermarked image
recomb_img= cell2mat(img4x4);
imwrite(uint8(recomb_img),'Recombined.jpg');
%PSNR of whole image
% PSNR calculation
image1= imread('lena.jpg');
image_2= imread('Recombined.jpg');
figure(1);
imshow(image1); title('Original image');
figure(2);
imshow(image_2); title('Watermarked image');
image2=rgb2hsv(image_2);
h_img= image2(:,:,1);
s_img= image2(:,:,2);
v_img= image2(:,:,3);
figure(3);
imwrite(uint8(h_img), 'H_comp.jpg');
imshow(h_img);
title('H component');
figure(4);
imshow(s_img);
title('S component');
imwrite(uint8(s_img), 'S_comp.jpg');
figure(5);
imshow(v_img);
title('V component');
imwrite(uint8(v_img), 'V_comp.jpg');
[row,col] = size(image1)
size_host = row*col;
o_double = double(image1);
w_double = double(image2);
s=0;
for j = 1:size_host; % the size of the original image
s = s+(w_double(j) - o_double(j))^2 ;
end
mes=s/size_host;
psnr =10*log10((255)^2/mes);
rmse= sqrt(mes);
display 'Value of',psnr
display 'Value of',mes
display 'Value of', rmse

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!