资源描述:
《forstner算子提取特征点.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Forstner算子提取特征点(原创);------------------------------;Forstner算子;;image:输入原始图像;vwsize:窗口宽度;ithresh:初选差分阈值;qthresh:兴趣值阈值functionForstner,image,vwsize=vwsize,ithresh=ithresh,Tq=TqIFN_Elements(vwsize)eq0THENvwsize=5IFN_Elements(ithresh)eq0THENithresh=50IFN_Elements(Tq)eq0THENT
2、q=0.5image=float(image)imgSize=Size(image,/Dimensions)xsize=imgSize[0]ysize=imgSize[1];灰度的协方差矩阵result=fltarr(xsize,ysize);第一步:利用差分算子提取初选点fori=1,xsize-2dobegin forj=1,ysize-2dobegin dg1=abs(image[i,j]-image[i+1,j]) dg2=abs(image[i,j]-image[i,j+1]) dg3=abs(image[i,j
3、]-image[i-1,j]) dg4=abs(image[i,j]-image[i,j-1]) dg=[dg1,dg2,dg3,dg4] temp=dg[sort(dg)] iftemp[2]gtithreshthenbegin result[i,j]=255 endifelsebegin result[i,j]=0 endelse endforendfor;第二步:在以初选点为中心的3*3的窗口中计算协方差矩阵与圆度;此处可用where提高循环效率;权重矩阵wMatrix=fltarr(xsiz
4、e,ysize)fori=1,xsize-2dobegin forj=1,ysize-2dobegin ;是初选点 ifresult[i,j]eq255thenbegin gu2=0.0&gv2=0.0&guv=0.0 forii=-1,1dobegin forjj=-1,1dobegin gu2=gu2+(image[i+1,j+1]-image[i,j])^2 gv2=gv2+(image[i,j+1]-image[i+1,j])^2 guv=guv+(image[i+1,
5、j+1]-image[i,j])*(image[i,j+1]-image[i+1,j]) endfor endfor DetN=gu2*gv2-guv trN=gu2+gv2 q=4*DetN/(trN*trN) ;第三步:设定阈值Tq,若满足则计算权值 ifqgtTqthenwMatrix[i,j]=DetN/trN endif endforendfor;第四步:以权值为基础,在一定窗口内抑制局部非最大值候选点;取出局部极大值点wradius=vwsize/2fori=wradius,
6、xsize-1-wradiusdobegin forj=wradius,ysize-1-wradiusdobegin tempiv=wMatrix[i-wradius:i+wradius,j-wradius:j+wradius] ;将区域内像素按从大至小排列 tempsort=tempiv(REVERSE(SORT(tempiv))) ;排除整个区域像素相等的情况 if(wMatrix[i,j]eqtempsort[0])and(wMatrix[i,j]netempsort[1])thenbegin resu
7、lt[i,j]=255 endifelsebegin result[i,j]=0 endelse endforendforreturn,resultend;--------------------proForstner_testDEVICE,DECOMPOSED=1;获取本程序所在文件路径RootDir=Sourceroot();file=RootDir+'small.bmp'file=RootDir+'8bit_house.bmp'queryStatus=QUERY_IMAGE(file,imgInfo)ifque
8、ryStatuseq0thenbegin Result=DIALOG_MESSAGE('参考图像格式不可识别!',/error,title='警告') returnendifif(imgInfo.CHA