本文主要是介绍视频的帧内置乱及逆置乱,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
置乱
%特定帧的帧内置乱
%程序开发: lilizong@gmail.com
%2013-9-19
clc;
clear all;
aviobj=avifile('myAVI\myAVI');
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*nShortl(i)=1-2*l(i-1)*l(i-1);
end
[lsort,lindex]=sort(l);
%产生第2个混沌序列
l(1)=0.99;
for i=2:m*nShortl(i)=1-2*l(i-1)*l(i-1);
end
[lsort,lindex2]=sort(l);
%产生第3个混沌序列
l(1)=0.92;
for i=2:m*nShortl(i)=1-2*l(i-1)*l(i-1);
end
[lsort,lindex3]=sort(l);
% b1=ones(m,n,3);
% b3=b1;
begin=5; %开始置乱的帧数
myEnd=10; %结束置乱的帧数
for i=1:begin-1b=read(mov,i);aviobj=addframe(aviobj,b);
end
%%%%%%%%%%%%%%%置乱
for i=begin:myEnd %将特定帧置乱b=read(mov,i);%彩色图像中的R层b1=reshape(b(:,:,1),1,m*nShort);for k=1:m*nShortb2(k)=b1(lindex(k));endb3(:,:,1)=reshape(b2,m,nShort);%彩色图像中的G层b1=reshape(b(:,:,2),1,m*nShort);for k=1:m*nShortb2(k)=b1(lindex2(k));endb3(:,:,2)=reshape(b2,m,nShort);%彩色图像中的B层置乱b1=reshape(b(:,:,3),1,m*nShort);for k=1:m*nShortb2(k)=b1(lindex3(k));endb3(:,:,3)=reshape(b2,m,nShort);% b2=reshape(b1,m,n);aviobj=addframe(aviobj,b3);
end
%%%%%%%%%%%%%%%置乱
for i=myEnd+1:mov.numberofframesb=read(mov,i);aviobj=addframe(aviobj,b);
end
aviobj=close(aviobj);
mplay('myAVI\myAVI.avi');
逆置乱:
%特定帧的帧内逆置乱
%程序开发: lilizong@gmail.com
%2013-9-19
clc;
clear all;
aviobj=avifile('myAVI\myAVI');
aviobj.Quality=100;
aviobj.compression='None';
mov=mmreader('aviVideo\myAVI.avi'); %用mmreader读入视频文件 50帧
mySize=read(mov,1);
[m n]=size(mySize);
nShort=n/3; %彩色图像的其中一帧
%产生混沌序列
%产生第一个混沌序列
l=linspace(0,0,m*nShort);
l(1)=0.98;
for i=2:m*nShortl(i)=1-2*l(i-1)*l(i-1);
end
[lsort,lindex]=sort(l);
[lsort,invertlindex]=sort(lindex);
%产生第2个混沌序列
l(1)=0.99;
for i=2:m*nShortl(i)=1-2*l(i-1)*l(i-1);
end
[lsort,lindex2]=sort(l);
[lsort,invertlindex2]=sort(lindex2);
%产生第3个混沌序列
l(1)=0.92;
for i=2:m*nShortl(i)=1-2*l(i-1)*l(i-1);
end
[lsort,lindex3]=sort(l);
[lsort,invertlindex3]=sort(lindex3);
% b1=ones(m,n,3);
% b3=b1;
begin=5; %开始置乱的帧数
myEnd=10; %结束置乱的帧数
for i=1:begin-1b=read(mov,i);aviobj=addframe(aviobj,b);
end
%%%%%%%%%%%%%%%置乱
for i=begin:myEnd %将特定帧置乱b=read(mov,i);%彩色图像中的R层b1=reshape(b(:,:,1),1,m*nShort);for k=1:m*nShortb2(k)=b1(invertlindex(k));endb3(:,:,1)=reshape(b2,m,nShort);%彩色图像中的G层b1=reshape(b(:,:,2),1,m*nShort);for k=1:m*nShortb2(k)=b1(invertlindex2(k));endb3(:,:,2)=reshape(b2,m,nShort);%彩色图像中的B层置乱b1=reshape(b(:,:,3),1,m*nShort);for k=1:m*nShortb2(k)=b1(invertlindex3(k));endb3(:,:,3)=reshape(b2,m,nShort);% b2=reshape(b1,m,n);aviobj=addframe(aviobj,b3);
end
%%%%%%%%%%%%%%%置乱
for i=myEnd+1:mov.numberofframesb=read(mov,i);aviobj=addframe(aviobj,b);
end
aviobj=close(aviobj);
mplay('myAVI\myAVI.avi');
这篇关于视频的帧内置乱及逆置乱的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!