当前位置:网站首页>Halcon principle: Auto_ Threshold operator

Halcon principle: Auto_ Threshold operator

2022-06-23 12:00:00 Mr anhydrous

One 、 operator auto_threshold brief introduction

        auto_threshold Use multiple thresholds to segment a single channel image . First , Determine the absolute histogram of the gray value . then , Extract the relevant minimum value from the histogram , These minimum values are used continuously as parameters for threshold operation . be used for byte Image threshold is 0、255, And all the minimum values extracted from the histogram ( Use standard deviation in histogram Sigma After Gaussian filter smoothing ). For each gray value interval , Will generate a region . therefore , The number of areas is the minimum + 1 The number of .

         about uint2 Images , The above process uses... Similarly . However , The highest threshold here is 65535. Besides , about uint2 Images ,Sigma Value ( actually ) It means having 256 Histogram of values , Although the histogram with higher resolution is used internally . This is done to facilitate switching between image types , Without changing the parameters Sigma.

         about float Images , The threshold is the minimum and maximum gray values in the image and all the minimum values extracted from the histogram . here , Parameters Sigma The scaling of the image refers to the original gray value of the image . Select the Sigma The bigger the value is. , The less areas to extract . If the region to be extracted shows similar gray values ( Homogeneous region ), This operator is useful .

Two 、 Actual case

read_image (Image, 'fabrik')
median_image (Image, Median, 'circle', 3, 'mirrored')
auto_threshold (Median, Seg, 5)
connection (Seg, Connected)

3、 ... and 、 Implement with your own code

         Here, according to  auto_threshold Official explanation , The principle of the operator implemented by the user . Be careful , The following algorithm has been used to auto_threshold The meaning of is completely expressed .

read_image (Image, 'fabrik')
median_image (Image, Median, 'circle', 3, 'mirrored')
get_image_size(Median, Width, Height)
gen_rectangle1(Rectangle, 0, 0, Width, Height)

gray_histo(Rectangle,Image, AbsoluteHisto, RelativeHisto)
create_funct_1d_array(RelativeHisto, Function)
smooth_funct_1d_gauss(Function, 4, SmoothedFunction)

derivate_funct_1d( SmoothedFunction, 'first',function1_der)
derivate_funct_1d( SmoothedFunction, 'second',function2_der)
funct_1d_to_pairs( function1_der, XValues1, YValues1)
funct_1d_to_pairs( function2_der, XValues2, YValues2)

tuple_length(XValues2, Length)

xx:=[]
for I:=0 to Length-1 by 1
    if (  ( abs(YValues1[I]) < 0.001 )  and (YValues2[I]>0.00001 ) )
        xx:=[xx,I]
    endif

endfor

stop()
offset:=6
var:=xx[0]
mm:=[]
mm:=[mm,var]

i:=1
tuple_length(xx,len)
len:=len-1
while(i<len)
    while(abs(xx[i]-var)<offset and  i<len  )
        var:=xx[i]
        i:=i+1
    endwhile      
    if(i<len)
        mm:=[mm,xx[i]]
        var:=xx[i]
    endif
endwhile
stop()

tlow:=[0,mm]
thigh:=[mm,255]
threshold(Image,Region, tlow,thigh)

connection (Region, Connected)

Reference article :

halcon principle : One dimensional function function_1d type 【1】

halcon principle : One dimensional function function_1d type 【2】

原网站

版权声明
本文为[Mr anhydrous]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206231152017494.html