我在MATLAB里做一个水印项目。将分块DCT应用于图像,并嵌入水印。采用逆DCT变换,并存储新的水印图像。为了提取的目的,当我再次尝试采取DCT时,我可以发现与DCT图像相比,在做反DCT之前(在观察过程中)发生了一些变化。由于这一变化,我无法提取正确的水印。有人能提出一些避免这种变化的方法吗?
下面是我尝试过的代码:
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); 发布于 2014-09-22 17:56:15
在这一点上,您的问题在代码中是明确的:
invdct=uint8(invdct)+128;% now invdct is modified image
againdct=double(invdct)-128; % agin spply dct to it 在你的结果中,它们是否有点不准确?那是因为你的uint8演员。invdct将不可避免地成为浮点,因此,如果将变量转换为uint8,则需要精确重构DCT系数所需的任何精度都将被删除。例如,当您采取反DCT,您将得到浮点值,如25.6161或9.19391。这些值可能不会出现在您的图像中,但这些是您将得到的数字类型。
执行uint8,将消除这种精度,因此您将得到25和9。如果你这样做的DCT,你肯定不会得到相同的结果,你对其他图像。你本质上是量化的,因此你的不准确就会发生。
因此,如果要重构相同的离散余弦变换结果,则应避免转换为uint8。尝试删除此强制转换并查看它是否有效。
https://stackoverflow.com/questions/25956331
复制相似问题