【2021亚太赛】A题第一问 图像数据预处理与实现过程

内容概述

前文链接:

内容比较齐全的原版思路: https://blog.csdn.net/weixin_43935696/article/details/121555038?spm=1001.2014.3001.5501
第一次梳理与勘误: https://blog.csdn.net/qq_44319167/article/details/121637986

  之前比赛由于时间原因,使用了Photoshop进行了图片的预处理,感觉这样不是很妥,因此进行了如下的工作

  • 进行了第一问中三张图像的预处理过程
  • 对提取出来的轮廓进一步筛选、连接,得到我们想要的轮廓
  • 对大家的疑问进行整合,对上一版本思路进行补充

1. 图1-1的预处理过程

  图片1是属于比较标准的图片,但是却有一些毛刺,会影响到最后的精确计算,所以给它执行和图2相同的预处理步骤

1.1 流程图

在这里插入图片描述

1.2 代码

* 读取文件
read_image (Image, 'Pic1_1.bmp')
dev_close_window()
get_image_size(Image, Width, Height)
dev_open_window_fit_size(0, 0, Height, Height, -1, -1, WindowHandle)
dev_display(Image)
* 灰度处理
rgb1_to_gray (Image, GrayImage)
* 预处理的一些步骤
invert_image (GrayImage, ImageInvert)
emphasize (GrayImage, ImageEmphasize, Width, Height, 1)
scale_image (GrayImage, ImageScaled1, 0.5, 0)
scale_image (GrayImage, ImageScaled2, 1, 100)
* scale_image (GrayImage, ImageScaled3, 1, -100)
* 直方图
* equ_histo_image (ImageScaled2, ImageEquHisto)
* binary_threshold (GrayImage, Region, 'max_separability', 'light', UsedThreshold)
* 亚像素边缘检测
edges_sub_pix (ImageScaled2, Edges, 'canny', 2, 25, 100)
* 二次筛选处理
select_contours_xld (Edges, SelectedContours, 'contour_length', 50, 3000, -0.5, 0.5)
union_adjacent_contours_xld (SelectedContours, UnionContours, 20 ,20, 'attr_keep')
* select_contours_xld (UnionContours, SelectedContours2, 'contour_length', 500, 10000, -0.5, 0.5)
* select_contours_xld (UnionContours, SelectedContours2, 'contour_length', 500, 3000, -0.5, 0.5)
* union_adjacent_contours_xld (SelectedContours2, UnionContours, 20 ,1, 'attr_keep')
* edges_sub_pix (ImageEquHisto, Edges, 'canny', 2, 20, 120)

1.3 效果

在这里插入图片描述

2. 图1-2的预处理过程

2.1 流程图

见图1-1的预处理过程流程图

2.2 代码

将注释改掉

2.3 效果

在这里插入图片描述

3. 图1-3的预处理过程

3.1 流程图

在这里插入图片描述

3.2 代码

read_image (Image, 'Pic1_3.bmp')
dev_close_window()
get_image_size(Image, Width, Height)
dev_open_window_fit_size(0, 0, Height, Height, -1, -1, WindowHandle)
dev_display(Image)
* 灰度处理
rgb1_to_gray (Image, GrayImage)
* 进一步预处理的一些步骤
invert_image (GrayImage, ImageInvert)
emphasize (GrayImage, ImageEmphasize, Width, Height, 1)
scale_image (GrayImage, ImageScaled1, 0.5, 0)
* scale_image (GrayImage, ImageScaled2, 1, 100)
* scale_image (GrayImage, ImageScaled3, 1, -100)
* 直方图
equ_histo_image (GrayImage, ImageEquHisto)
* binary_threshold (GrayImage, Region, 'max_separability', 'light', UsedThreshold)

* 亚像素边缘检测
edges_sub_pix (ImageEquHisto, Edges, 'canny', 2, 20, 120)

* 二次筛选处理
select_contours_xld (Edges, SelectedContours, 'contour_length', 50, 3000, -0.5, 0.5)
union_adjacent_contours_xld (SelectedContours, UnionContours, 20 ,1, 'attr_keep')
select_contours_xld (UnionContours, SelectedContours2, 'contour_length', 500, 10000, -0.5, 0.5)
* select_contours_xld (UnionContours, SelectedContours2, 'contour_length', 500, 3000, -0.5, 0.5)
* union_adjacent_contours_xld (SelectedContours2, UnionContours, 20 ,1, 'attr_keep')
* edges_sub_pix (ImageEquHisto, Edges, 'canny', 2, 20, 120)

3.3 效果

在这里插入图片描述

4. 回答部分问题

4.1 问题1

  • 怎么把检测出来的轮廓放在原图上
  • 首先点击这里清空图形窗口
    在这里插入图片描述
  • 之后先选择显示下方读取到的原图形
  • 最后再选择显示下方检测到的轮廓
    在这里插入图片描述
  • 即可得到如下图所示的效果
    在这里插入图片描述

4.2 问题2

  • 第二问出现的错误应该怎么修改

  • 第二问中按照第一版思路的做法,会讲下图中红色边缘的长度计算错误,值大概为4000多。因为多选中了一个外边框

  • 我们只需要在代码的最后一行,加入以下代码

edges_sub_pix (GrayImage, Edges2, 'canny', 2, 20, 80)

之后我们用第一问的方法即可求出轮廓的像素长度

4.3 第三问的各项指标数据如何计算

  • 这部分比较复杂,已经录制了视频,有时间会整理一版文字教程

5. 小结

  • 对之前欠缺的部分工作进行了补充,实现了图像的预处理,并对检测出的轮廓进行了进一步的操作,实现了本赛题第一问的求解。
  • 回答了大家复现实验中的几个问题
  • 类似于Photoshop中的图形学操作,也可以利用这个Halcon进行操作,时间原因本次不做演示
  • 8
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一川风絮千片雪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值