- ***使用灰階投影搜尋變化
- read_image (Test, 'C:/Users/genel/Downloads/1.jpg')
- rgb1_to_gray (Test, GrayImage)
- get_image_size(GrayImage, Width, Height)
- get_domain(GrayImage, Domain)
- ***分段投影
- gray_projections (Domain, GrayImage, 'rectangle', HorProjection, VertProjection)
- create_funct_1d_array (VertProjection, Function)
- smooth_funct_1d_gauss (Function, 8, SmoothedFunction)
- derivate_funct_1d (SmoothedFunction, 'first', Derivative)
- ***
- sel:= Derivative[4:|Derivative|-1]
- **定位
- tuple_greater_elem (sel, 0.05, Greater)
- tuple_find(Greater, 1, Indices)
- ***正緣變化
- p_start:=[]
- p_end:=[]
- pre:=0
- for i:=0 to |Greater|-1 by 1
- if(Greater>0 and pre=0)
- p_start[|p_start|]:=i
- pre:=1
- else
- if(Greater=0 and pre=1)
- pre:=0
- p_end[|p_end|]:=i-1
- endif
- endif
- endfor
- tuple_less_elem (sel, -0.05, Less)
- tuple_find(Less, 1, NegIndices)
- **抓負緣
- n_start:=[]
- n_end:=[]
- n_pre:=0
- for i:=0 to |Less|-1 by 1
- if(Less>0 and n_pre=0)
- n_start[|n_start|]:=i
- n_pre:=1
- else
- if(Less=0 and n_pre=1)
- n_pre:=0
- n_end[|n_end|]:=i-1
- endif
- endif
- endfor
- ****判斷 負緣先出現 則為干擾
- defect:=[]
- for i:=0 to |p_start|-1 by 1
- if(p_start<n_start)
- defect[|defect|]:=i
- endif
- endfor
- ***draw result 懶惰隨便來!
- for j:=0 to |defect|-1 by 1
- gen_rectangle1(Rectangle, 0,p_start[defect[j]], 54, n_end[defect[j]])
- endfor
复制代码
|