I really need help on this, this is my first time making a watermarking project

3 visualizzazioni (ultimi 30 giorni)
clc
clear all
close all
%%
host_image=imread('xray2.jpg');
host=im2gray(host_image);
figure(1)
imshow(host,[]);
title(host_image);
[m,n]=size(host)
watermarkImage = imread('Lenna.png');
watermarkgray = rgb2gray(watermarkImage);
%
figure(2)
imshow(watermarkgray,[]);
title('watermark_Image');
% Extract the low-frequency DCT coefficients
% [LL, HL, LH, HH] = dwt2(hostnew, 'haar');
dct_img=dct2(host);
LL = dct_img(1:floor(size(dct_img, 1)/4), 1:floor(size(dct_img, 2)/4));
watermark=imresize(watermarkgray,size(LL));
watermark=double(watermark);
% figure (4)
% imshow(LL)
% Apply SVD to the low-frequency DCT & watermark coefficients
[Ull,Sll,Vll] = svd(LL);
[Uw,Sw,Vw] = svd(watermark);
% Generate a pseudo-random PN sequence
pnSequence=eye(size(Sw));
% Define the spread spectrum parameter
alpha = 0.04;
spreadfact = 0.5;
% Apply spread spectrum embedding
spreadingSw = Sw + spreadfact * pnSequence;
% spreadingSw =Sw +spreadfact*pnSequence;
SpreadedwatermarkSLL = Sll + alpha * spreadingSw;
% figure(2)
% imshow(spreadWatermark);
% title('spreadWatermark');
modifiedLL = Ull * SpreadedwatermarkSLL * Vll';
% Replace the low-frequency DCT coefficients with the modified coefficients
% Apply inverse DWT to get watermarked image:
dct_img(1:floor(size(dct_img, 1)/4), 1:floor(size(dct_img, 2)/4)) = modifiedLL;
% hostnew = idwt2(LLe, HL, LH, HH, 'haar');
watermarkedImage = idct2(dct_img);
% watermarkedImage8 = uint8(idct_img);
% watermarkedImage=watermarkedImage8;
% %Salt and Pepper Noise:
% watermarkedImage = imnoise(watermarkedImage, 'salt & pepper', 0.1);
% % % %Gaussian Noise:
% watermarkedImage = imnoise(watermarkedImage8, 'gaussian', 0, 0.01);
%Cropping:
% watermarkedImage = watermarkedImage8;
% watermarkedImage(1:32, 1:32) = 0;
%Blurring
% blurFilter = fspecial('average', [3 3]);
% watermarkedImage = imfilter(watermarkedImage8, blurFilter);
% %Sharpening:
% sharpenFilter = [-1 -1 -1; -1 9 -1; -1 -1 -1];
% watermarkedImage = imfilter(watermarkedImage8, sharpenFilter);
% %Convolution Filter:
% customFilter = ...
% [0.0625 0.125 0.0625; 0.125 0.25 0.125; 0.0625 0.125 0.0625];
% watermarkedImage = imfilter(watermarkedImage8, customFilter);
% %Median Filtering:
% watermarkedImage = medfilt2(watermarkedImage8, [3 3]);
% %Histogram Equalization:
% watermarkedImage = histeq(watermarkedImage8);
% %%%%%%%%%%%%%%%%%%
%
figure(3)
imshow(watermarkedImage);
title('Watermarked Image');
imwrite((watermarkedImage),'watermarkedimage.png')
%
%% % % extra
% Read the watermarked image
watermarkedImagee = imread('watermarkedimage.png');
% Convert the watermarked image to grayscale
% watermarkedgray = im2gray(watermarkedImage);
% Apply DCT to the watermarked image
dct_watermarked = dct2(watermarkedImagee)
% [LL_watermarked, HL_watermarked, LH_watermarked, HH_watermarked] = dwt2(watermarkedImage, 'haar');
LL_watermarked = dct_watermarked(1:floor(size(dct_watermarked, 1)/4), 1:floor(size(watermarkedImage, 2)/4));
;
% get the Low-frequency DCT cooefficients
% Apply SVD to the low-frequency DCT coefficients
[U_watermarked, S_watermarked, V_watermarked] = svd(LL_watermarked);
extractedSw = ( S_watermarked-Sll) / alpha;
% Remove the spread spectrum effect
% S_extracted = diag(extractedSw)- sum(spreadfact*pnSequence,2);
% extractedd=diag(S_extracted);
S_extracted = extractedSw- spreadfact*pnSequence;
WatermarkExt = Uw * S_extracted * Vw';
the_extracted = uint8(WatermarkExt);
figure(4)
imshow(the_extracted)
  2 Commenti
John D'Errico
John D'Errico il 2 Giu 2023
But what is your question? Just asking for general help does nothing. Does your code not work? Where does it fail? What is wrong with it?
LEILA
LEILA il 3 Giu 2023
Ohkey so my problem is when i add the attacks the extracted watermak is distorted like fully and i dont know what went wrong

Accedi per commentare.

Risposte (1)

Tushar
Tushar il 4 Giu 2023
Hi LEILA,
Based on the code you provided, it appears that you are performing image watermarking using the Discrete Cosine Transform (DCT) and spread spectrum embedding. After embedding the watermark, you apply various image processing attacks such as noise, cropping, blurring, sharpening, convolution filtering, median filtering, and histogram equalization. However, you mentioned that the extracted watermark is distorted when attacks are applied.
There are several potential reasons for this issue:
  1. Attack Intensity: The intensity or parameters of the applied attacks might be too strong, leading to significant distortion of the watermark during extraction. You can try adjusting the parameters of the attacks to reduce their impact and minimize distortion.
  2. Attack Order: The order in which you apply the attacks can affect the final result. Some attacks may be more destructive to the watermark than others. Consider experimenting with different attack orders to see if it improves the extraction quality.
  3. Attack Reversibility: Not all image processing attacks are easily reversible, and some may introduce irreversible changes that affect the watermark extraction process. Ensure that the attacks you apply are suitable for watermarking and can be reversed without significant loss of information.
  4. Watermark Strength: The strength of the embedded watermark may impact its resilience against attacks. If the watermark is too weak, it may be more prone to distortion or complete loss during the attacks. Consider adjusting the embedding strength or using robust watermarking techniques to improve the extraction quality.
  5. Algorithm Sensitivity: The watermark extraction algorithm itself may be sensitive to the applied attacks. Different algorithms have varying degrees of robustness to different attacks. You might need to explore alternative watermark extraction algorithms that are more resilient to the specific attacks you are using.
It is also worth noting that watermarking is a complex field, and the effectiveness of watermarking techniques can depend on various factors, including the choice of algorithms, image characteristics, and the specific application requirements. It may require further experimentation and optimization to achieve satisfactory results.
Additionally, consider visualizing intermediate results during the watermarking and attack processes to better understand the impact of each step and identify where the distortion may be introduced.
Finally, you can refer to academic literature or research papers on image watermarking and attack robustness to explore more advanced techniques and methodologies for improving the resilience of your watermarking system against various attacks.

Community Treasure Hunt

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

Start Hunting!

Translated by