代码效果
抽取前
中值抽取暗
halcon函数代码
测试图片参数 NoiseCut:=16 Gain:=1
输入ImagePart NoiseCut Gain
*获取直方图
get_domain (ImagePart, Domain)
gray_histo_range(Domain,ImagePart,0,255,256, Histo, BinSize)
area_center(Domain, NumPixels, Row, Column)
*获取中值
Threshold := NumPixels / 2
MedianValue := 0
Index := 0
while ( MedianValue< Threshold)
Index := Index + 1
MedianValue:=Histo[Index]+MedianValue
endwhile
MedianValue := Index
*中值补正
gen_image_proto(ImagePart, ImageCleared2, MedianValue)
*抽取暗
*小于中值的赋值为255
abs_diff_image(ImagePart, ImageCleared2, ImageAbsDiff1, 1)
threshold(ImageAbsDiff1, Region1, 0, 0)
paint_region(Region1, ImageAbsDiff1, ImageResult1, 255, 'fill')
*抽取暗 255- (中值-像素值-抗干扰值) * 增益
*抽取明 (像素值-中值-抗干扰值)*增益 截断
gen_image_proto(ImagePart, ImageCleared3, 255)
gen_image_proto(ImageCleared3, ImageCleared, MedianValue-NoiseCut)
sub_image(ImageCleared, ImagePart, ImageSub, Gain, 0)
sub_image(ImageCleared3, ImageSub, ImageSub22, 1, 0)
max_image(ImageResult1, ImageSub22, ImageMax)
return ()