halcon-閉運算(先膨脹后腐蝕)


 

 

 

閉運算:對區域先進行膨脹操作,然后對膨脹的結果再進行腐蝕操作,稱為閉運算
閉運算特點:具有與膨脹相似的特點,但是能夠防止區域膨脹過度,能夠很好的保持區域的形狀。

效果:能填補縫隙

closing_circle區域圓閉運算

在HDevelop中

dev_update_off()

read_image (Image, 'D:/bb/tu/3.jpg')
rgb1_to_gray(Image,Image1)

threshold (Image1, Region, 200, 230)
closing_circle (Region, RegionClosing, 3.5)
*區域圓閉運算
*參數1:要閉運算的區域
*參數2:輸出區域
*結構圓半徑


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(RegionClosing)

 

 


在Qt Creator中

    HObject  ho_Image, ho_Image1, ho_Region, ho_RegionClosing;
    HTuple  hv_Width, hv_Height, hv_WindowHandle;
    HTuple  hv_WindowHandle1;
    ReadImage(&ho_Image, "D:/bb/tu/3.jpg");
    Rgb1ToGray(ho_Image, &ho_Image1);

    Threshold(ho_Image1, &ho_Region, 200, 230);
    ClosingCircle(ho_Region, &ho_RegionClosing, 3.5);
    //區域圓閉運算
    //參數1:要閉運算的區域
    //參數2:輸出區域
    //結構圓半徑


    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_RegionClosing, HDevWindowStack::GetActive());

 

closing_rectangle1區域矩形閉運算

在HDevelop中

dev_update_off()

read_image (Image, 'D:/bb/tu/3.jpg')
rgb1_to_gray(Image,Image1)

threshold (Image1, Region, 200, 230)
closing_rectangle1 (Region, RegionClosing, 10, 10)
*區域矩形閉運算
*參數1:要閉運算的區域
*參數2:輸出區域
*結構矩形的寬和高


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(RegionClosing)

 

 在Qt Creator中

    HObject  ho_Image, ho_Image1, ho_Region, ho_RegionClosing;
    HTuple  hv_Width, hv_Height, hv_WindowHandle;
    HTuple  hv_WindowHandle1;
    ReadImage(&ho_Image, "D:/bb/tu/3.jpg");
    Rgb1ToGray(ho_Image, &ho_Image1);

    Threshold(ho_Image1, &ho_Region, 200, 230);
    ClosingRectangle1(ho_Region, &ho_RegionClosing, 10, 10);
    //區域矩形閉運算
    //參數1:要閉運算的區域
    //參數2:輸出區域
    //結構矩形的寬和高


    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_RegionClosing, HDevWindowStack::GetActive());

 

gray_closing_shape圖像閉運算 

在HDevelop中

dev_update_off()

read_image (Image, 'D:/bb/tu/3.jpg')
rgb1_to_gray(Image,Image1)

gray_closing_shape (Image1, ImageClosing, 11, 11, 'octagon')
*圖像閉運算
*參數1:要閉運算的單通道圖像
*參數2:輸出圖像
*參數3和參數4:結構矩形的寬和高
*參數5:結構元形狀
*       'octagon'    八角形
*       'rectangle'  矩形
*       'rhombus'    棱形


get_image_size (Image1, Width, Height)
dev_open_window(10,100,Width, Height,'black',WindowHandle)
dev_display(Image1)
dev_open_window(10,100,Width, Height,'black',WindowHandle1)
dev_display(ImageClosing)

 


在Qt Creator中

  HObject  ho_Image, ho_Image1, ho_ImageClosing;
  HTuple  hv_Width, hv_Height, hv_WindowHandle;
  HTuple  hv_WindowHandle1;
  ReadImage(&ho_Image, "D:/bb/tu/3.jpg");
  Rgb1ToGray(ho_Image, &ho_Image1);

  GrayClosingShape(ho_Image1, &ho_ImageClosing, 11, 11, "octagon");
  //圖像閉運算
  //參數1:要閉運算的單通道圖像
  //參數2:輸出圖像
  //參數3和參數4:結構矩形的寬和高
  //參數5:結構元形狀
  //      'octagon'    八角形
  //      'rectangle'  矩形
  //      'rhombus'    棱形


  GetImageSize(ho_Image1, &hv_Width, &hv_Height);
  SetWindowAttr("background_color","black");
  OpenWindow(10,100,hv_Width,hv_Height,0,"visible","",&hv_WindowHandle);
  HDevWindowStack::Push(hv_WindowHandle);
  if (HDevWindowStack::IsOpen())
    DispObj(ho_Image1, 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_ImageClosing, HDevWindowStack::GetActive());

 

gray_closing_rect圖像閉運算 

在HDevelop中

dev_update_off()

read_image (Image, 'D:/bb/tu/3.jpg')
rgb1_to_gray(Image,Image1)

gray_closing_rect (Image1, ImageClosing, 11, 11)
*圖像閉運算
*參數1:要閉運算的單通道圖像
*參數2:輸出圖像
*參數3和參數4:結構矩形的寬和高



get_image_size (Image1, Width, Height)
dev_open_window(10,100,Width, Height,'black',WindowHandle)
dev_display(Image1)
dev_open_window(10,100,Width, Height,'black',WindowHandle1)
dev_display(ImageClosing)

 

 


在Qt Creator中

  HObject  ho_Image, ho_Image1, ho_ImageClosing;
  HTuple  hv_Width, hv_Height, hv_WindowHandle;
  HTuple  hv_WindowHandle1;
  ReadImage(&ho_Image, "D:/bb/tu/3.jpg");
  Rgb1ToGray(ho_Image, &ho_Image1);

  GrayClosingRect(ho_Image1, &ho_ImageClosing, 11, 11);
  //圖像閉運算
  //參數1:要閉運算的單通道圖像
  //參數2:輸出圖像
  //參數3和參數4:結構矩形的寬和高



  GetImageSize(ho_Image1, &hv_Width, &hv_Height);
  SetWindowAttr("background_color","black");
  OpenWindow(10,100,hv_Width,hv_Height,0,"visible","",&hv_WindowHandle);
  HDevWindowStack::Push(hv_WindowHandle);
  if (HDevWindowStack::IsOpen())
    DispObj(ho_Image1, 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_ImageClosing, HDevWindowStack::GetActive());

 

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM