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('第一层加水印图像');计算含水印图像的 PSNR;计算提取水印的 NC和BER
时间: 2024-03-25 07:39:28 浏览: 115
计算含水印图像的PSNR:
```matlab
Im = imread('szy1.jpg');
In = rgb2gray(Im);
I1 = bitget(In, 1);
one = I1(1:200,1:200);
one = im2bw(uint8(one) * 255);
I = In - (min(In(:)));
message = imread('watermark.bmp');
[Mw,Nw]=size(message);
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
imwrite(embed,'ok.bmp')
I = imread('ok.bmp');
[M, N] = size(I);
MSE = sum(sum((I - embed).^2)) / (M * N);
PSNR = 10 * log10(255^2 / MSE)
```
计算提取水印的NC:
```matlab
waterMark = I0(1:32,1:32);
waterMark = im2bw(uint8(waterMark) * 255);
NC = sum(sum(waterMark == message)) / (32 * 32)
```
计算提取水印的BER:
```matlab
waterMark = I0(1:200,1:200);
waterMark = im2bw(uint8(waterMark) * 255);
BER = sum(sum(waterMark ~= one)) / (200 * 200)
```
需要注意的是,上述代码中的变量`I0`没有给出,需要根据实际情况进行修改,以便能够正确运行。
阅读全文