资源简介

LSB匹配图像隐写代码,用matlab实现的,方便初学者学习。

资源截图

代码片段和文件信息

close all
clear all;


% read in the cover object
file_name=‘lena512.bmp‘;
[cover_objectmap]=imread(file_name);
% figure;
% imshow(cover_object);

% read in the secret image
file_name=‘pepper.bmp‘;
[secretmap1]=imread(file_name);
%灰度化
secret = rgb2gray(secret);

% figure;
% imshow(secret);
% convert to double for normalization then back again
% secret=double(secret);
% secret=fix(secret./2);    %rounds the elements of A toward zero resulting in an array of integers
% secret=uint8(secret);
% figure;
% imshow(secretmap1);
% determine size of cover object
Mc=size(cover_object1);    %Height
Nc=size(cover_object2);    %Width

% determine size of secret object
Mm=size(secret1);            %Height
Nm=size(secret2);            %Width

% generate an i.i.d. random variable with uniform distribution on {-1 +1}
k = rand(MmNm);
for i=1:Mm
    for j=1:Nm
        if (k(ij)>=0.5)
            k(ij)=1;
        else
            k(ij) = -1;
        end
    end
end
% title the secret object out to cover object size to generate watermark
%实质为二值化!
for ii = 1:Mc
    for jj = 1:Nc
        if (secret(iijj)>70)
            watermark(iijj)=255;
        else
            watermark(iijj)=0;
        end
    end
end
figure;
imshow(watermark);
title(‘水印图片‘);
% now we set the lsb of cover_object(iijj) to the value of watermark(iijj)
watermarked_image=cover_object;
for ii = 1:Mc
    for jj = 1:Nc
        if (bitget(uint8(watermark(iijj))1)==bitget(cover_object(iijj)1))
            watermarked_image(iijj)=cover_object(iijj);  %Set bit at certain position
        else if(watermark(iijj)==0 || k(iijj)>0)
            %watermarked_image(iijj)=bitset(watermarked_image(iijj)10);
            watermarked_image(iijj) = watermarked_image(iijj) +1;
             else if (watermark(iijj)==255 || k(iijj)<0)
                     %watermarked_image(iijj)=bitset(watermarked_image(iijj)11);
                     watermarked_image(iijj) = watermarked_image(iijj) -1;
                 end
             end
        end
    end
end
%==================================Extraction=================================================== 
% determine size of watermarked image 
Mw=size(watermarked_image1); %Height 
Nw=size(watermarked_image2); %Width 
 
% use lsb of watermarked image to recover watermark 
for ii = 1:Mw 
    for jj = 1:Nw 
        RecoveryWatermark(iijj)=bitget(watermarked_image(iijj)1); 
    end 
end 
%RecoveryWatermark=200*double(RecoveryWatermark); 
for ii = 1:Mc
    for jj = 1:Nc
        if (RecoveryWatermark(iijj)== 1)
            RecoveryWatermark(iijj)=255;
        end
    end
end
figure;
imshow(RecoveryWatermark);
title(‘恢复的水印图片‘);

% write the watermarked image out to a file
imwrite(watermarked_image‘lsbpp_watermarked.bmp‘‘bmp‘);
figure;
subplot(121)
imshow(watermarked_image)
title(‘隐秘图像‘)
subplot(122)
c=imread(‘lena512.bmp‘);
imshow(c)

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        3042  2011-04-23 21:44  LSB_Matching.m
     文件         389  2011-04-23 02:28  PSNR.m
     文件      263222  2010-05-19 22:45  lena512.bmp
     文件      786486  2010-05-19 22:51  pepper.bmp

评论

共有 条评论