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