I am getting an error in watermark extraction.. actually extracted watermark is showing blank image. please help me with this code.. thank you

4 visualizaciones (últimos 30 días)
% Step 1: Read the original color image OI of size N x N
OI = imread('mandrill.jpg');
OI = uint8(imresize(OI, [512 512]));
% Step 2: Select the Red color component from the original image
color_component = OI(:, :, 1); % Red color component
% Step 3: Apply DWT to decompose the color component into LL, HL, LH, and HH sub-bands
[LL, HL, LH, HH] = dwt2(color_component, 'haar');
% Step 4: Apply DWT to the LL sub-band to decompose it further
[LL_LL, LL_HL, LL_LH, LL_HH] = dwt2(LL, 'haar');
% Step 5: Apply DCT to the LL_HH sub-band and obtain the DCT coefficient matrix B
B = dct2(LL_HH);
% Step 6: Apply SVD to B and obtain U, S, and V
[U, S, V] = svd(B);
% Step 7: Read the watermark image OW of size N/2 x N/2
OW = imread('peppers.jpg');
OW = uint8(imresize(OW, [256 256]));
OW = OW(:, :, 1); % Red color component
% Step 8: Apply DWT to decompose the watermark image into WLL, WHL, WLH, and WHH sub-bands
[WLL, WHL, WLH, WHH] = dwt2(OW, 'haar');
% Step 9: Apply DCT to the WHH sub-band and obtain the DCT coefficient matrix D
D = dct2(WHH);
% Step 10: Apply SVD to D and obtain U1, S1, and V1
[U1, S1, V1] = svd(D);
% Step 11: Modify S with the watermark by calculating S2 = S + alpha * S1
alpha = 0.01; % Modify the value of alpha as needed
S2 = S + alpha * S1;
% Step 12: Obtain B* using B* = U * S2 * V'
B_modified = U * S2 * V';
% Step 13: Apply inverse DCT to B* to produce the modified LL_HH* sub-band
LL_HH_modified = idct2(B_modified);
% Step 14: Apply inverse DWT to LL_LL, LL_HL, LL_LH, and LL_HH* to get the modified LL* sub-band
LL_modified = idwt2(LL_LL, LL_HL, LL_LH, LL_HH_modified, 'haar');
% Step 15: Apply inverse DWT to LL*, HL, LH, and HH to get the watermarked image
WI = idwt2(LL_modified, HL, LH, HH, 'haar');
% Step 16: Set the modified color component to the original image
OI_watermarked = OI;
OI_watermarked(:, :, 1) = WI; % Replace the Red component with the watermarked component
% Display and save the watermarked image
figure;
imshow(OI_watermarked);
title('Watermarked Image');
imwrite(OI_watermarked, 'watermarked_image.jpg');
% Step 1: Read the watermarked image
OI_watermarked = imread('watermarked_image.jpg');
% Step 2: Select the Red color component from the watermarked image
color_component_watermarked = OI_watermarked(:, :, 1); % Red color component
% Step 3: Apply DWT to decompose the color component into LL, HL, LH, and HH sub-bands
[LL_watermarked, HL_watermarked, LH_watermarked, HH_watermarked] = dwt2(color_component_watermarked, 'haar');
% Step 4: Apply DWT to the LL sub-band to decompose it further
[LL_LL_watermarked, LL_HL_watermarked, LL_LH_watermarked, LL_HH_watermarked] = dwt2(LL_watermarked, 'haar');
% Step 5: Select the LL_HH* band and apply DCT to it to obtain the DCT coefficient matrix A
A = dct2(LL_HH_watermarked);
% Step 6: Apply SVD to A and obtain WU, WS, and WV
[WU, WS, WV] = svd(A);
% Step 7: Calculate Sr by subtracting the original singular values WS from S
Sr = (S - WS) / alpha;
% Step 8: Obtain Wr using Wr = U1 * Sr * V1'
Wr = U1 * Sr * V1';
% Step 9: Apply inverse DCT to Wr to produce the extracted LL_HH* sub-band
LL_HH_extracted = idct2(Wr);
% Step 10: Apply inverse DWT to LL_LL_watermarked, LL_HL_watermarked, LL_LH_watermarked, and LL_HH_extracted to get the extracted LL* sub-band
LL_extracted = idwt2(LL_LL_watermarked, LL_HL_watermarked, LL_LH_watermarked, LL_HH_extracted, 'haar');
% Step 11: Apply inverse DWT to LL_extracted, HL_watermarked, LH_watermarked, and HH_watermarked to get the extracted watermarked image
OW_extracted = idwt2(LL_extracted, HL_watermarked, LH_watermarked, HH_watermarked, 'haar');
% Set the extracted watermark to the original watermark size
extracted_watermark = imresize(OW_extracted, [256 256]);
% Display the extracted watermark image
figure;
imshow(extracted_watermark);
title('Extracted Watermark');
% Save the extracted watermark image
imwrite(extracted_watermark, 'extracted_watermark.jpg');

Respuestas (1)

Image Analyst
Image Analyst el 30 de Mayo de 2023
Looks like it requires teh Wavelet toolbox, which I don't have. Is extracted_watermark floating point? If so, try this:
imshow(extracted_watermark, []);
  8 comentarios
