修改最大像素值的可逆数字算法的实现

论文的算法,继续与大家分享

修改最大像素值的可逆数字算法的实现

%designed by 李立宗

%[email protected]

%t4311.m

c=imread('e:\lena.bmp');

subplot(1,3,1),imshow(c),title('嵌入水印前图像');

[m,n]=size(c);

dix=zeros(255);

for i=1:512

for j=1:512

for k=1:255

if c(i,j)==k

dix(k)=dix(k)+1;

end

end

end

end

% subplot(3,3,2),plot(dix);

max=dix(1);

for i=1:255

if max<dix(i)

max=dix(i);

maxi=i;

end

end

max

c1=c;

for i=1:512

for j=1:512

if c(i,j)<maxi

c1(i,j)=c(i,j)-1;

else

c1(i,j)=c(i,j);

end

end

end

dix2=zeros(255);

for i=1:512

for j=1:512

for k=1:255

if c1(i,j)==k

dix2(k)=dix2(k)+1;

end

end

end

end

% subplot(3,3,3),plot(dix2);

% subplot(3,3,4),plot(dix,'r'),hold on,plot(dix2,'g:');

mark=imread('e:\logo1.bmp');

mark=im2bw(mark);

subplot(1,3,2),imshow(mark),title('水印图像');

%读入水印图像,并将之二值化处理

% figure,imshow(mark),title('水印图像');

mark1=zeros(1,1600);

n=1;

for i=1:40

for j=1:40

mark1(n)=mark(i,j);

n=n+1;

end

end

% mark1=reshape(mark,1,1600);

%测试mark1的正确与否

% n=1;

% for i=1:40

% for j=1:40

% mark2(i,j)=mark1(n);

% n=n+1;

% end

% end

% subplot(1,3,3),imshow(mark2),title('水印图像');

c2=zeros(512,512);

c2=c1;

n=0;

for i=1:512

for j=1:512

if c2(i,j)==maxi

n=n+1;

if(n==1600)

n=1;

end

if mark1(n)==1

c2(i,j)=c2(i,j)-1;

end

end

end

end

% n=1;

% for i=1:512

% for j=1:512

% ifc2(i,j)==maxi && mark1(n)==1

% c2(i,j)=c2(i,j)-1;

% n=n+1;

%

% end

% end

% end

subplot(1,3,3),imshow(c2),title('嵌入水印后图像');

markshow=zeros(1,5000);

%分配一个大数组,这样可以存储冗余量

n=1;

for i=1:512

for j=1:512

if c2(i,j)==maxi

markshow(n)=0;

n=n+1;

elseif c2(i,j)==(maxi-1)

markshow(n)=1;

n=n+1;

end

end

end

markshow;

markshow1=zeros(40,40);

%定义一个数组,用来存储恢复的水印

n=1;

for i=1:40

for j=1:40

markshow1(i,j)=markshow(n);

n=n+1;

end

end

% subplot(1,3,3),imshow(markshow1),title('恢复水印图像');

c3=c2;

for i=1:512

for j=1:512

if c2(i,j)<maxi

c3(i,j)=c2(i,j)+1;

else

c3(i,j)=c2(i,j);

end

end

end

% subplot(1,3,3),imshow(c3),title('恢复原始载体图像');

你可能感兴趣的:(C++,c,算法,C#,J#)