冈萨雷斯(bound2im、frdescp、boundaries)

%bound2im源程序
function B=bound2im(b,M,N,x0,y0)
%  BOUND2IM Converts a boundary to an image.
%  B = bound2im(b) converts b, an np-by-2 or 2-by-np array
%  representing the integer coordinates of a boundary, into a binary
%  image with 1s in the locations defined by the coordinates in b
%  and 0s elsewhere.
%
%  B = bound2im(b, M, N) places the boundary approximately centered
%  in an M-by-N image. If any part of the boundary is outside the
%  M-by-N rectangle, an error is issued.
%
%  B = bound2im(b, M, N, X0, Y0) places the boundary in an image of
%  size M-by-N, with the topmost boundary point located at X0 and
%  the leftmost point located at Y0. If the shifted boundary is
%  outside the M-by-N rectangle, an error is issued. XO and X0 must
%  be positive integers.[np,nc]=size(b);
if np<ncb=b';%To convert to size np-by-2.[np,nc]=size(b);
end%Make sure the coordinates are integers.
x=round(b(:,1));
y=round(b(:,2));%Set up the default size parameters.
x=x-min(x)+1;
y=y-min(y)+1;
B=false(max(x),max(y));
C=max(x)-min(x)+1;
D=max(y)-min(y)+1;if nargin==1%Use the preceding defualt valuaes.
elseif nargin==3if C>M | D>Nerror('The boundary is outsize the M-by-N region.')end%The image size will be M-by-N.Set up the parameters for this.B=false(M,N);%Distribute extra rows appox. even between top and botton.NR=round((M-C)/2);NC=round((N-D)/2);%The same for columns.x=x+NR;%Offset the boundary to new position.y=y+NC;
elseif nargin==5if x0<0 | y0<0error('x0 and y0 must be positive integers.')endx=x+round(x0)-1;y=y+round(y0)-1;C=C+x0-1;D=D+y0-1;if C>M | D>Nerror('The shifted boundary is outside the M-by-N region.')endB=false(M,N);
elseerror('Incorrect number of inputs.')
endB(sub2ind(size(B),x,y))=true;
%frdescp源程序
function z = frdescp(s)
%FRDESCP Computes Fourier descriptors.
%   Z = FRDESCP(S) computes the Fourier descriptors of S, which is an
%   np-by-2 sequence of image coordinates describing a boundary.
%
%   Due to symmetry considerations when working with inverse Fourier
%   descriptors based on fewer than np terms, the number of points in
%   S when computing the descriptors must be even.  If the number of
%   points is odd, FRDESCP duplicates the end point and adds it at
%   the end of the sequence. If a different treatment is desired, the
%   sequence must be processed externally so that it has an even
%   number of points.
%
%   See function IFRDESCP for computing the inverse descriptors.  %   Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins
%   Digital Image Processing Using MATLAB, Prentice-Hall, 2004
%   $Revision: 1.4 $  $Date: 2003/10/26 23:13:28 $ % Preliminaries
[np, nc] = size(s);
if nc ~= 2  error('S must be of size np-by-2.');
end
if np/2 ~= round(np/2); s(end + 1, :) = s(end, :); np = np + 1;
end % Create an alternating sequence of 1s and -1s for use in centering
% the transform.
x = 0:(np - 1);
m = ((-1) .^ x)'; % Multiply the input sequence by alternating 1s and -1s to
% center the transform.
s(:, 1) = m .* s(:, 1);
s(:, 2) = m .* s(:, 2);
% Convert coordinates to complex numbers.
s = s(:, 1) + i*s(:, 2);
% Compute the descriptors.
z = fft(s); 
%boundaries源程序
function B=boundaries(BW,conn,dir)
%BOUNDARIES Trace object boundaries.
%B=BOUNDARIES(BW) traces the exterior boundaries of objects in the binary
%image BW.B is a p_by_1 cell array,where p is the number of objects in the
%image.Each cell contains a Q_by_2 matrix,each row of which contains the
%row and column coordinates of a boundary pixel.Q is the number of boundary
%pixels for the corresponding object.Object boundaries are traced in the
%clockwise direction.
%
%B=BOUNDARIES(BW,CONN) specifies the connectivity to use when tracing
%boundaries.CONN may be either 8 or 4.The default value for CONN is 8.
%
%B=BOUNDARIES(BW,CONN,DIR) specifies the direction used for tracing
%boundaries.DIR should be either 'cw'(trace boundaries clockwise) or
%'ccw'(trace boundaries counterclockwise).If DIR is omitted BOUNDARIES
%traces in the clockwise direction.
if nargin<3   %nargin定义在用户自定义函数体内,nargin返回 %用来调用函数的变量的个数。 dir='cw';
end
if nargin<2 conn=8;
end
L=bwlabel(BW,conn); %返回值是矩阵L,大小同BW,包含了BW中的连通部分的标记
%The number of objects is the maximum value of L.Initialize the cell
%array(元包数组)B so that each cell initially contains a 0_by_2 matrix.
numObjects=max(L(:));%寻找L中所作标记中的最大值,这个最大值实际上就对应着L中
% 包含的最多的连通部分的数目。
if numObjects>0 B={zeros(0,2)};%元包数组中仅包含一个元素。 B=repmat(B,numObjects,1);%将B进行numObjects*1个复制构成新的B。
else B={};
end
%Pad label matrix with zeros.This lets us write the boundary_following loop
%without worrying about going off the edge of the image.
Lp=padarray(L,[1 1],0,'both');
%Compute the linear indexing offsets to take us from a pixel to its
%neighbors.
M=size(Lp,1);%SIZE(X,1) returns the number of rows.  if conn==8 %Order is N NE E SE S SW W NW. offsets=[-1,M-1,M,M+1,1,-M+1,-M,-M-1];
else %Order is N E S W. offsets=[-1,M,1,-M];
end
%next_search_direction_lut is a lookup table.Given the direction from pixel
%k to pixel k+1,what is the direction to start with when examining the
%neighborhood of pixel k+1?
if conn==8 next_search_direction_lut=[8 8 2 2 4 4 6 6];
else next_search_direction_lut=[4 1 2 3];
end
%next_direction_lut is a lookup table.Given that we just looked at neighbor
%in a given direction,which neighbor do we look at next?
if conn==8 next_direction_lut=[2 3 4 5 6 7 8 1];
else next_direction_lut=[2 3 4 1];
end
%Values used for marking the starting and boundary pixels.
START=-1;
BOUNDARY=-2;
%Initialize scratch space in which to record the boundary pixels as well as
%follow the boundary.
scratch=zeros(100,1);
%Find candidate starting locations for boundaries.
[rr,cc]=find((Lp(2:end-1,:)>0)&(Lp(1:end-2,:)==0));
rr=rr+1;
for k=1:length(rr) r=rr(k); c=cc(k); if (Lp(r,c)>0)&(Lp(r-1,c)==0)&isempty(B{Lp(r,c)}) %We've found the start of the next boundary.Compute its linear %offset,record which boundary it is,mark it,and initialize the %counter for the number of boundary pixels. idx=(c-1)*size(Lp,1)+r; which=Lp(idx); scratch(1)=idx; Lp(idx)=START; numpixels=1; currentpixel=idx; initial_departure_direction=[]; done=0; next_search_direction=2; while ~done %Find the next boundary pixel. direction=next_search_direction; found_next_pixel=0; for k=1:length(offsets) neighbor=currentpixel+offsets(direction); if Lp(neighbor)~=0 %Found the next boundary pixel. if (Lp(currentpixel)==START)&... isempty(initial_departure_direction) %We are making the initial departure from the starting %pixel. initial_departure_direction=direction; elseif (Lp(currentpixel)==START)&... (initial_departure_direction==direction) % We are about to retrace our path. %That means we're done. done=1; found_next_pixel=1; break; end %Take the next step along the boundary. next_search_direction=... next_search_direction_lut(direction); found_next_pixel=1; numpixels=numpixels+1; if numpixels>size(scratch,1) %Double the scratch space. scratch(2*size(scratch,1))=0; end scratch(numpixels)=neighbor; if Lp(neighbor)~=START Lp(neighbor)=BOUNDARY; end currentpixel=neighbor; break; end direction=next_direction_lut(direction); end if ~found_next_pixel %If there is no next neighbor,the object must just have a %single pixel. numpixels=2; scratch(2)=scratch(1); done=1; end end %Convert linear indices to row_column coordinates and save in the %output cell array. [row,col]=ind2sub(size(Lp),scratch(1:numpixels)); B{which}=[row-1,col-1]; end
end
if strcmp(dir,'ccw') for k=1:length(B) B{k}=B{k}(end:-1:1,:); end
end

