文件夹内有不同对焦情况下的图像,使用某种图像清晰度评定方法(intensity),遍历所有图片,找到在此评定方法下,清晰度最高的图像,将其显示在图像窗口上。
*读取文件夹
dev_clear_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
dev_set_draw ('margin')
list_image_files ('F:/CYYT/VirtualProject/focus', 'default', [], ImageFiles)
*遍历图片
Ret:=[]
for Index := 1 to |ImageFiles| - 1 by 1
read_image (Image, ImageFiles[Index])
rgb1_to_gray (Image, GrayImage)
get_image_size (GrayImage, Width, Height)
intensity (GrayImage, GrayImage, Mean, Deviation)
set_tposition (WindowHandle, 300, 200)
write_string (WindowHandle, 'The' +Index + 'th' +' image')
*把方差保存到字典中
Ret:=[Ret,Deviation]
endfor
index1 := find(Ret,max(Ret))
*显示清晰度最高的图像
read_image (Image1, 'F:/CYYT/VirtualProject/focus/focus_bga_'+index1$'02d')
dev_display (Image1)
set_tposition (WindowHandle, 300, 200)
write_string (WindowHandle, 'This is the highest definition image')
运行结果