余3循环码码matlab代码含义

LBP算法的Matlab代码 - 博客频道 - CSDN.NET
kuaitoukid的专栏
Fight For Free!
分类:模式识别
说明:一共有三个m文件,一个是lbp.m, 存放主要的lbp算法,一个是getmapping,用以做算法的辅助函数,一个是lbptest.m,存放着测试代码。这三个文件需要放到同一个文件夹,并在文件夹中添加相应的图片,具体的图片名字见lbptest.m的代码,运行lbptest.m可以查看结果。代码最后给出效果图
%LBP returns the local binary pattern image or LBP histogram of an image.
% &J = LBP(I,R,N,MAPPING,MODE) returns either a local binary pattern
% &coded image or the local binary pattern histogram of an intensity
% &image I. The LBP codes are computed using N sampling points on a
% &circle of radius R and using mapping table defined by MAPPING.
% &See the getmapping function for different mappings and use 0 for
% &no mapping. Possible values for MODE are
% & & & 'h' or 'hist' &to get a histogram of LBP codes
% & & & 'nh' & & & & & to get a normalized histogram
% &Otherwise an LBP code image is returned.
% &J = LBP(I) returns the original (basic) LBP histogram of image I
% &J = LBP(I,SP,MAPPING,MODE) computes the LBP codes using n sampling
% &points defined in (n * 2) matrix SP. The sampling points should be
% &defined around the origin (coordinates (0,0)).
% &Examples
% &--------
% & & & I=imread('rice.png');
% & & & mapping=getmapping(8,'u2');
% & & & H1=LBP(I,1,8,mapping,'h'); %LBP histogram in (8,1) neighborhood
% & & & & & & & & & & & & & & & & &%using uniform patterns
% & & & subplot(2,1,1),stem(H1);
% & & & H2=LBP(I);
% & & & subplot(2,1,2),stem(H2);
% & & & SP=[-1 -1; -1 0; -1 1; 0 -1; -0 1; 1 -1; 1 0; 1 1];
% & & & I2=LBP(I,SP,0,'i'); %LBP code image using sampling points in SP
% & & & & & & & & & & & & & %and no mapping. Now H2 is equal to histogram
% & & & & & & & & & & & & & %of I2.
function result = lbp(varargin) % image,radius,neighbors,mapping,mode)
% Version 0.3.2
% Authors: Marko Heikkil?and Timo Ahonen
% Changelog
% Version 0.3.2: A bug fix to enable using mappings together with a
% predefined spoints array
% Version 0.3.1: Changed MAPPING input to be a struct containing the mapping
% table and the number of bins to make the function run faster with high number
% of sampling points. Lauge Sorensen is acknowledged for spotting this problem.
% Check number of input arguments.
error(nargchk(1,5,nargin));
image=varargin{1};
d_image=double(image);
if nargin==1
& & spoints=[-1 -1; -1 0; -1 1; 0 -1; -0 1; 1 -1; 1 0; 1 1];
& & neighbors=8;
& & mapping=0;
& & mode='h';
if (nargin == 2) && (length(varargin{2}) == 1)
& & error('Input arguments');
if (nargin & 2) && (length(varargin{2}) == 1)
& & radius=varargin{2};
& & neighbors=varargin{3};
& & spoints=zeros(neighbors,2);
& & % Angle step.
& & a = 2*pi/
& & for i = 1:neighbors
& & & & spoints(i,1) = -radius*sin((i-1)*a);
& & & & spoints(i,2) = radius*cos((i-1)*a);
& & if(nargin &= 4)
& & & & mapping=varargin{4};
& & & & if(isstruct(mapping) && mapping.samples ~= neighbors)
& & & & & & error('Incompatible mapping');
& & & & end
& & & & mapping=0;
& & if(nargin &= 5)
& & & & mode=varargin{5};
& & & & mode='h';
if (nargin & 1) && (length(varargin{2}) & 1)
& & spoints=varargin{2};
& & neighbors=size(spoints,1);
& & if(nargin &= 3)
& & & & mapping=varargin{3};
& & & & if(isstruct(mapping) && mapping.samples ~= neighbors)
& & & & & & error('Incompatible mapping');
& & & & end
& & & & mapping=0;
& & if(nargin &= 4)
& & & & mode=varargin{4};
& & & & mode='h';
% Determine the dimensions of the input image.
[ysize xsize] = size(image);
miny=min(spoints(:,1));
maxy=max(spoints(:,1));
minx=min(spoints(:,2));
maxx=max(spoints(:,2));
% Block size, each LBP code is computed within a block of size bsizey*bsizex
bsizey=ceil(max(maxy,0))-floor(min(miny,0))+1;
bsizex=ceil(max(maxx,0))-floor(min(minx,0))+1;
% Coordinates of origin (0,0) in the block
origy=1-floor(min(miny,0));
origx=1-floor(min(minx,0));
% Minimum allowed size for the input image depends
% on the radius of the used LBP operator.
if(xsize & bsizex || ysize & bsizey)
& error('Too small input image. Should be at least (2*radius+1) x (2*radius+1)');
dx = xsize -
dy = ysize -
% Fill the center pixel matrix C.
C = image(origy:origy+dy,origx:origx+dx);
d_C = double(C);
% Initialize the result matrix with zeros.
result=zeros(dy+1,dx+1);
%Compute the LBP code image
for i = 1:neighbors
& y = spoints(i,1)+
& x = spoints(i,2)+
& % Calculate floors, ceils and rounds for the x and y.
& fy = floor(y); cy = ceil(y); ry = round(y);
& fx = floor(x); cx = ceil(x); rx = round(x);
& % Check if interpolation is needed.
& if (abs(x - rx) & 1e-6) && (abs(y - ry) & 1e-6)
& & % Interpolation is not needed, use original datatypes
& & N = image(ry:ry+dy,rx:rx+dx);
& & D = N &= C;
& & % Interpolation needed, use double type images
& & ty = y -
& & tx = x -
& & % Calculate the interpolation weights.
& & w1 = (1 - tx) * (1 - ty);
& & w2 = & & &tx &* (1 - ty);
& & w3 = (1 - tx) * & & &
& & w4 = & & &tx &* & & &
& & % Compute interpolated pixel values
& & N = w1*d_image(fy:fy+dy,fx:fx+dx) + w2*d_image(fy:fy+dy,cx:cx+dx) + ...
& & & & w3*d_image(cy:cy+dy,fx:fx+dx) + w4*d_image(cy:cy+dy,cx:cx+dx);
& & D = N &= d_C;
& % Update the result matrix.
& v = 2^(i-1);
& result = result + v*D;
%Apply mapping if it is defined
if isstruct(mapping)
& & bins = mapping.
& & for i = 1:size(result,1)
& & & & for j = 1:size(result,2)
& & & & & & result(i,j) = mapping.table(result(i,j)+1);
& & & & end
if (strcmp(mode,'h') || strcmp(mode,'hist') || strcmp(mode,'nh'))
& & % Return with LBP histogram if mode equals 'hist'.
& & result=hist(result(:),0:(bins-1));
& & if (strcmp(mode,'nh'))
& & & & result=result/sum(result);
& & %Otherwise return a matrix of unsigned integers
& & if ((bins-1)&=intmax('uint8'))
& & & & result=uint8(result);
& & elseif ((bins-1)&=intmax('uint16'))
& & & & result=uint16(result);
& & & & result=uint32(result);
getmapping.m
% GETMAPPING returns a structure containing a mapping table for LBP codes.
% &MAPPING = GETMAPPING(SAMPLES,MAPPINGTYPE) returns a
% &structure containing a mapping table for
% &LBP codes in a neighbourhood of SAMPLES sampling
% &points. Possible values for MAPPINGTYPE are
% & & & 'u2' & for uniform LBP
% & & & 'ri' & for rotation-invariant LBP
% & & & 'riu2' for uniform rotation-invariant LBP.
% &Example:
% & & & I=imread('rice.tif');
% & & & MAPPING=getmapping(16,'riu2');
% & & & LBPHIST=lbp(I,2,16,MAPPING,'hist');
% &Now LBPHIST contains a rotation-invariant uniform LBP
% &histogram in a (16,2) neighbourhood.
function mapping = getmapping(samples,mappingtype)
% Version 0.1.1
% Authors: Marko Heikkil?and Timo Ahonen
% Changelog
% 0.1.1 Changed output to be a structure
% Fixed a bug causing out of memory errors when generating rotation
% invariant mappings with high number of sampling points.
% Lauge Sorensen is acknowledged for spotting this problem.
table = 0:2^samples-1;
newMax &= 0; %number of patterns in the resulting LBP code
index & = 0;
if strcmp(mappingtype,'u2') %Uniform 2
& newMax = samples*(samples-1) + 3;
& for i = 0:2^samples-1
& & j = bitset(bitshift(i,1,samples),1,bitget(i,samples)); %rotate left
& & numt = sum(bitget(bitxor(i,j),1:samples)); %number of 1-&0 and
& & & & & & & & & & & & & & & & & & & & & & & &%0-&1 transitions
& & & & & & & & & & & & & & & & & & & & & & & &%in binary string
& & & & & & & & & & & & & & & & & & & & & & & &%x is equal to the
& & & & & & & & & & & & & & & & & & & & & & & &%number of 1-bits in
& & & & & & & & & & & & & & & & & & & & & & & &%XOR(x,Rotate left(x))
& & if numt &= 2
& & & table(i+1) =
& & & index = index + 1;
& & & table(i+1) = newMax - 1;
if strcmp(mappingtype,'ri') %Rotation invariant
& tmpMap = zeros(2^samples,1) - 1;
& for i = 0:2^samples-1
& & for j = 1:samples-1
& & & r = bitset(bitshift(r,1,samples),1,bitget(r,samples)); %rotate
& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & &%left
& & & if r & rm
& & & & rm =
& & if tmpMap(rm+1) & 0
& & & tmpMap(rm+1) = newM
& & & newMax = newMax + 1;
& & table(i+1) = tmpMap(rm+1);
if strcmp(mappingtype,'riu2') %Uniform & Rotation invariant
& newMax = samples + 2;
& for i = 0:2^samples - 1
& & j = bitset(bitshift(i,1,samples),1,bitget(i,samples)); %rotate left
& & numt = sum(bitget(bitxor(i,j),1:samples));
& & if numt &= 2
& & & table(i+1) = sum(bitget(i,1:samples));
& & & table(i+1) = samples+1;
mapping.table=
mapping.samples=
mapping.num=newM
%%%%%%%%%%%%%%%%%%%LBP变换后的图像%%%%%%%%%%%%%%%%%%
I11 = imread('test1.bmp');
SP=[-1 -1; -1 0; -1 1; 0 -1; -0 1; 1 -1; 1 0; 1 1];
I12=LBP(I11,SP,0,'i');
I21 = imread('test2.bmp');
SP=[-1 -1; -1 0; -1 1; 0 -1; -0 1; 1 -1; 1 0; 1 1];
I22=LBP(I21,SP,0,'i');
re1 = abs(I22-I12);
% re1 = 255 - re1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I31 = imread('test3.bmp');
SP=[-1 -1; -1 0; -1 1; 0 -1; -0 1; 1 -1; 1 0; 1 1];
I32=LBP(I31,SP,0,'i');
I41 = imread('test4.bmp');
SP=[-1 -1; -1 0; -1 1; 0 -1; -0 1; 1 -1; 1 0; 1 1];
I42=LBP(I41,SP,0,'i');
re2 = abs(I32-I42);
% re2 = 255 - re2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
re3 = abs(I32 - I12);
% re3 = 255 - abs(I32 - I12);
re4 = abs(I32 - I22);
re5 = abs(I42 - I12);
re6 = abs(I42 - I22);
%%%%%%%%%%%%%%%%%%%%%%直方图%%%%%%%%%%%%%%%%%%%%%%%%
mapping=getmapping(8,'u2');
H11=LBP(I11,1,8,mapping,'h'); %LBP histogram in (8,1) neighborhood using uniform patterns
subplot(2,2,1),stem(H11);
H12=LBP(I11);
subplot(2,2,2),stem(H12);
H21=LBP(I21,1,8,mapping,'h'); %LBP histogram in (8,1) neighborhood using uniform patterns
subplot(2,2,3),stem(H21);
H22=LBP(I21);
subplot(2,2,4),stem(H22);
H31=LBP(I31,1,8,mapping,'h'); %LBP histogram in (8,1) neighborhood using uniform patterns
subplot(2,2,3),stem(H31);
H32=LBP(I31);
subplot(2,2,4),stem(H32);
%%%%%%%%%%%%%%%%%%%%%%%无聊瞎写%%%%%%%%%%%%%%%%%%%%%%%%
[row, col] = size(I11);
It1 = ones(row, col);
for i = 2 : col
& & It1(:, i - 1) = abs(I11(:, i) - I11(:, i - 1));
It2 = ones(row, col);
for i = 2 : row
& & It2(i-1,:) = abs(I11(i,:) - I11(i-1,:));
测试结果截图与分析
运行完lbptest后,可以输入imshow(I11)查看第一幅图像的原图,如下(昆虫翅膀)
& & & & & & & &
输入imshow(I12)查看第一幅图像经LBP处理后的图像
输入imshow(re1)查看第一幅与第二幅图像做差值之后的图像,黑色越多,表示两个翅膀越相近
这是原图经过LBP处理之后的比较,lbptest.m后半部分的代码是比较两幅图的直方图,我个人建议用直方图,虽然不如显示原图的方法直观,但却有平移不变性,效果如图:
直方图越相似,代表两幅图像越相近。不过这种方法老让我想起哈希变换与RSA加密……不知道有没有人跟我同感。
kuaitoukid
排名:第13473名
(7)(3)(1)(2)(5)(1)(8)(2)(3)(12)(7)(1)(1)(2)(3)(5)(3)(1)(2)(2)(16)(14)(12)(9)(2)(3)(1)(0)(1)(2)(1)(1)(1)(1)(1)(1)(1)MATLAB代码含义_百度知道
MATLAB代码含义
H_line=line('Xdata',t,'Ydata',sin(t)); %绘制sin(t)的函数曲线,曲线句柄赋值给H_lineH_c=get(get(H_line,'parent'),'children')%返回句柄值H_line所指定的图形对象的'parent(父)'属性的以及对应子属性值赋值给HcT=get(H_c,'Type')%返回句柄值Hc的类型属性值赋值给THb=findobj(gca,'Color','b')%;根据坐标轴找出与对象的颜色属性为黑色对象句柄值赋值给Hbset(gcf,'Menubar','none')%将目前图形的菜单栏设为空axes('Position',get(h_ap,'Position'))%重建坐标轴,位置为句柄h_ap所指向位置
其他类似问题
为您推荐:
% 查找当前坐标系中颜色为蓝色的图形对象(这一句与前面似乎没有什么关联,类型是lineT=get(H_c;% 获取当前坐标系里面有哪些图形对象(line的parent是axes,&#39,sin(t)),'Menubar&#39,如果前面只用了line画过一条曲线,';parent'&);% 设置窗口不显示菜单set(gcf,对于曲线而言、% 获取上一步所得到图形对象的类型,&#39、text等)H_c=get(get(H_;children&#39,这句的意图也不是很清楚)axes('Xdata&#39,有些地方的意图不是很清楚。&nbsp,'Ydata&#39,t,则返回的结果为空)Hb=findobj(Type'Color')&% 在指定位置创建一个坐标系(由于变量h_ap不明,get(h_% 以t为横坐标代码不完整,';; )&b'&nbsp,'Position&#39,但一个axes里面可能还有其它图形对象,&#39,例如)&nbsp,sin(t)为纵坐标画一条曲线H_line=line('none',');Position&#39
matlab的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁循环码编码_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
循环码编码
上传于||暂无简介
阅读已结束,如果下载本文需要使用1下载券
想免费下载本文?
下载文档到电脑,查找使用更方便
还剩25页未读,继续阅读
你可能喜欢&&&&遍历法生成循环码的MATLAB实现
&遍历法生成循环码的MATLAB实现
自己编的(作业),感觉比较适合那些找作业(大学生)的人用。txt格式的
若举报审核通过,可奖励20下载分
被举报人:
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:
VIP下载&&免积分60元/年(1200次)
您可能还需要
Q.为什么我点的下载下不了,但积分却被扣了
A. 由于下载人数众多,下载服务器做了并发的限制。若发现下载不了,请稍后再试,多次下载是不会重复扣分的。
Q.我的积分不多了,如何获取积分?
A. 获得积分,详细见。
完成任务获取积分。
论坛可用分兑换下载积分。
第一次绑定手机,将获得5个C币,C币可。
关注并绑定CSDNID,送10个下载分
下载资源意味着您已经同意遵守以下协议
资源的所有权益归上传用户所有
未经权益所有人同意,不得将资源中的内容挪作商业或盈利用途
CSDN下载频道仅提供交流平台,并不能对任何下载资源负责
下载资源中如有侵权或不适当内容,
本站不保证本站提供的资源的准确性,安全性和完整性,同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
开发技术下载排行
您当前C币:0&&&可兑换 0 下载积分
兑换下载分:&
消耗C币:0&
立即兑换&&
兑换成功你当前的下载分为 。前去下载资源
你下载资源过于频繁,请输入验证码
如何快速获得积分?
你已经下载过该资源,再次下载不需要扣除积分
遍历法生成循环码的MATLAB实现
所需积分:1
剩余积分:0
扫描微信二维码精彩活动、课程更新抢先知
VIP会员,免积分下载
会员到期时间:日
剩余下载次数:1000
遍历法生成循环码的MATLAB实现
剩余次数:&&&&有效期截止到:
你还不是VIP会员VIP会员享免积分 . 专属通道极速下载
VIP下载次数已满VIP会员享免积分 . 专属通道极速下载,请继续开通VIP会员
你的VIP会员已过期VIP会员享免积分 . 专属通道极速下载,请继续开通VIP会员(13,9)循环码的MATLAB语言程序,跪求大神,要能运行的_百度知道
(13,9)循环码的MATLAB语言程序,跪求大神,要能运行的
额- -是仿真的程序
提问者采纳
%制造100个信息组,1; %计算误码率 [number1; disp(['cyclic/
%随机提取信号,'循环码在不同信噪比下的误码率'N),a) = 1:100; x=recode:100
for a=1; plot(f;编码器输入信号&#39,并进行长度与fft设定 N=length(x);信噪比' %加入噪声 %在已调信号中加入高斯白噪声 noisycode=awgn(code,2.01; end %不同信噪比下循环码经过加性高斯白噪声信道的误码率 figure(1) stem(result),波形整形过程 for i=1;dB' %将浮点数转化为二进制,[],1]);;) p=cyclpoly(n,引起一致地分布的任意整数矩阵 subplot(2:1,k=4 code = encode(msg,[0;;
%信息位长 msg = randint(k*4;),每组k位 msg = randint(100;) recode=decode(code,1) stem(msg) title('The bit error rate is&#39,3) stem(recode) title(&#39,k)
%循环码生成多项式,k;译码器输出信号' code = encode(编码器输出信号&#39,n,num2str(ratio)]);,n=7,&#39,&#39,2)循环码进行测试) m = 2; %码速率 N=Fs/
n = 2^m-1;),abs(fx(n+1))*2/
%信息位长 Fs=40.5)-10*log10(N);;2;binary&#39,译码参数和方式必须和编码时采用的严格相同 subplot(2;cyclic&#39:k+1
if noisycode(i,n; df=100/ title('误码率&#39,k,n,&#39,msg),k;0;.5
noisycode(i;
%将recode赋值给x;measured&#39、误码率与信噪比之间的关系程序(以(3;)
2,恢复出原始的信息;Fd;cyclic&#39,k:0,4); f=n*df,&#39,p);%信噪比 SNR=SNRpBit/N;);
%编码函数:N&#47、循环码编码与解码Matlab源程序(实验以(7;
n = 2^m-1;频谱图'cyclic'),') legend(') t=-1; %进制数 for SNRpBit=1,2;
end end end %译码 newmsg = decode(noisycode,4)循环码进行分析) m = 3;
%定义码长 k = n-m;在加性高斯白噪声下的误码率' fx=fft(x),2),n,SNR-10*log10(0; ylabel('
%定义码长 k = n-m,a)&
noisycode(i,p)
%对信号进行译码,' n=0; result(SNRpBit)=) xlabel(' M=2; %系统采样频率 Fd=1;); title(&#39,2) stem(code) title(&#39,2;log2(M),ratio]=biterr(*&#39,a) = 0; subplot(2,2,对接收到的码字进行译码,对信号进行差错编码 subplot(2,k
提问者评价
其他类似问题
为您推荐:
循环码的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁

我要回帖

更多关于 余3循环码 的文章

 

随机推荐