how to successfully extract the image in blind color image watermarking using FWHT and SVD
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
my extracted watermark image is not similar with original watermark image where there exist gray background in the extracted watermark image and the color also did not same as original.
this is my code using FWHT and SVD algorithm
% Read the watermarked image
%watermarked = imread('C:\Users\window10\Documents\JAMILAH\KELAS CS249\FYP\Watermarking\images\watermarked_1\2.png');
% Read the original host image
host = imread('C:\Users\window10\Documents\JAMILAH\KELAS CS249\FYP\Watermarking\images\host 1.png');
wm = imread('C:\Users\window10\Documents\JAMILAH\KELAS CS249\FYP\Watermarking\images\w image 2.png');
%EMBEDDING
% Resize watermark to match the host image size if necessary
wm = imresize(wm, size(host(:,:,1)));
% Extract individual color channels of the host image
h_red = host(:,:,1);
h_green = host(:,:,2);
h_blue = host(:,:,3);
% Extract individual color channels of the watermark image
wm_red = wm(:,:,1);
wm_green = wm(:,:,2);
wm_blue = wm(:,:,3);
% Apply FWHT to host image
transformed_h_red = fwht2(h_red);
transformed_h_green = fwht2(h_green);
transformed_h_blue = fwht2(h_blue);
% Apply FWHT to watermark image
transformed_wm_red = fwht2(wm_red);
transformed_wm_green = fwht2(wm_green);
transformed_wm_blue = fwht2(wm_blue);
% Apply SVD to FWHT-transformed host images
[U_h_red, S_h_red, V_h_red] = svd(transformed_h_red);
[U_h_green, S_h_green, V_h_green] = svd(transformed_h_green);
[U_h_blue, S_h_blue, V_h_blue] = svd(transformed_h_blue);
% Apply SVD to FWHT-transformed watermark images
[~, S_wm_red] = svd(transformed_wm_red);
[~, S_wm_green] = svd(transformed_wm_green);
[~, S_wm_blue] = svd(transformed_wm_blue);
% Modify the singular values of the host image by the singular values of the watermark image
alpha = 0.01; % Example scaling factor, adjust as needed
S_new_red = S_h_red + (alpha * S_wm_red);
S_new_green = S_h_green + (alpha * S_wm_green);
S_new_blue = S_h_blue + (alpha * S_wm_blue);
% Apply the inverse SVD to get the watermarked image channels
watermarked_red = U_h_red * S_new_red * V_h_red';
watermarked_green = U_h_green * S_new_green * V_h_green';
watermarked_blue = U_h_blue * S_new_blue * V_h_blue';
% Apply inverse FWHT to each color channel of the watermarked image
watermarked_red = ifwht2(watermarked_red);
watermarked_green = ifwht2(watermarked_green);
watermarked_blue = ifwht2(watermarked_blue);
% Combine the RGB blocks to form the final watermarked color image
watermarked_color_image = cat(3, watermarked_red, watermarked_green, watermarked_blue);
% Scale the image data to the range [0, 1] and convert to uint8
watermarked = (255 * mat2gray(watermarked_color_image));
%watermarked = uint8(watermarked);
% Display the final watermarked color image in original size
%figure; % Open a new figure window
%imshow(watermarked, 'InitialMagnification', 'fit');
%title('Watermarked Image');
% Open a dialog box to get the file path
%[filename, pathname] = uiputfile({'*.png';'*.jpg';'*.bmp';'*.tiff'}, 'Save as');
%if isequal(filename,0) || isequal(pathname,0)
% disp('User pressed cancel')
%else
% Create the full file path
% full_filename = fullfile(pathname, filename);
% Save the watermarked color image to the chosen location
% imwrite(watermarked_color_image, full_filename);
% Display a message to indicate the image has been saved
% disp(['Watermarked image saved as ', full_filename]);
%end
%END EMBED
%%
%EXTRACTION PROCESS
% Extract individual color channels of the watermarked image
%watermarked = imread('C:\Users\User\Downloads\watermarked_12.png');
% Read the original host image
%host = imread('C:\Users\User\Downloads\host 1.png');
%wm = imread('C:\Users\User\Downloads\w image 1.png');
%EMBEDDING
% Resize watermark to match the host image size if necessary
wm = imresize(wm, size(host(:,:,1)));
% % Extract individual color channels of the host image
% h_red = host(:,:,1);
% h_green = host(:,:,2);
% h_blue = host(:,:,3);
% Extract individual color channels of the watermark image
wm_red = wm(:,:,1);
wm_green = wm(:,:,2);
wm_blue = wm(:,:,3);
w_red = watermarked(:,:,1);
w_green = watermarked(:,:,2);
w_blue = watermarked(:,:,3);
% Extract individual color channels of the host image
h_red = host(:,:,1);
h_green = host(:,:,2);
h_blue = host(:,:,3);
% Apply FWHT to the watermarked image and the host image
transformed_w_red = fwht2(w_red);
transformed_w_green = fwht2(w_green);
transformed_w_blue = fwht2(w_blue);
transformed_wm_red = fwht2(wm_red);
transformed_wm_green = fwht2(wm_green);
transformed_wm_blue = fwht2(wm_blue);
transformed_h_red = fwht2(h_red);
transformed_h_green = fwht2(h_green);
transformed_h_blue = fwht2(h_blue);
% Apply SVD to the FWHT-transformed watermarked image
[U_w_red, S_w_red, V_w_red] = svd(transformed_w_red);
[U_w_green, S_w_green, V_w_green] = svd(transformed_w_green);
[U_w_blue, S_w_blue, V_w_blue] = svd(transformed_w_blue);
% Apply SVD to the FWHT-transformed watermarked image
[U_wm_red, S_wm_red, V_wm_red] = svd(transformed_wm_red);
[U_wm_green, S_wm_green, V_wm_green] = svd(transformed_wm_green);
[U_wm_blue, S_wm_blue, V_wm_blue] = svd(transformed_wm_blue);
% Apply SVD to the FWHT-transformed host image
[~, S_h_red, ~] = svd(transformed_h_red);
[~, S_h_green, ~] = svd(transformed_h_green);
[~, S_h_blue, ~] = svd(transformed_h_blue);
% Subtract the singular values of the host image from the singular values of the watermarked image
S_ext_red = (S_w_red - S_h_red)/alpha;
S_ext_green = (S_w_green - S_h_green)/alpha;
S_ext_blue = (S_w_blue - S_h_blue)/alpha;
% Apply the inverse SVD to acquire the extracted watermark image
extracted_red = U_wm_red * S_ext_red * V_wm_red';
extracted_green = U_wm_green * S_ext_green * V_wm_green';
extracted_blue = U_wm_blue * S_ext_blue * V_wm_blue';
% Apply the inverse FWHT
extracted_red = ifwht2(extracted_red);
extracted_green = ifwht2(extracted_green);
extracted_blue = ifwht2(extracted_blue);
% Combine the RGB blocks to form the final extracted watermark image
extracted_watermark = cat(3, extracted_red, extracted_green, extracted_blue);
%%
% figure;imshow(uint8(extracted_watermark));
extracted_watermark = uint8(255 * mat2gray( (extracted_watermark)));
% extracted_watermark = uint8(extracted_watermark);
figure;imshow(extracted_watermark);
% Resize the extracted watermark image to 128 x 128
extracted_watermark = imresize(extracted_watermark, [128 128]);
% Display the host image, watermark image, watermarked image, and extracted image side by side
figure; % Open a new figure window
subplot(1, 4, 1);
imshow(host, 'InitialMagnification', 'fit');
title('Host Image');
subplot(1, 4, 2);
imshow(wm, 'InitialMagnification', 'fit');
title('Watermark Image');
watermarked = uint8(watermarked);
subplot(1, 4, 3);
imshow(watermarked, 'InitialMagnification', 'fit');
title('Watermarked Image');
subplot(1, 4, 4);
imshow(extracted_watermark, 'InitialMagnification', 'fit');
title('Extracted Watermark Image');
% Function to apply 2D FWHT
function transformed_image = fwht2(image)
% Apply the 2D FWHT
transformed_image = fwht(fwht(double(image)).').';
end
% Function to apply 2D inverse FWHT
function image = ifwht2(transformed_image)
% Apply the 2D inverse FWHT
image = ifwht(ifwht(double(transformed_image)).').';
end
1 comentario
Drishti
el 9 de Ag. de 2024
Is this code working fine and can you tell me if you are only facing issue in the quality of image generated at the end?
Respuestas (1)
Gayathri
el 9 de Ag. de 2024
The implementation is done in R2024a. I implemented the code by taking two images available in my side. I have done a few changes to the code. It is always advisable to work on images in “double” format rather than working in “uint8” format. Hence, the images are converted to “double” using “im2double” function before any operations are applied on the image.
Also, you were converting your watermarked image to “uint8” and then tried to extract from it. The “double” format of image is retained till end of the code. Before displaying, the images are converted back into “uint8” using “im2uint8” function. In this way, background of the extracted image will be similar to the original image.
Please see the code below for reference.
wm = imresize(wm, size(host(:,:,1)));
host=im2double(host)
wm=im2double(wm)
% Extract individual color channels of the host image
h_red = host(:,:,1);
h_green = host(:,:,2);
h_blue = host(:,:,3);
% Extract individual color channels of the watermark image
wm_red = wm(:,:,1);
wm_green = wm(:,:,2);
wm_blue = wm(:,:,3);
% Apply FWHT to host image
transformed_h_red = fwht2(h_red);
transformed_h_green = fwht2(h_green);
transformed_h_blue = fwht2(h_blue);
% Apply FWHT to watermark image
transformed_wm_red = fwht2(wm_red);
transformed_wm_green = fwht2(wm_green);
transformed_wm_blue = fwht2(wm_blue);
% Apply SVD to FWHT-transformed host images
[U_h_red, S_h_red, V_h_red] = svd(transformed_h_red);
[U_h_green, S_h_green, V_h_green] = svd(transformed_h_green);
[U_h_blue, S_h_blue, V_h_blue] = svd(transformed_h_blue);
% Apply SVD to FWHT-transformed watermark images
[~, S_wm_red] = svd(transformed_wm_red);
[~, S_wm_green] = svd(transformed_wm_green);
[~, S_wm_blue] = svd(transformed_wm_blue);
% Modify the singular values of the host image by the singular values of the watermark image
alpha = 0.01; % Example scaling factor, adjust as needed
S_new_red = S_h_red + (alpha * S_wm_red);
S_new_green = S_h_green + (alpha * S_wm_green);
S_new_blue = S_h_blue + (alpha * S_wm_blue);
% Apply the inverse SVD to get the watermarked image channels
watermarked_red = U_h_red * S_new_red * V_h_red';
watermarked_green = U_h_green * S_new_green * V_h_green';
watermarked_blue = U_h_blue * S_new_blue * V_h_blue';
% Apply inverse FWHT to each color channel of the watermarked image
watermarked_red = ifwht2(watermarked_red);
watermarked_green = ifwht2(watermarked_green);
watermarked_blue = ifwht2(watermarked_blue);
% Combine the RGB blocks to form the final watermarked color image
watermarked = cat(3, watermarked_red, watermarked_green, watermarked_blue);
wm = imresize(wm, size(host(:,:,1)));
% % Extract individual color channels of the host image
% h_red = host(:,:,1);
% h_green = host(:,:,2);
% h_blue = host(:,:,3);
% Extract individual color channels of the watermark image
wm_red = wm(:,:,1);
wm_green = wm(:,:,2);
wm_blue = wm(:,:,3);
w_red = watermarked(:,:,1);
w_green = watermarked(:,:,2);
w_blue = watermarked(:,:,3);
% Extract individual color channels of the host image
h_red = host(:,:,1);
h_green = host(:,:,2);
h_blue = host(:,:,3);
% Apply FWHT to the watermarked image and the host image
transformed_w_red = fwht2(w_red);
transformed_w_green = fwht2(w_green);
transformed_w_blue = fwht2(w_blue);
% Apply SVD to the FWHT-transformed watermarked image
[U_w_red, S_w_red, V_w_red] = svd(transformed_w_red);
[U_w_green, S_w_green, V_w_green] = svd(transformed_w_green);
[U_w_blue, S_w_blue, V_w_blue] = svd(transformed_w_blue);
% Apply SVD to the FWHT-transformed watermarked image
[U_wm_red, S_wm_red, V_wm_red] = svd(transformed_wm_red);
[U_wm_green, S_wm_green, V_wm_green] = svd(transformed_wm_green);
[U_wm_blue, S_wm_blue, V_wm_blue] = svd(transformed_wm_blue);
% Apply SVD to the FWHT-transformed host image
[~, S_h_red, ~] = svd(transformed_h_red);
[~, S_h_green, ~] = svd(transformed_h_green);
[~, S_h_blue, ~] = svd(transformed_h_blue);
% Subtract the singular values of the host image from the singular values of the watermarked image
S_ext_red = (S_w_red - S_h_red)/alpha;
S_ext_green = (S_w_green - S_h_green)/alpha;
S_ext_blue = (S_w_blue - S_h_blue)/alpha;
% Apply the inverse SVD to acquire the extracted watermark image
extracted_red = U_wm_red * S_ext_red * V_wm_red';
extracted_green = U_wm_green * S_ext_green * V_wm_green';
extracted_blue = U_wm_blue * S_ext_blue * V_wm_blue';
% Apply the inverse FWHT
extracted_red = ifwht2(extracted_red);
extracted_green = ifwht2(extracted_green);
extracted_blue = ifwht2(extracted_blue);
% Combine the RGB blocks to form the final extracted watermark image
extracted_watermark = cat(3, extracted_red, extracted_green, extracted_blue);
%%
% figure;imshow(uint8(extracted_watermark));
extracted_watermark = im2uint8(extracted_watermark);
% extracted_watermark = uint8(extracted_watermark);
figure;imshow(extracted_watermark);
% Resize the extracted watermark image to 128 x 128
extracted_watermark = imresize(extracted_watermark, [128 128]);
% Display the host image, watermark image, watermarked image, and extracted image side by side
figure; % Open a new figure window
subplot(1, 4, 1);
imshow(host, 'InitialMagnification', 'fit');
title('Host Image');
subplot(1, 4, 2);
imshow(wm, 'InitialMagnification', 'fit');
title('Watermark Image');
watermarked = im2uint8(watermarked);
subplot(1, 4, 3);
imshow(watermarked, 'InitialMagnification', 'fit');
title('Watermarked Image');
subplot(1, 4, 4);
imshow(extracted_watermark, 'InitialMagnification', 'fit');
title('Extracted Watermark Image');
% Function to apply 2D FWHT
function transformed_image = fwht2(image)
% Apply the 2D FWHT
transformed_image = fwht(fwht(double(image)).').';
end
% Function to apply 2D inverse FWHT
function image = ifwht2(transformed_image)
% Apply the 2D inverse FWHT
image = ifwht(ifwht(double(transformed_image)).').';
end
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!