【语言转换】matlab imdilate,strel参数为square的方法idl实现

来源:互联网 发布:软件任务实施计划 编辑:程序博客网 时间:2024/05/16 13:40

matlab中用来求扩张的方法,在参数第一项中有很多选项,详情~~帮助文档里有,本文实现的是参数为‘square’的方法。

SEs=strel('square',b); a=imdilate(a,SEs);

在matlab中应是如上的语句。应是规定一个b*b的矩形模板,对a进行掩膜,每个值取邻域b*b里最大的值。

idl中通过实现方法是这样调用的:

a=imdilate_square(a,b)

具体方法实现如下,测试用例也在前面有:

FUNCTION imdilate_square,dataimage,valueimage;PRO imdilate_square;dataimage=[[1,2,3,4,5,6,7,8,9,10],[10,2,3,4,5,6,7,8,9,1],[1,2,3,4,5,6,7,8,9,10],[3,4,5,6,7,8,9,10,1,2]]result=dataimage;valueimage=3errorvalue=min(dataimage)cols=n_elements(dataimage[*,0])rows=n_elements(dataimage[0,*]);合法性检查if valueimage le 0 then begin  return,-1endifif valueimage gt cols && cols le rows then begin  valueimage=colsendifif valueimage gt rows && rows le cols then begin  valueimage=rowsendiffor i=0, rows-1 do begin  for j=0, cols-1 do begin    tmpmatirx= dblarr(valueimage*valueimage)    tmp=0    for h=-valueimage+2,valueimage-2 do begin      for k=-valueimage+2,valueimage-2 do begin        if j+h lt 0|| i+k lt 0 then begin          tmpmatirx[tmp]=errorvalue        endif else if j+h gt cols-1|| i+k gt rows-1 then begin            tmpmatirx[tmp]=errorvalue        endif else begin          tmpmatirx[tmp]=dataimage[j+h,i+k]        endelse        tmp++      endfor    endfor    result[j,i]=max(tmpmatirx)  endforendfor;print,resultreturn,resultEND


阅读全文
0 0
原创粉丝点击