Suniti Singh
Suniti Singh el 31 de Mayo de 2023
thank you for you reply but sir i am implementing one paper using the same steps an same images with same dimensions and as i said i am getting PSNR value is infinite but the paper i referred had only PSNR values approx to 55dB. If possible can you go through my code to check is there any mistakes in the code it will be a great help for me.
thank you once again for giving your valuable time.
Image Analyst
Image Analyst el 31 de Mayo de 2023
Sorry, I don't have the wavelet toolbox, and I can't really debug or examine variables if I run the code here in answers.
% Step 1: Read the original color image OI of size N x N
OI = imread('mandrill.jpg');
OI = uint8(imresize(OI, [512 512]));
% Step 2: Select the Red color component from the original image
color_component = OI(:, :, 1); % Red color component
% Step 3: Apply DWT to decompose the color component into LL, HL, LH, and HH sub-bands
[LL, HL, LH, HH] = dwt2(color_component, 'haar');
% Step 4: Apply DWT to the LL sub-band to decompose it further
[LL_LL, LL_HL, LL_LH, LL_HH] = dwt2(LL, 'haar');
% Step 5: Apply DCT to the LL_HH sub-band and obtain the DCT coefficient matrix B
B = dct2(LL_HH);
% Step 6: Apply SVD to B and obtain U, S, and V
[U, S, V] = svd(B);
% Step 7: Read the watermark image OW of size N/2 x N/2
OW = imread('peppers.png');
OW = uint8(imresize(OW, [256 256]));
OW = OW(:, :, 1); % Red color component
% Step 8: Apply DWT to decompose the watermark image into WLL, WHL, WLH, and WHH sub-bands
[WLL, WHL, WLH, WHH] = dwt2(OW, 'haar');
% Step 9: Apply DCT to the WHH sub-band and obtain the DCT coefficient matrix D
D = dct2(WHH);
% Step 10: Apply SVD to D and obtain U1, S1, and V1
[U1, S1, V1] = svd(D);
% Step 11: Modify S with the watermark by calculating S2 = S + alpha * S1
alpha = 0.01; % Modify the value of alpha as needed
S2 = S + alpha * S1;
% Step 12: Obtain B* using B* = U * S2 * V'
B_modified = U * S2 * V';
% Step 13: Apply inverse DCT to B* to produce the modified LL_HH* sub-band
LL_HH_modified = idct2(B_modified);
% Step 14: Apply inverse DWT to LL_LL, LL_HL, LL_LH, and LL_HH* to get the modified LL* sub-band
LL_modified = idwt2(LL_LL, LL_HL, LL_LH, LL_HH_modified, 'haar');
% Step 15: Apply inverse DWT to LL*, HL, LH, and HH to get the watermarked image
WI = idwt2(LL_modified, HL, LH, HH, 'haar');
% Step 16: Set the modified color component to the original image
OI_watermarked = OI;
OI_watermarked(:, :, 1) = WI; % Replace the Red component with the watermarked component
% Display and save the watermarked image
figure;
imshow(OI_watermarked);
title('Watermarked Image');
imwrite(OI_watermarked, 'watermarked_image.jpg');
% Step 1: Read the watermarked image
OI_watermarked = imread('watermarked_image.jpg');
% Step 2: Select the Red color component from the watermarked image
color_component_watermarked = OI_watermarked(:, :, 1); % Red color component
% Step 3: Apply DWT to decompose the color component into LL, HL, LH, and HH sub-bands
[LL_watermarked, HL_watermarked, LH_watermarked, HH_watermarked] = dwt2(color_component_watermarked, 'haar');
% Step 4: Apply DWT to the LL sub-band to decompose it further
[LL_LL_watermarked, LL_HL_watermarked, LL_LH_watermarked, LL_HH_watermarked] = dwt2(LL_watermarked, 'haar');
% Step 5: Select the LL_HH* band and apply DCT to it to obtain the DCT coefficient matrix A
A = dct2(LL_HH_watermarked);
% Step 6: Apply SVD to A and obtain WU, WS, and WV
[WU, WS, WV] = svd(A);
% Step 7: Calculate Sr by subtracting the original singular values WS from S
Sr = (S - WS) / alpha;
% Step 8: Obtain Wr using Wr = U1 * Sr * V1'
Wr = U1 * Sr * V1';
% Step 9: Apply inverse DCT to Wr to produce the extracted LL_HH* sub-band
LL_HH_extracted = idct2(Wr);
% Step 10: Apply inverse DWT to LL_LL_watermarked, LL_HL_watermarked, LL_LH_watermarked, and LL_HH_extracted to get the extracted LL* sub-band
LL_extracted = idwt2(LL_LL_watermarked, LL_HL_watermarked, LL_LH_watermarked, LL_HH_extracted, 'haar');
% Step 11: Apply inverse DWT to LL_extracted, HL_watermarked, LH_watermarked, and HH_watermarked to get the extracted watermarked image
OW_extracted = idwt2(LL_extracted, HL_watermarked, LH_watermarked, HH_watermarked, 'haar');
% Set the extracted watermark to the original watermark size
extracted_watermark = imresize(OW_extracted, [256 256]);
% Display the extracted watermark image
figure;
whos extracted_watermark
Name Size Bytes Class Attributes extracted_watermark 256x256 524288 double
imshow(extracted_watermark, []);
title('Extracted Watermark');
% Save the extracted watermark image
imwrite(extracted_watermark, 'extracted_watermark.jpg');

Iniciar sesión para comentar.

Productos


Versión

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by