Watermarking in the Frequency Domain

I am new in Matlab and I have an assignment that is asking for watermarking an image using DCT transform:
  • Read Lin.jpg color image and apply DCT.
  • Threshold the logo.jpg (watermark) into binary and ten times of its strength, and then add it to the coefficient of transformed Lin image.
Here are the two images:
I have three questions:
  1. Am I supposed to divide Lin.jpg into 8x8 blocks and logo.jpg into 2x2 blocks or that is not necessary?
  2. what does it mean by : "ten times of its strength"? Is that just multiplying by 10?
  3. How can I get the coefficient of transformed Lin.jpg image?
Here is what I tried:
img = imread('Lin.jpg');
wImg = imread('njit_logo.jpg');
wImgBinary = imbinarize(wImg) * 10;
[rows, cols] = size(img(:,:,1));
[Wrows, Wcols] = size(wImgBinary);
% make the watermark image as large as the original
watermark = zeros(size(img), 'uint8');
for column = 1:cols
for row = 1:rows
watermark(row, column) = wImgBinary(mod(row,Wrows)+1, mod(column,Wcols)+1);
end
end
watermark = watermark(1:rows, 1:cols);
% apply dct and add with watermark at each channel
for i = 1:3
imgDct = dct2(img(:,:,i));
C = imgDct + double(watermark);
Iw(:,:,i) = round(real(idct2(C)));
end
IIw = uint8(Iw);
figure, imshow(IIw), title('watermarked image');

9 Comments

I would tend to think the ten times would be multiplying the binary (0, 1) by 10, getting either 0 or 10.
wImgDct = dct2(wImgBinary);
That is not asked for. Just add the wImgBinary to imgDct .
ok I fixed that part. but still not sure how to do this.
The resulting watermarked image doesn't have any difference with the original.
The watermarked image does differ from the original. Do
imshowpair(IIw, img)
and
imshowpair(IIw, img, 'diff')
Yes, I asked the same question here and I think the problem was I should have applied DCT to the logo as well.
Our professor said no, but without applying DCT to both the image and watermark before addition, I got strange results.
Hadi if you look when you do the side by side it kind of looks like his note in HW4R in the top left, so I think its strange to us but correct. Have you figured out the inverse or part B?
Yes I think I had it wrong. This is what Professor said:
"You take the Lin image by DCT. Then the NJIT watermark is thresholded into a binary image.
Then add the binary watermark to the DCT of Lin point-by-point starting at the upper-left corner of the image."
For part B, I did this:
  • noisy = added noist to the watermarked image from part A
  • noisyDCT = dct2(noisy)
  • sub = noisyDCT - 10 * dct2(binaryLogo)
  • de-watermarked = uint8(real(idct2(sub)))
but I am sure this one is wrong as well, especially the dct2(binaryLogo) part.
So wait because he confuses me too... isn't idct supposed to be one of the five images in part A too? or does part B provide the last 2 images he asked for in A. Because in the above I didn't notice where you did the inverse dct on Lin
part B it says first DCT the noisy image. Then subtract the (logo*10) and at the end IDCT the result. For me, it is in the last line above (uint8(real(idct2(sub)))). But I got black images from this so I applied DCT on the (logo) as well.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!