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