冈萨雷斯toolbox相关推荐

  1. ai条码插件免安装_ai条码插件2款下载|Barcode Toolbox插件+Barcode条码插件下载 - 偶要下载站...

    本次一次性打包两款ai条码插件和大家分享,分别是Barcode Toolbox插件和Barcode脚本插件,支持Illustrator CS5~CC2015的条形码脚本!这两个插件不是一个插件,是有区 ...

  2. 扩展城市信道etu模型matlab仿真,LTE System Toolbox:无线通信系统的仿真、分析和测试...

    LTE System Toolbox 提供用于设计.仿真和验证 LTE 和 LTE-Advanced 通信系统且符合标准的函数和应用程序.该系统工具箱加速了 LTE 算法和物理层 (PHY) 部署,支 ...

  3. matlab length_《Matlab - Robotics System Toolbox》学习笔记(2)

    写作说明: 1. 本文主要记录学习 Matlab - Robotics System Toolbox[1]的过程,就其中的一些重要知识点做相关记录.方便后期供自己与他人进行学习. 2. 由于 Matl ...

  4. GATB=The Genome Analysis Toolbox with de-Bruijn graph 带有de-Bruijn图的基因组分析工具箱

    带有de-Bruijn图的基因组分析工具箱 Software Depending on your needs, you can choose one the following software co ...

  5. Velocity Toolbox

    2019独角兽企业重金招聘Python工程师标准>>> 一.velocity简介:略 二.需要引入一些相关的包: (相关包可以到官方下载:http://velocity.apache ...

  6. 使用docker toolbox 在windows上搭建统一环境

    1.先下载docker toolbox 以下是下载地址: http://get.daocloud.io/#install-docker-for-mac-windows 2.下载安装 git windo ...

  7. echarts中toolbox位置_基于QGIS中的LSMS(大规模均值漂移)分割算法

    在学习分割算法中,很多使用的是易康(eCognition)中的分割算法,在这里仅介绍一个开源软件的大规模均值漂移算法,在Remote Sensing期刊中也有用到.希望此文给与一定帮助.感兴趣可以阅读 ...

  8. 【资源分享】数字图像处理MATLAB版冈萨雷斯+中文高清版+随书源码链接

    写在这里的初衷,一是备忘,二是希望得到高人指点,三是希望能遇到志同道合的朋友. 目录 1.数字图像处理MATLAB版冈萨雷斯+中文高清版 2.数字图像处理MATLAB版冈萨雷斯随书源码 1.数字图像处 ...

  9. 【 MATLAB 】Signal Processing Toolbox Functions - By Category

    目录 Signal Processing Toolbox Functions - By Category Signal Generation and Preprocessing Smoothing a ...

最新文章

  1. android java服务器文件传输_java – 使用FTPS将文件从android传输到服务器
  2. mx51 uboot启动感悟
  3. 一文读懂全系列树莓派!
  4. Android及java中list循环添加时覆盖的问题-20171021
  5. AndroidStudio_百度人脸识别离线SDK_代码分析_使用流程_随时更新---Android原生开发工作笔记217
  6. myeclipse注册机,自己生成注册码
  7. python阈值分割_Python实现otsu阈值分割算法
  8. android添加本地资源文件,本地html文件放置位置,android中加载本地Html文件
  9. 5.1.1 电商离线数仓(数仓需求分析、日志采集、表数据加载、json数据处理、 Datax 数据导出、Tez高仿日启动测试)
  10. 华为软件编程规范和范例
  11. nginx反向代理是什么?
  12. 【计算机毕业设计】017学生公寓电费信息管理系统
  13. 强人工智能基本问题:自上而下还是自下而上?
  14. 雨伞被拿错,你怎么办?!
  15. 通达信资金净流入公式_通达信资金净流入指标公式$$$$$$
  16. 大数据中台架构以及建设全流程二(Daas层设计)
  17. Pycharm、Vscode设置美女背景【内附20张高清图片】
  18. spring+springMVC+mybatis 上篇
  19. Hadoop基础环境搭建完整版
  20. 嵌入式linux如何学?

热门文章

  1. Unity3d C#用UGUI系统实现类似于哔哩哔哩(B站)的弹幕效果功能(含源码)
  2. cntopic库:支持中英文LDA话题分析
  3. 2023计算机毕业设计题目选题经验
  4. java支付接口(支付宝、微信、QQ)
  5. UE4鼠标双击事件实现
  6. 三菱伺服电机故障代码维修
  7. UG NX 4 运动仿真提示“file not found” 不能进行运动仿真的解决方法
  8. html做的网页连wifi,ESP32通过WEB页面连接WIFI
  9. 2018考研数学一真题 ​​​
  10. 多重网格算法matlab程序,多重网格法求解雷诺方程.pdf