# 基于小波变换的双彩色数字水印算法

xiaoxiao2021-02-28  21

function [MarkedImg] = Hide_3(OriImg,Print) % 功能 将Print中的携带的信息通过图像处理技术隐藏在OriImg中 % OriImg 输入参数，RGB彩色图像，uint8格式，大小为512*512*3，作为隐 % 藏信息的载体 % Print 输入参数，RGB彩色图像，uint8格式，大小为140*200*3，信息本 % 身所在 % MarkedImg 输出参数，RGB彩色图像，uint8格式，大小为512*512*3，经过 % 信息隐藏处理后的图像 %OriImg = imread('I2.jpg'); %Print = imread('m5.jpg'); OriImg = rgb2hsv(OriImg); vlayer = OriImg(:,:,3); vvalue = sum(sum(vlayer)); if vvalue > 2e5 alpha = 0.04; elseif vvalue<1.5e5 alpha = 0.1; else alpha = 0.2; end MarkedImg = zeros(size(OriImg)); for i=1:3 Orilayer = OriImg(:,:,i); Printlayer = Print(:,:,i); Printlayer = (double(Printlayer)-128)/128; %归一到-1~1 [C,S] = wavedec2(Orilayer,1,'db2'); [rows, cols] = size(Printlayer); totallength = rows*cols; cA1 = appcoef2(C,S,'db2',1); [cA1_r, cA1_c] = size(cA1); part1length = cA1_r*cA1_c; cA1 = C(1:part1length); [~, IA] = sort(abs(cA1),'descend'); IA = IA(1:totallength); flattenpri = reshape(Printlayer, 1, []); C(IA) = C(IA)+alpha*flattenpri; Outlayer = waverec2(C,S,'db2'); MarkedImg(:,:,i) = Outlayer; end Imgout = hsv2rgb(MarkedImg); MarkedImg = im2uint8(Imgout); imshow(MarkedImg); end function [Print] = Recover_3(MarkedImg, Rect, OriImg) rec_row = Rect(2,1); rec_col = Rect(2,2); %OriImg = imread('I2.jpg'); OriImg = rgb2hsv(OriImg); %MarkedImg = imread('testhid1.jpg'); MarkedImg = rgb2hsv(MarkedImg); Print = zeros(rec_row, rec_col, 3); vlayer = OriImg(:,:,3); vvalue = sum(sum(vlayer)); if vvalue > 2e5 alpha = 0.04; elseif vvalue<1.5e5 alpha = 0.1; else alpha = 0.2; end for i=1:3 Orilayer = OriImg(:,:,i); Marklayer = MarkedImg(:,:,i); [Co,So] = wavedec2(Orilayer,1,'db2'); coA1 = appcoef2(Co,So,'db2',1); [cA1_r, cA1_c] = size(coA1); part1length = cA1_r*cA1_c; coA1 = Co(1:part1length); [~, IAo] = sort(abs(coA1),'descend'); IAo = IAo(1:rec_row*rec_col); [Cm,~] = wavedec2(Marklayer,1,'db2'); cmA1 = Cm(1:part1length); flat_print = cmA1(IAo)-coA1(IAo); Print_layer = reshape(flat_print, rec_row, rec_col)/alpha; Print_layer = (Print_layer*128)+128; Print(:,:,i) = Print_layer; end Print = uint8(Print); figure(2) imshow(Print); end 实现效果：

OriImg