Im = imread('szy1.jpg'); In = rgb2gray(Im); I1 = bitget(In, 1); one = I1(1:200,1:200); one = im2bw(uint8(one) * 255); figure; subplot(2,3,3) imshow(one); title('第一层图像'); I = In - (min(In(:))); [M,N] = size(I); subplot(2,3,1) imshow(I); title('载体图像'); message=imread('watermark.bmp');[Mw,Nw]=size(message); subplot(2,3,2) imshow(message);title('原始水印'); embed=I; for i=1:Mw for j=1:Nw embed(i,j)=embed(i,j)-mod(embed(i,j),2)+uint8(message(i,j)); end end subplot(2,3,4) imshow(embed);title('含水印图像');drawnow; imwrite(embed,'ok.bmp') I = imread('ok.bmp'); I0 = bitget(I, 1); waterMark = I0(1:32,1:32); waterMark = im2bw(uint8(waterMark) * 255); subplot(2,3,5) imshow(waterMark); title('提取图像'); waterMark = I0(1:200,1:200); waterMark = im2bw(uint8(waterMark) * 255); subplot(2,3,6) imshow(waterMark); title('第一层加水印图像'); I_double = im2double(I); Im_double = im2double(Im); MSE = mean((I_double(:) - Im_double(:)).^2); PSNR = 10 * log10(1/MSE); fprintf('PSNR = %f dB\n', PSNR); NC = sum(waterMark(:) == one(:)) / numel(one); fprintf('NC = %f\n', NC); diff = abs(waterMark - one); BER = sum(diff(:)) / numel(diff); fprintf('BER = %f\n', BER);修改,矩阵维度不一样
时间: 2024-03-22 19:40:56 浏览: 59
gray2rgb.rar_Gray转化为RGB_gray2rgb_gray2rgb算法
如果原始水印图像和第一层加水印的图像的尺寸不同,需要修改提取水印的代码。假设原始水印图像为 $M_1 \times N_1$,第一层加水印的图像为 $M_2 \times N_2$,可以按照下面的代码进行修改:
```
I0 = bitget(I, 1);
waterMark = I0(1:M1,1:N1); % 提取水印
waterMark = im2bw(uint8(waterMark) * 255);
subplot(2,3,5); imshow(waterMark); title('提取图像');
waterMark = I0(1:M2,1:N2); % 提取第一层加水印的水印
waterMark = im2bw(uint8(waterMark) * 255);
subplot(2,3,6); imshow(waterMark); title('第一层加水印图像的水印');
```
其中,$M_1,N_1$ 是原始水印图像的尺寸,$M_2,N_2$ 是第一层加水印的图像的尺寸。
阅读全文