Halcon清晰度檢測實例(轉)

Halcon清晰度檢測實例(轉)  

2013-10-08 14:11:07|  分類: halcon|舉報|字號 訂閱

此實例通過使用Halcon實現5種清晰度算法函數:
1. 方差算法函數;
2. 拉普拉斯能量函數;
3. 能量梯度函數;
4. Brenner函數;
5. Tenegrad函數;
測試效果如下圖片;找到峯值對應的那張圖,確實是最清晰的那張;使用直方圖顯示清晰度結果,如果有更好的方法,那就跟帖回覆吧。
此實例有HalconBBS羣友提供!
 
Halcon清晰度檢測實例(轉) - zazaniao - zazaniao的個人主頁
 
*evaluate_definition的使用例子
*使用halcon自帶的圖片
*實現了五種評價函數,
*選擇算子的Method值,可以觀察不同評價函數的效果。
read_image (Image, 'pcb_focus/pcb_focus_telecentric_106')
dev_update_off ()
dev_close_window ()
dev_open_window_fit_image (Image, 0, 0, 752, 480, WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_color ('lime green')
dev_set_line_width (3)
Ret:=[]
get_image_size(Image, Width, Height)
for Index := 1 to 121 by 1
    read_image (Image, 'pcb_focus/pcb_focus_telecentric_'+Index$'03d')
    
    evaluate_definition (Image, 'Tenegrad', Value)
    
    dev_display (Image)
    Ret:=[Ret,Value]
endfor
*使用直方圖顯示清晰度結果,如果有更好的方法,那就跟帖回覆吧
VMax:=max(Ret)
VMin:=min(Ret)
GRet := 100*(Ret-VMin)/(VMax-VMin)
gen_region_histo(Region, Ret, 255, 255, 1)
*找到峯值對應的那張圖,確實是最清晰的那張。
qxd:=find(Ret, max(Ret))
read_image (GoodImage, 'pcb_focus/pcb_focus_telecentric_'+qxd$'03d')
dev_display (GoodImage)
dev_display (Region)
evaluate_definition函數代碼如下:
 
scale_image_max(Image, Image)
get_image_size(Image, Width, Height)

if(Method = 'Deviation')
*方差法
    region_to_mean (Image, Image, ImageMean) 
    convert_image_type (ImageMean, ImageMean, 'real')
    convert_image_type (Image, Image, 'real') 
    sub_image(Image, ImageMean, ImageSub, 1, 0)
    mult_image(ImageSub, ImageSub, ImageResult, 1, 0)
    intensity(ImageResult, ImageResult, Value, Deviation) 
    
elseif(Method = 'laplace')
*拉普拉斯能量函數
    laplace (Image, ImageLaplace4, 'signed', 3, 'n_4')
    laplace (Image, ImageLaplace8, 'signed', 3, 'n_8')
    add_image(ImageLaplace4,ImageLaplace4,ImageResult1, 1, 0)
    add_image(ImageLaplace4,ImageResult1,ImageResult1, 1, 0)
    add_image(ImageLaplace8,ImageResult1,ImageResult1, 1, 0)
    mult_image(ImageResult1, ImageResult1, ImageResult, 1, 0)
    intensity(ImageResult, ImageResult, Value, Deviation)

elseif(Method = 'energy')
*能量梯度函數
    crop_part(Image, ImagePart00, 0, 0, Width-1, Height-1)
    crop_part(Image, ImagePart01, 0, 1, Width-1, Height-1)
    crop_part(Image, ImagePart10, 1, 0, Width-1, Height-1)
    convert_image_type (ImagePart00, ImagePart00, 'real')
    convert_image_type (ImagePart10, ImagePart10, 'real')
    convert_image_type (ImagePart01, ImagePart01, 'real')
    sub_image(ImagePart10, ImagePart00, ImageSub1, 1, 0)
    mult_image(ImageSub1, ImageSub1, ImageResult1, 1, 0)
    sub_image(ImagePart01, ImagePart00, ImageSub2, 1, 0)
    mult_image(ImageSub2, ImageSub2, ImageResult2, 1, 0)
    add_image(ImageResult1, ImageResult2, ImageResult, 1, 0)    
    intensity(ImageResult, ImageResult, Value, Deviation)
elseif(Method = 'Brenner')
*Brenner函數法
    crop_part(Image, ImagePart00, 0, 0, Width, Height-2)
    convert_image_type (ImagePart00, ImagePart00, 'real')
    crop_part(Image, ImagePart20, 2, 0, Width, Height-2)
    convert_image_type (ImagePart20, ImagePart20, 'real')
    sub_image(ImagePart20, ImagePart00, ImageSub, 1, 0)
    mult_image(ImageSub, ImageSub, ImageResult, 1, 0)
    intensity(ImageResult, ImageResult, Value, Deviation)
elseif(Method = 'Tenegrad')
*Tenegrad函數法
    sobel_amp (Image, EdgeAmplitude, 'sum_sqrt', 3)
    min_max_gray(EdgeAmplitude, EdgeAmplitude, 0, Min, Max, Range)
    threshold(EdgeAmplitude, Region1, 11.8, 255)
    region_to_bin(Region1, BinImage, 1, 0, Width, Height)
    mult_image(EdgeAmplitude, BinImage, ImageResult4, 1, 0)
    mult_image(ImageResult4, ImageResult4, ImageResult, 1, 0)
    intensity(ImageResult, ImageResult, Value, Deviation)
   
elseif(Method = '2')

elseif(Method = '3')
    
endif
    
return ()

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章