Reputation: 3
I'm doing a watermarking project in MATLAB. I have applied blockwise DCT to image and watermark is embedded. Inverse DCT is taken and new watermarked image is stored. For extraction purpose, when I again tried to take the DCT i could find some change happened when compared to the DCT image just before doing inverse DCT(in watremarking process). Because of this change i couldnt extract correct watermark. Can anyone suggest some methods to avoid this changes?
Here is the code I have tried:
img=imread('cameraman.tif');
original=double(img)-128;
fundct = @(block_struct) dct2(block_struct.data);
dctimg=blockproc(original,[8 8],fundct);
modified=dctimg+10;%modification is done
funrev = @(block_struct) idct2(block_struct.data); %to perform inverse dct
invdct = blockproc(modified,[8 8],funrev); % combining 8*8 blocks
invdct=uint8(invdct)+128;% now invdct is modified image
againdct=double(invdct)-128; % agin spply dct to it
fundct = @(block_struct) dct2(block_struct.data);
againdct=blockproc(againdct,[8 8],fundct);
Upvotes: 0
Views: 2369
Reputation: 104514
Your problem is specifically at this point in your code:
invdct=uint8(invdct)+128;% now invdct is modified image
againdct=double(invdct)-128; % agin spply dct to it
In your results, are they slightly inaccurate? That's because of your uint8
casting. invdct
will inevitably be floating point, and so if you cast the variable to uint8
, any precision that is required to accurately reconstruct the DCT coefficients is removed. For example, when you take the inverse DCT, you will get floating point values, like 25.6161 or 9.19391. These values may not appear in your image, but these are the kinds of numbers you would get.
Doing uint8
, will remove this precision, and so you would get 25
and 9
. If you do the DCT of this, you will for sure not get the same results as you did with the other image. You are essentially quantizing and thus your inaccuracy occurs.
As such, you should avoid casting to uint8
if you want to reconstruct the same DCT results. Try removing this cast and see if it works.
Upvotes: 1