在机器视觉领域,图像的预处理算法十分重要。对于一些成像质量较差,受噪声影响较大的场景中,为保证视觉测量,定位,检测效果的稳定性。往往第一步就是对图像做处理,这里对常用的预处理算法做总结。
dev_close_window ()
dev_open_window (0, 0, 900, 512, 'black', WindowHandle)
read_image (Image, 'F:\\fabrik.png')
*腐蚀图像
gray_erosion_rect (Image, ImageMin, 11, 11)
*膨胀图像
gray_dilation_rect (Image, ImageMax, 11, 11)
*图像闭操作
gray_closing_rect (Image, ImageClosing, 11, 11)
*图像开操作
gray_opening_rect (Image, ImageOpening, 11, 11)
*边缘抽取
sobel_amp (Image, EdgeAmplitude, 'sum_abs', 3)
*水平边缘提取
sobel_amp (Image, EdgeAmplitude1, 'x', 3)
*垂直边缘提取
sobel_amp (Image, EdgeAmplitude1, 'y', 3)
*边缘增强
emphasize (Image, ImageEmphasize, 7, 7, 1)
*prewitt
prewitt_amp (Image, ImageEdgeAmp)
*roberts
roberts (Image, ImageRoberts, 'gradient_sum')
*laplace
laplace (Image, ImageLaplace, 'absolute', 3, 'n_4')
*去除背景
tuple_gen_const (256,0, Newtuple)
lowVal:=10
highVal:=150
if(lowVal<highVal)
for Index := lowVal to highVal by 1
Newtuple[Index]:=(Index-lowVal)*255/(highVal-lowVal)
endfor
for Index := highVal to 255 by 1
Newtuple[Index]:=255
endfor
lut_trans (Image, ImageResult, Newtuple)
endif
*亮度修正
lowVal:=10
highVal:=150
tuple_gen_const (256, 0, Newtuple)
for Index := 0 to 255 by 1
val:=Index*lowVal + highVal
if(val>255)
val := 255
endif
if(val<0)
val := 0
endif
Newtuple[Index]:=val
endfor
lut_trans (Image, ImageResult1, Newtuple)
*异物消除
lowVal:=10
highVal:=150
minVal:=lowVal-highVal
maxVal:=lowVal+highVal
factor:=0.1
if(factor<0.5)
dirVal:=255
else
dirVal:=0
endif
if(minVal<0)
minVal:=0
endif
if(minVal>255)
minVal:=255
endif
tuple_gen_const (256, 0, Newtuple)
for Index := 0 to 256 by 1
Newtuple[Index]:=Index
endfor
for Index := minVal to maxVal by 1
Newtuple[Index]:=dirVal
endfor
*lut_trans (Image, ImageResult2, Newtuple)
*二值化
get_image_size (Image, Width, Height)
threshold (Image, Region, 128, 255)
region_to_bin (Region, BinImage, 255, 0, Width, Height)
*动态二值化
mean_image (Image, ImageMean, Width, Height)
dyn_threshold (ImageMean, ImageMean, RegionDynThresh, 5, 'light')
region_to_bin (RegionDynThresh, BinImage1, 255, 0, Width, Height)
*黑白颠倒
invert_image (Image, ImageInvert)
*灰度拉伸
scale_image_max (ImageInvert, ImageScaleMax)
*直方图拉伸
equ_histo_image (Image, ImageEquHisto)
*纹理滤波
texture_laws (Image, ImageTexture, 'el', 2, 5)