资源简介

这是华中科技大学数字图像处理的大实验,用小波变换的方法进行数字盲水印的添加和提取,采用Matlab实现

资源截图

代码片段和文件信息

clear;
clc;
close all;

figure(1);

% read original picture
input=imread(‘image.jpg‘);
imshow(input);
title(‘original pic‘);

% read watermark
figure(2);
water=imread(‘watermark.jpg‘);
imshow(water);
title(‘watermark‘);

% seperate RGB
input=double(input);
water=double(water);
inputr=input(::1);
waterr=water(::1);
inputg=input(::2);
waterg=water(::2);
inputb=input(::3);
waterb=water(::3);

% more robust when r is big more transparent the opposite
r=0.04;

% decomposite watermark R
[CwrSwr]=wavedec2(waterr1‘haar‘);

% decomposite the original pic R
[CrSr]=wavedec2(inputr2‘haar‘);

% add watermark
Cr(1:size(Cwr2)/16)=...
    Cr(1:size(Cwr2)/16)+r*Cwr(1:size(Cwr2)/16);
k=0;
while k<=size(Cr2)/size(Cwr2)-1
    Cr(1+size(Cr2)/4+k*size(Cwr2)/4:size(Cr2)/4+...
        (k+1)*size(Cwr2)/4)=Cr(1+size(Cr2)/4+...
        k*size(Cwr2)/4:size(Cr2)/4+(k+1)*size(Cwr2)/4)+...
        r*Cwr(1+size(Cwr2)/4:size(Cwr2)/2);
    Cr(1+size(Cr2)/2+k*size(Cwr2)/4:size(Cr2)/2+...
        (k+1)*size(Cwr2)/4)=Cr(1+size(Cr2)/2+...
        k*size(Cwr2)/4:size(Cr2)/2+(k+1)*size(Cwr2)/4)+...
        r*Cwr(1+size(Cwr2)/2:3*size(Cwr2)/4);
    Cr(1+3*size(Cwr2)/4+k*size(Cwr2)/4:3*size(Cwr2)/4+...
        (k+1)*size(Cwr2)/4)=Cr(1+3*size(Cr2)/4+...
        k*size(Cwr2)/4:3*size(Cr2)/4+(k+1)*size(Cwr2)/4)+...
        r*Cwr(1+3*size(Cwr2)/4:size(Cwr2));
    k=k+1;
end;
Cr(1:size(Cwr2)/4)=Cr(1:size(Cwr2)/4)+r*Cwr(1:size(Cwr2)/4);

g=0.02;
% decomposite watermark G
[CwgSwg]=wavedec2(waterg1‘haar‘);
% decomposite original pic G
[CgSg]=wavedec2(inputg2‘haar‘);
% add watermark
Cg(1:size(Cwg2)/16)=...
    Cg(1:size(Cwg2)/16)+g*Cwg(1:size(Cwg2)/16);
k=0;
while k<=size(Cg2)/size(Cwg2)-1
    Cg(1+size(Cg2)/4+k*size(Cwg2)/4:size(Cg2)/4+...
        (k+1)*size(Cwg2)/4)=Cg(1+size(Cg2)/4+...
        k*size(Cwg2)/4:size(Cg2)/4+(k+1)*size(Cwg2)/4)+...
        g*Cwg(1+size(Cwg2)/4:size(Cwg2)/2);
    Cg(1+size(Cg2)/2+k*size(Cwg2)/4:size(Cg2)/2+...
        (k+1)*size(Cwg2)/4)=Cg(1+size(Cg2)/2+...
        k*size(Cwg2)/4:size(Cg2)/2+(k+1)*size(Cwg2)/4)+...
        g*Cwg(1+size(Cwg2)/2:3*size(Cwg2)/4);
    Cg(1+3*size(Cg2)/4+k*size(Cwg2)/4:3*size(Cg2)/4+...
        (k+1)*size(Cwg2)/4)=Cg(1+3*size(Cg2)/4+...
        k*size(Cwg2)/4:3*size(Cg2)/4+(k+1)*size(Cwg2)/4)+...
        g*Cwg(1+3*size(Cwg2)/4:size(Cwg2));
    k=k+1;
end;
Cg(1:size(Cwg2)/4)=Cg(1:size(Cwg2)/4)+g*Cwg(1:size(Cwg2)/4);

b=0.16;
% B
[CwbSwb]=wavedec2(waterb1‘haar‘);
% B
[CbSb]=wavedec2(inputb2‘haar‘);
% add watermark
Cb(1:size(Cwb2)/16)+b*Cwb(1:size(Cwb2)/16);
k=0;
while k<=size(Cb2)/size(Cwb2)-1
    Cb(1+size(Cb2)/4+k*size(Cwb2)/4:size(Cb2)/4+...
        (k+1)*size(Cwb2)/4)=Cb(1+size(Cb2)/4+...
        k*size(Cwb2)/4:size(Cb2)/4+(k+1)*size(Cwb2)/4)+...
        g*Cwb(1+size(Cwb2)/4:size(Cwb2)/2);
    Cb(1+size(Cb2)/2+k*size(Cwb

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-05-09 20:36  csdn1\
     文件       10478  2018-05-09 20:36  csdn1\watermark.jpg
     目录           0  2018-05-09 20:39  __MACOSX\
     目录           0  2018-05-09 20:39  __MACOSX\csdn1\
     文件         172  2018-05-09 20:36  __MACOSX\csdn1\._watermark.jpg
     文件        4608  2018-04-30 11:00  csdn1\extract_watermark.m
     文件         369  2018-04-30 11:00  __MACOSX\csdn1\._extract_watermark.m
     文件        3995  2018-04-30 11:04  csdn1\add_watermark.m
     文件         369  2018-04-30 11:04  __MACOSX\csdn1\._add_watermark.m
     文件        6148  2018-05-09 20:32  csdn1\.DS_Store
     文件         120  2018-05-09 20:32  __MACOSX\csdn1\._.DS_Store
     文件       23041  2018-05-09 20:36  csdn1\extracted.jpg
     文件       34843  2018-05-09 20:36  csdn1\watermarked.jpg
     文件       34940  2018-05-09 20:35  csdn1\image.jpg
     文件         228  2018-05-09 20:35  __MACOSX\csdn1\._image.jpg
     文件         212  2018-05-09 20:36  __MACOSX\._csdn1

评论

共有 条评论