天天看點

深度了解灰階圖像形态學之腐蝕3

結構元素1

0 0 0

0 0 0

0 0 0

結構元素2

0 10 0 A(00) A(01) A(02)

20 0 30 A(10) A(11) A(12)

0 40 0 A(20) A(21) A(22)

當結構體區域内最小值在A01位置時,結果為最小值-A(01)

當結構體區域内最小值在A10位置時,結果為最小值-A(10)

當結構體區域内最小值在A12位置時,結果為最小值-A(12)

當結構體區域内最小值在A21位置時,結果為最小值-A(21)

當結構體區域内最小值在其餘位置(結構元素為0)時,結果為最小值。大部分是這樣,有的位置找不到規律,不知道為何,如第二行第三列89,不知道為何

dev_close_window ()

*建立原圖 9*9
gen_image_const (Image, 'byte', 9, 9)
get_image_size (Image, Width, Height)
dev_open_window_fit_image (Image, 0, 0, Width, Height, WindowHandle)
*生成随機數0-255,并将随機數設定成圖像像素
tuple_rand (81, Rand)
Rand:=Rand*100
tuple_int (Rand, Int)
Int:=Int+120
Cnt:=9
for Index := 0 to Cnt-1 by 1
    for Index1 := 0 to Cnt-1 by 1
        Pos:=Index*Cnt+Index1
        set_grayval (Image, Index, Index1, Int[Pos])
    endfor
endfor

*建立結構元素1 内部都是0
* 0 0 0
* 0 0 0
* 0 0 0
gen_image_const (ImageSE, 'byte', 3, 3)
Cnt:=3
for Index := 0 to Cnt-1 by 1
    for Index1 := 0 to Cnt-1 by 1
        Pos:=Index*Cnt+Index1
        set_grayval (ImageSE, Index, Index1, 0)
    endfor
endfor

*建立結構元素2
* 0  10 0
* 20 0  30
* 0  40 0
gen_image_const (ImageSE1, 'byte', 3, 3)
set_grayval (ImageSE1, 0, 0, 0)
set_grayval (ImageSE1, 0, 1, 10)
set_grayval (ImageSE1, 0, 2, 0)
set_grayval (ImageSE1, 1, 0, 20)
set_grayval (ImageSE1, 1, 1, 0)
set_grayval (ImageSE1, 1, 2, 30)
set_grayval (ImageSE1, 2, 0, 0)
set_grayval (ImageSE1, 2, 1, 40)
set_grayval (ImageSE1, 2, 2, 0)

*一:使用結構元素1腐蝕原圖并顯示前後像素對比
dev_display (Image)
gray_erosion (Image, ImageSE, ImageErosion)

*顯示腐蝕前後像素對比
dev_open_window (0, 0, 400, 640, 'black', WindowHandle1)
BeginRow:=10
BeginColumn:=10
Cnt:=9
for Index := 0 to Cnt-1 by 1
    for Index1 := 0 to Cnt-1 by 1
        Pos:=Index*Cnt+Index1
        get_grayval (Image, Index, Index1, Grayval)
        Row:=BeginRow+Index*30
        Column:=BeginColumn+Index1*40
        disp_message (WindowHandle1, Grayval, 'window', Row, Column, 'red', 'true')
    endfor
endfor

Row:=Row+40
disp_line (WindowHandle1, Row, 0, Row, 640)

BeginRow:=Row+10
BeginColumn:=10
for Index := 0 to Cnt-1 by 1
    for Index1 := 0 to Cnt-1 by 1
        Pos:=Index*Cnt+Index1
        get_grayval (ImageErosion, Index, Index1, Grayval)
        Row:=BeginRow+Index*30
        Column:=BeginColumn+Index1*40
        disp_message (WindowHandle1, Grayval, 'window', Row, Column, 'red', 'true')
    endfor
endfor
stop ()

*二:使用結構元素2腐蝕原圖并顯示前後像素對比
dev_set_window (WindowHandle)
gray_erosion (Image, ImageSE1, ImageErosion1)

*顯示腐蝕前後像素對比
dev_open_window (0, 0, 400, 640, 'black', WindowHandle2)
BeginRow:=10
BeginColumn:=10
Cnt:=9
for Index := 0 to Cnt-1 by 1
    for Index1 := 0 to Cnt-1 by 1
        Pos:=Index*Cnt+Index1
        get_grayval (Image, Index, Index1, Grayval)
        Row:=BeginRow+Index*30
        Column:=BeginColumn+Index1*40
        disp_message (WindowHandle2, Grayval, 'window', Row, Column, 'red', 'true')
    endfor
endfor

Row:=Row+40
disp_line (WindowHandle2, Row, 0, Row, 640)
BeginRow:=Row+10
BeginColumn:=10
for Index := 0 to Cnt-1 by 1
    for Index1 := 0 to Cnt-1 by 1
        Pos:=Index*Cnt+Index1
        get_grayval (ImageErosion1, Index, Index1, Grayval)
        Row:=BeginRow+Index*30
        Column:=BeginColumn+Index1*40
        disp_message (WindowHandle2, Grayval, 'window', Row, Column, 'red', 'true')
    endfor
endfor
stop ()


           
深度了解灰階圖像形态學之腐蝕3

繼續閱讀