資源簡介
matlab實現圖像邊緣提取,hough變換進行橢圓檢測,有注釋
代碼片段和文件信息
f1=imread(‘G:\bishe\lll.JPG‘);???%讀入圖像返回二維矩陣
figure;
imshow(f1);
fedge=edge?(f1‘canny‘[00.7]0.07);??%提取邊緣
figure;
imshow(fedge);
[row?col]=size(fedge);??????%?獲取矩陣的行列數??
%?minofa=5;????????%
%?maxofa=round(row/2)-20;?????%四舍五入行/2
minofa=15;
maxofa=30;
minofy0=round(col/2)-40;??%四舍五入
maxofy0=round(col/2)-25;????%------
minofb=15;
maxofb=25;
%minofb=round(col/2)-60;???????%------
%maxofb=round(col/2)-20;??????????%---------
maxofx=round(row/2)+20;???????????%--------
scalor=1;?????????????????%令scalor=4
H=zeros(floor((maxofa-minofa)/scalor)+1floor((maxofa-minofa)/scalor)+1floor((maxofy0-minofy0)/scalor)+1floor((maxofb-minofb)/scalor)+1);???????????%取小于某數的最大整數?
for?x=1:maxofx
???for?y=1:col
?????temp=fedge(xy);??????????????????????????%從第一行第一列開始
???????if?temp==255????????????????????????????%如果這一點為?,則
?????????for?a=minofa:scalor:maxofa
???????????for?x0=a:scalor:maxofa
?????????????for?b=minofb:scalor:maxofb
???????????????for?y0=minofy0:scalor:maxofy0
??????????????????temp=((y-y0)/b)^2+((x-x0)/a)^2;
????????????????????if?abs(temp-1)<=0.01?????????????????%?判斷在誤差范圍內是否為橢圓;如果是
?????????????????????????xtemp=floor((x0-minofa)/scalor)+1;??????
??????
評論
共有 條評論