detect_indent_fft.hdev相關例程學習(檢測凹痕)

SRT字元不夠發表於2015-07-18
Index:.../Applications/Surface-Inspection/detect_indent_fft.hdev
主要步驟:
 
* Optimize the fft speed for the specific image size
optimize_rft_speed (Width, Height, 'standard')
* 選取了最優rft變化速度的影像大小
* Construct a suitable filter by combining two gaussian
* filters
Sigma1 := 10.0
Sigma2 := 3.0
gen_gauss_filter (GaussFilter1, Sigma1, Sigma1, 0.0, 'none', 'rft', Width, Height)
gen_gauss_filter (GaussFilter2, Sigma2, Sigma2, 0.0, 'none', 'rft', Width, Height)
sub_image (GaussFilter1, GaussFilter2, Filter, 1, 0)
* 建立兩個高斯濾波器然後又結合起來
*要搞明白究竟何為高斯濾波器 
* Process the images iteratively
NumImages := 11
for Index := 1 to NumImages by 1
    * 
    * Read an image and convert it to gray values
    read_image (Image, 'plastics/plastics_' + Index$'02')
    rgb1_to_gray (Image, Image)
    * Perform the convolution in the frequency domain
    rft_generic (Image, ImageFFT, 'to_freq', 'none', 'complex', Width)
    convol_fft (ImageFFT, Filter, ImageConvol)
    rft_generic (ImageConvol, ImageFiltered, 'from_freq', 'n', 'real', Width)
    * 各種rft變化加摺積在rft變化
    * Process the filtered image
    gray_range_rect (ImageFiltered, ImageResult, 10, 10)
*通過此步驟就找到了凹痕所在,看了這個運算元的幫助文件,我就明白關鍵在於計算了每個mask中灰度的差,然後給一個總返回值,沒有參考文獻,看來是halcon自己的演算法。
    min_max_gray (ImageResult, ImageResult, 0, Min, Max, Range)
    threshold (ImageResult, RegionDynThresh, max([5.55,Max * 0.8]), 255)
    connection (RegionDynThresh, ConnectedRegions)
    select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 4, 99999)
    union1 (SelectedRegions, RegionUnion)
    closing_circle (RegionUnion, RegionClosing, 10)
    connection (RegionClosing, ConnectedRegions1)
    select_shape (ConnectedRegions1, SelectedRegions1, 'area', 'and', 10, 99999)
    area_center (SelectedRegions1, Area, Row, Column)
    * 一系列提取演算法,沒有需要關注的point

學習了這個例程,明白如何有效構建高斯濾波器和利用fft變化,halcon裡有rft和fft不知道內在區別,但核心都是FFT。

相關文章