如何使用 3 LSB 在图像中实现隐形水印图像
How to implement invisible watermark image in image using 3 LSB
我需要在不使用 MATLAB 中现有函数的情况下实现 3 LSB 水印。
我需要我的函数来获取 2 个图像,包括灰度级图像和使用 3 LSB 的预成型水印。
我尝试了以下方法,但是从新图像中减去原始图像的结果全为零,这意味着它们是相同的。
function [C] = Q2(image,watermark)
% clc;
% image=imread('moon.tif');
% watermark=imread('cameraman.tif');
[X,Y] = size(image);
rewatermark = imresize(watermark,[X,Y]); % resizing watermark to fit image
% iterate the 3 LSB of the watermark and set them to a copy of the original
% image 3 LSB
C = image;
for i = 1:X
for j = 1:Y
for k = 1:3
if(bitget(rewatermark(i,j),k) == 1)
bitset(C(i,j),k,1);
else
bitset(C(i,j),k,0);
end
end
end
end
subplot(1,3,1)
imshow(image);
title('Original');
subplot(1,3,2);
imshow(rewatermark)
title('Watermark');
subplot(1,3,3)
imshow(C)
title('Invisble watermarked');
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
set(gcf,'name','Q2 - Results','numbertitle','off')
而不是 bitset(C(i,j),k,1)
,使用:C(i,j) = bitset(C(i,j),k,1)
除了 OOP 编程,MATLAB 不支持引用(或指针)。
执行bitset(C(i,j),k,1)
,并不修改C(i,j)
的内容,而是将相关位设置为1,return修改后的值。
注:
我建议起诉 rewatermark
的高位(位 6、7、8),而不是主要是“噪声”的低位 1、2、3(但这取决于您的目标)。
这是一个代码示例:
%function [C] = Q2(image,watermark)
clc;
image=imread('moon.tif');
watermark=imread('cameraman.tif');
[X,Y] = size(image);
rewatermark = imresize(watermark,[X,Y]); % resizing watermark to fit image
% iterate the 3 LSB of the watermark and set them to a copy of the original
% image 3 LSB
C = image;
for i = 1:X
for j = 1:Y
for k = 1:3
b = bitget(rewatermark(i,j), k+5); % Use the high bits 6,7,8 (instead of lower bits 1,2,3 that are mainly "noise")
C(i, j) = bitset(C(i, j), k, b); % Set bit k to the value of b (1 or 0)
%if(bitget(rewatermark(i,j),k) == 1)
% bitset(C(i,j),k,1);
%else
% bitset(C(i,j),k,0);
%end
end
end
end
subplot(1,3,1)
imshow(image);
title('Original');
subplot(1,3,2);
imshow(rewatermark)
title('Watermark');
subplot(1,3,3)
imshow(C)
title('Invisble watermarked');
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
set(gcf,'name','Q2 - Results','numbertitle','off')
reconstructed_rewatermark = bitshift(C, 5);
imshow(reconstructed_rewatermark);title('reconstructed_rewatermark');
我需要在不使用 MATLAB 中现有函数的情况下实现 3 LSB 水印。
我需要我的函数来获取 2 个图像,包括灰度级图像和使用 3 LSB 的预成型水印。
我尝试了以下方法,但是从新图像中减去原始图像的结果全为零,这意味着它们是相同的。
function [C] = Q2(image,watermark)
% clc;
% image=imread('moon.tif');
% watermark=imread('cameraman.tif');
[X,Y] = size(image);
rewatermark = imresize(watermark,[X,Y]); % resizing watermark to fit image
% iterate the 3 LSB of the watermark and set them to a copy of the original
% image 3 LSB
C = image;
for i = 1:X
for j = 1:Y
for k = 1:3
if(bitget(rewatermark(i,j),k) == 1)
bitset(C(i,j),k,1);
else
bitset(C(i,j),k,0);
end
end
end
end
subplot(1,3,1)
imshow(image);
title('Original');
subplot(1,3,2);
imshow(rewatermark)
title('Watermark');
subplot(1,3,3)
imshow(C)
title('Invisble watermarked');
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
set(gcf,'name','Q2 - Results','numbertitle','off')
而不是 bitset(C(i,j),k,1)
,使用:C(i,j) = bitset(C(i,j),k,1)
除了 OOP 编程,MATLAB 不支持引用(或指针)。
执行bitset(C(i,j),k,1)
,并不修改C(i,j)
的内容,而是将相关位设置为1,return修改后的值。
注:
我建议起诉 rewatermark
的高位(位 6、7、8),而不是主要是“噪声”的低位 1、2、3(但这取决于您的目标)。
这是一个代码示例:
%function [C] = Q2(image,watermark)
clc;
image=imread('moon.tif');
watermark=imread('cameraman.tif');
[X,Y] = size(image);
rewatermark = imresize(watermark,[X,Y]); % resizing watermark to fit image
% iterate the 3 LSB of the watermark and set them to a copy of the original
% image 3 LSB
C = image;
for i = 1:X
for j = 1:Y
for k = 1:3
b = bitget(rewatermark(i,j), k+5); % Use the high bits 6,7,8 (instead of lower bits 1,2,3 that are mainly "noise")
C(i, j) = bitset(C(i, j), k, b); % Set bit k to the value of b (1 or 0)
%if(bitget(rewatermark(i,j),k) == 1)
% bitset(C(i,j),k,1);
%else
% bitset(C(i,j),k,0);
%end
end
end
end
subplot(1,3,1)
imshow(image);
title('Original');
subplot(1,3,2);
imshow(rewatermark)
title('Watermark');
subplot(1,3,3)
imshow(C)
title('Invisble watermarked');
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
set(gcf,'name','Q2 - Results','numbertitle','off')
reconstructed_rewatermark = bitshift(C, 5);
imshow(reconstructed_rewatermark);title('reconstructed_rewatermark');