如图,找到下面黄色的线,思路是线拆分为三通道图像然后转换称hsv颜色模型,然后根据灰度阈值删选出大致区域,裁剪出来,继续灰度阈值删选出准确黄色区域,继续裁剪得到
实现代码:
*图像处理案例找出黄色的线
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
*打开图片
read_image (Image, 'C:/Users/24771/Pictures/Saved Pictures/2.jpg')
*拆分为3通道图像
decompose3 (Image, Red, Green, Blue)
dev_display (Red)
dev_display (Green)
dev_display (Blue)
*三通道图像转换为hsv模型,
*hsv颜色模型的一种,色调(H),饱和度(S),透明度(V)。
trans_from_rgb (Red, Green, Blue, Hue, Saturation, Intensity, 'hsv')
dev_display (Hue)
dev_display (Saturation)
dev_display (Intensity)
*使用全局阈值分割图像,下面是选取灰度100到255的区域
threshold (Saturation, HighSaturation, 100, 255)
*裁剪图像
reduce_domain (Hue,HighSaturation , HueHighSaturation)
*选取灰度20到50的区域
threshold (HueHighSaturation, Yellow, 20, 50)
connection (Yellow, ConnectedRegions)
*选取最大的区域
select_shape_std (ConnectedRegions, SelectedRegions, 'max_area', 0)
* closing_circle (SelectedRegions, Yellow, 3.5)
*裁剪出黄色线图像
reduce_domain (Image, Yellow, ImageReduced)
dev_display (ImageReduced)
* dev_display (HueHighSaturation)
* dev_display (ImageReduced)
stop()