Karhunen-Loeve Transform for watermarking

2 ビュー (過去 30 日間)
Emile Van Vaerenbergh
Emile Van Vaerenbergh 2022 年 12 月 12 日
回答済み: Harsh Sanghai 2023 年 3 月 23 日
Does someone have any code for digital watermarking using the KLT transform? Any help would be welcome!

回答 (1 件)

Harsh Sanghai
Harsh Sanghai 2023 年 3 月 23 日
Hi,
Here is a sample code which you can use for digital watermarking using KLT transform in using MATLAB:
% Read the original image
I = imread('original_image.jpg');
% Convert the image to grayscale
I_gray = rgb2gray(I);
% Generate the watermark image
W = rand(size(I_gray)) > 0.5;
% Perform KLT transform on the original image
C = dct2(I_gray);
% Calculate the covariance matrix
R = cov(C);
% Calculate the eigenvalues and eigenvectors
[V,D] = eig(R);
% Sort the eigenvalues in descending order
[~,ind] = sort(diag(D),'descend');
V = V(:,ind);
% Use the first N eigenvectors to embed the watermark
N = 5;
W_embedded = C + 0.1*W.*repmat(V(:,1:N)*V(:,1:N)',size(C,1),size(C,2));
% Perform inverse KLT transform
I_watermarked = idct2(W_embedded);
% Display the original and watermarked images
figure;imshow(I_gray);title('Original Image');
figure;imshow(I_watermarked);title('Watermarked Image');

Community Treasure Hunt

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

Start Hunting!

Translated by