膨脹特點:對於填補圖像分割后物體的空洞以及區域邊界的凹陷區域具有很好的效果
膨脹分類:根據膨脹結構元的形狀,在halcon中分為圓形膨脹以及矩形膨脹等
1.jpg
膨脹原理看視頻:https://www.bilibili.com/video/BV1rS4y1g7sf/
在HDevelop中
dev_update_off() read_image (Image, 'D:/bb/tu/1.jpg') rgb1_to_gray(Image,Image1) *將RGB圖像轉換為灰度圖像 threshold (Image1, Region, 200, 230) dilation_circle (Region, RegionDilation, 3.5) *圓形膨脹 *參數1:需要膨脹的區域 *參數2:輸出區域 *參數3:結構元大小 get_image_size (Image1, Width, Height) dev_open_window(10,10,Width, Height,'black',WindowHandle) dev_display(Region) dev_open_window(10,100,Width, Height,'black',WindowHandle1) dev_display(RegionDilation)
在QtCreator中
HObject ho_Image, ho_Image1, ho_Region, ho_RegionDilation;
HTuple hv_Width, hv_Height, hv_WindowHandle;
HTuple hv_WindowHandle1;
ReadImage(&ho_Image, "D:/bb/tu/1.jpg"); Rgb1ToGray(ho_Image, &ho_Image1); //將RGB圖像轉換為灰度圖像 Threshold(ho_Image1, &ho_Region, 200, 230); DilationCircle(ho_Region, &ho_RegionDilation, 3.5); //圓形膨脹 //參數1:需要膨脹的區域 //參數2:輸出區域 //參數3:結構元大小 GetImageSize(ho_Image1, &hv_Width, &hv_Height); SetWindowAttr("background_color","black"); OpenWindow(10,10,hv_Width,hv_Height,0,"visible","",&hv_WindowHandle); HDevWindowStack::Push(hv_WindowHandle); if (HDevWindowStack::IsOpen()) DispObj(ho_Region, HDevWindowStack::GetActive()); SetWindowAttr("background_color","black"); OpenWindow(10,100,hv_Width,hv_Height,0,"visible","",&hv_WindowHandle1); HDevWindowStack::Push(hv_WindowHandle1); if (HDevWindowStack::IsOpen()) DispObj(ho_RegionDilation, HDevWindowStack::GetActive());