Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

视频帧异或

$
0
0

视频帧内异或,针对视频帧内的某些帧,在其帧内进行异或,

使用混沌图像,跟帧的高位(第8位)进行异或。

异或过程:

%特定帧的帧内异或
%程序开发: lilizong@gmail.com
%2013-9-19
clc;
clear all;
aviobj=avifile('aviVideo\myAVIXor');
aviobj.Quality=100;
aviobj.compression='None';
mov=mmreader('aviVideo\vipfly.avi');     %用mmreader读入视频文件  50帧
mySize=read(mov,1);
[m n]=size(mySize);
nShort=n/3;    %彩色图像的其中一帧
%产生混沌序列
%产生第1个混沌序列
l=linspace(0,0,m*nShort);
l(1)=0.98;
for i=2:m*nShort
    l(i)=1-2*l(i-1)*l(i-1);
end
%转为二进制只包含0和1
for i=1:m*nShort
    if l(i)>0
        l(i)=1;
    else
        l(i)=0;
    end
end
cs1=reshape(l,m,nShort);%chaotic system1
%产生第2个混沌序列
l(1)=0.99;
for i=2:m*nShort
    l(i)=1-2*l(i-1)*l(i-1);
end
%转为二进制只包含0和1
for i=1:m*nShort
    if l(i)>0
        l(i)=1;
    else
        l(i)=0;
    end
end
cs2=reshape(l,m,nShort);%chaotic system2
%产生第3个混沌序列
l(1)=0.92;
for i=2:m*nShort
    l(i)=1-2*l(i-1)*l(i-1);
end
%转为二进制只包含0和1
for i=1:m*nShort
    if l(i)>0
        l(i)=1;
    else
        l(i)=0;
    end
end
cs3=reshape(l,m,nShort);  %chaotic system3
% b1=ones(m,n,3);
% b3=b1;
begin=5;  %开始置乱的帧数
myEnd=10;   %结束置乱的帧数
for i=1:begin-1
    b=read(mov,i);
    aviobj=addframe(aviobj,b);
end
%%%%%%%%%%%%%%%异或
for i=begin:myEnd       %将特定帧内异或
    b=read(mov,i);
    cs(:,:,1)=cs1;
    cs(:,:,2)=cs2;
    cs(:,:,3)=cs3;
    %         result=xor(b,cs);
    t=bitget(b,8);
    temp1=xor(cs,t);   
    result=bitset(b,8,temp1);
    %     result=ones(240,320,3);
    aviobj=addframe(aviobj,result);
end
%%%%%%%%%%%%%%%置乱
for i=myEnd+1:mov.numberofframes
    b=read(mov,i);
    aviobj=addframe(aviobj,b);
end
aviobj=close(aviobj);
mplay('aviVideo\myAVIXor.avi');

逆异或过程,与异或过程一致,仅仅选取的初始文件有差异而已:

%特定帧的帧内逆异或
%程序开发: lilizong@gmail.com
%2013-9-19
clc;
clear all;
aviobj=avifile('myAVI\myAVIXor');
aviobj.Quality=100;
aviobj.compression='None';
mov=mmreader('aviVideo\myAVIXor.avi');     %用mmreader读入视频文件  50帧
mySize=read(mov,1);
[m n]=size(mySize);
nShort=n/3;    %彩色图像的其中一帧
%产生混沌序列
%产生第1个混沌序列
l=linspace(0,0,m*nShort);
l(1)=0.98;
for i=2:m*nShort
    l(i)=1-2*l(i-1)*l(i-1);
end
%转为二进制只包含0和1
for i=1:m*nShort
    if l(i)>0
        l(i)=1;
    else
        l(i)=0;
    end
end
cs1=reshape(l,m,nShort);%chaotic system1
%产生第2个混沌序列
l(1)=0.99;
for i=2:m*nShort
    l(i)=1-2*l(i-1)*l(i-1);
end
%转为二进制只包含0和1
for i=1:m*nShort
    if l(i)>0
        l(i)=1;
    else
        l(i)=0;
    end
end
cs2=reshape(l,m,nShort);%chaotic system2
%产生第3个混沌序列
l(1)=0.92;
for i=2:m*nShort
    l(i)=1-2*l(i-1)*l(i-1);
end
%转为二进制只包含0和1
for i=1:m*nShort
    if l(i)>0
        l(i)=1;
    else
        l(i)=0;
    end
end
cs3=reshape(l,m,nShort);  %chaotic system3
% b1=ones(m,n,3);
% b3=b1;
begin=5;  %开始置乱的帧数
myEnd=10;   %结束置乱的帧数
for i=1:begin-1
    b=read(mov,i);
    aviobj=addframe(aviobj,b);
end
%%%%%%%%%%%%%%%异或
for i=begin:myEnd       %将特定帧内异或
    b=read(mov,i);
    cs(:,:,1)=cs1;
    cs(:,:,2)=cs2;
    cs(:,:,3)=cs3;
    %         result=xor(b,cs);
    t=bitget(b,8);
    temp1=xor(cs,t);   
    result=bitset(b,8,temp1);
    %     result=ones(240,320,3);
    aviobj=addframe(aviobj,result);
end
%%%%%%%%%%%%%%%置乱
for i=myEnd+1:mov.numberofframes
    b=read(mov,i);
    aviobj=addframe(aviobj,b);
end
aviobj=close(aviobj);
mplay('myAVI\myAVIXor.avi');



作者:superdont 发表于2013-9-19 12:51:11 原文链接
阅读:81 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>