灰度值形态学

1. 膨胀、腐蚀

g(r,c):待处理的图像

s(r,c):结构元图像

平坦结构元:结构元图像内灰度值都是0,s(r,c) = 0

当使用平坦结构元时,膨胀:在结构元的范围内选择灰度值最大值。如果把结构元视为滤波器掩码,膨胀可被称为最大值滤波。

当使用平坦结构元时,腐蚀:在结构元的范围内选择灰度值最小值。如果把结构元视为滤波器掩码,腐蚀可被称为最小值滤波。

2. 开操作与闭操作

对于灰度值形态学,

开操作:腐蚀+膨胀

闭操作:膨胀+腐蚀

3. 顶帽、底帽

顶帽:原图像 - 开操作

底帽:闭操作 - 原图像

4. 灰度范围 -- 形态学梯度算子

计算出现在结构元内的灰度值范围:膨胀 - 腐蚀

gray_range_rect(Image : ImageResult : MaskHeight, MaskWidth : )

calculates the gray value range, i.e., the difference (max - min) of the maximum and minimum gray values, of the input image Image within a rectangular mask of size (MaskHeight, MaskWidth) for each image point. The resulting image is returned in ImageResult. 

5. 算子

  • gray_dilation(Image, SE : ImageDilation : : )
  • gray_erosion(Image, SE : ImageErosion : : )
  • gray_opening(Image, SE : ImageOpening : : )
  • gray_closing(Image, SE : ImageClosing : : )
  • gray_tophat(Image, SE : ImageTopHat : : )
  • gray_bothat(Image, SE : ImageBotHat : : )

指定结构元SE

  • gray_dilation_rect(Image : ImageMax : MaskHeight, MaskWidth : )
  • gray_erosion_rect(Image : ImageMin : MaskHeight, MaskWidth : )
  • gray_opening_rect(Image : ImageOpening : MaskHeight, MaskWidth : )
  • gray_closing_rect(Image : ImageClosing : MaskHeight, MaskWidth : )

 

  • gray_dilation_shape(Image : ImageMax : MaskHeight, MaskWidth, MaskShape : )
  • gray_erosion_shape(Image : ImageMin : MaskHeight, MaskWidth, MaskShape : )
  • gray_opening_shape(Image : ImageOpening : MaskHeight, MaskWidth, MaskShape : )
  • gray_closing_shape(Image : ImageClosing : MaskHeight, MaskWidth, MaskShape : )

MaskShape :Shape of the mask.
Default value: 'octagon'
List of values: 'octagon'八边形,  'rectangle'矩形,  'rhombus'菱形

6. 例子

* 
* This example demonstrates the general gray morphology. "General"
* means, that any shape for the structuring elements can be used.
* The example shows how to segment the drill holes of a PCB.
* 
dev_close_window ()
read_image (Image, 'pcb_layout')
get_image_size (Image, Width, Height)
dev_open_window_fit_size (0, 0, Width, Height, 800, 700, WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_set_draw ('fill')
dev_update_off ()
dev_set_colored (6)
dev_display (Image)
disp_message (WindowHandle, 'Original image', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* We define a circle as structuring element that fits the size
* of the drill holes we are looking for.
* 
gen_image_const (ConstImage, 'byte', 11, 11)
get_image_size (ConstImage, MaskWidth, MaskHeight)
gen_circle (Circle, (MaskHeight - 1) / 2.0, (MaskWidth - 1) / 2.0, 3)
reduce_domain (ConstImage, Circle, ImageReduced)
* To allow a realistic time measurement, the operators are called once
* to load the program code into memory
gray_closing (Image, ImageReduced, ImageClosingFast)
gray_opening (Image, ImageReduced, ImageOpeningFast)
sub_image (ImageClosingFast, ImageOpeningFast, ImageSubFast, 1, 0)
* Now the execution time can be measured
count_seconds (Start)
gray_closing (Image, ImageReduced, ImageClosingFast)
gray_opening (Image, ImageReduced, ImageOpeningFast)
sub_image (ImageClosingFast, ImageOpeningFast, ImageSubFast, 1, 0)
count_seconds (End)
dev_display (ImageSubFast)
disp_message (WindowHandle, ['Subtraction of gray_closing','and gray_opening','Execution time: ' + ((End - Start) * 1000.0)$'4.2f' + ' ms'], 'window', 5, 12, 'black', 'true')
get_image_size (ConstImage, MaskWidth, MaskHeight)
dev_open_window (0, 500, 100, 100, 'black', WindowHandle1)
dev_display (ConstImage)
dev_set_draw ('margin')
dev_display (Circle)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
dev_set_window (WindowHandle1)
dev_close_window ()
dev_set_window (WindowHandle)
* 
segment_boreholes (ImageSubFast, Image, HolesFast, 80)
dev_display (Image)
dilation_circle (HolesFast, RegionDilation, 3.5)
dev_display (RegionDilation)
disp_message (WindowHandle, 'Segmentation of the larger drill holes', 'window', 12, 12, 'black', 'true')