dev_set_draw的fill和margin模式

本文通过一个简单的图像处理示例,展示了不同填充模式的效果对比,包括内部填充、边缘填充及缺省填充,有助于理解如何在开发中选择合适的填充模式。

注意:分别观察两张填充模式,一种是内部填充,一种是边缘填充。还有一种缺省的填充。

Name

dev_set_draw — Define the region fill mode.

Signature

dev_set_draw( : : DrawMode : )

 

read_image(Image,'monkey')
threshold(Image,Region,128,255)
dev_display(Region)
stop()

dev_clear_window ()
dev_set_color('green')
dev_set_draw('fill')
dev_display(Region)
stop()

dev_set_color('white')
dev_set_draw('margin')
dev_display(Region)

 

 

 

 

 

 

 

* This example program applies image segmentation with an MLP * classifier to separate oranges and lemons from the background. * read_image (Image, 'color/citrus_fruits_01') get_image_pointer1 (Image, Pointer, Type, Width, Height) dev_close_window () dev_open_window (0, 0, Width, Height, 'white', WindowHandle) set_display_font (WindowHandle, 12, 'mono', 'true', 'false') dev_set_draw ('margin') dev_set_line_width (2) dev_display (Image) dev_update_window ('off') dev_update_pc ('off') dev_update_var ('off') dev_set_color ('white') * * Create an MLP classifier create_class_mlp (3, 3, 3, 'softmax', 'normalization', 10, 42, MLPHandle) * * Read a training image and add samples for the classes * 'oranges' and 'background' to the classifier read_image (Image, 'color/citrus_fruits_01') dev_display (Image) gen_rectangle1 (OrangeRegion, 100, 130, 230, 200) dev_display (OrangeRegion) disp_message (WindowHandle, 'OrangeRegion', 'window', 100, 210, 'black', 'true') dev_set_color ('white') gen_rectangle1 (BackgroundRegion, 30, 20, 50, 50) dev_display (BackgroundRegion) disp_message (WindowHandle, 'BackgroundRegion', 'window', 30, 60, 'black', 'true') dev_set_color ('white') gen_empty_region (EmptyRegion) gen_empty_obj (TrainingRegions1) concat_obj (TrainingRegions1, OrangeRegion, TrainingRegions1) concat_obj (TrainingRegions1, EmptyRegion, TrainingRegions1) concat_obj (TrainingRegions1, BackgroundRegion, TrainingRegions1) add_samples_image_class_mlp (Image, TrainingRegions1, MLPHandle) stop () * * Read a training image and add samples for the classes * 'lemons' and 'background' to the classifier read_image (Image, 'color/citrus_fruits_03') dev_display (Image) gen_rectangle1 (LemonRegion, 180, 130, 230, 240) dev_display (LemonRegion) disp_message (WindowHandle, 'LemonRegion', 'window', 180, 250, 'black', 'true') dev_set_color ('white') gen_rectangle1 (BackgroundRegion, 400, 20, 430, 50) dev_display (BackgroundRegion) disp_message (WindowHandle, 'BackgroundRegion', 'window', 400, 60, 'black', 'true') gen_empty_obj (TrainingRegions2) concat_obj (TrainingRegions2, EmptyRegion, TrainingRegions2) concat_obj (TrainingRegions2, LemonRegion, TrainingRegions2) concat_obj (TrainingRegions2, BackgroundRegion, TrainingRegions2) add_samples_image_class_mlp (Image, TrainingRegions2, MLPHandle) stop () * * Train the classifier disp_message (WindowHandle, 'Training...', 'window', 10, 450, 'black', 'true') train_class_mlp (MLPHandle, 200, 1, 0.01, Error, ErrorLog) disp_message (WindowHandle, 'completed', 'window', 30, 450, 'black', 'true') disp_continue_message (WindowHandle, 'black', 'true') dev_set_color ('white') stop () dev_set_draw ('fill') * * Segment images for I := 1 to 15 by 1 read_image (Image, 'color/citrus_fruits_' + I$'.2d') classify_image_class_mlp (Image, ClassRegions, MLPHandle, 0.5) select_obj (ClassRegions, ClassOranges, 1) select_obj (ClassRegions, ClassLemons, 2) select_obj (ClassRegions, ClassBackground, 3) dev_set_draw ('fill') dev_display (Image) dev_set_color ('slate blue') dev_display (ClassBackground) dev_set_color ('goldenrod') dev_display (ClassOranges) dev_set_color ('yellow') dev_display (ClassLemons) disp_message (WindowHandle, 'Classify Image ' + I, 'window', 10, 10, 'black', 'true') disp_continue_message (WindowHandle, 'black', 'true') stop () * * Apply a post processing closing_circle (ClassOranges, RegionClosingOranges, 3.5) connection (RegionClosingOranges, ConnectedRegionsOranges) select_shape (ConnectedRegionsOranges, SelectedRegionsOranges, 'area', 'and', 20000, 99999) fill_up (SelectedRegionsOranges, RegionFillUpOranges) area_center (RegionFillUpOranges, AreasOranges, RowsOranges, ColumnsOranges) shape_trans (RegionFillUpOranges, RegionFillUpOranges, 'convex') * closing_circle (ClassLemons, RegionClosingLemons, 3.5) connection (RegionClosingLemons, ConnectedRegionsLemons) select_shape (ConnectedRegionsLemons, SelectedRegionsLemons, 'area', 'and', 15000, 99999) fill_up (SelectedRegionsLemons, RegionFillUpLemons) area_center (RegionFillUpLemons, AreasLemons, RowsLemons, ColumnsLemons) shape_trans (RegionFillUpLemons, RegionFillUpLemons, 'convex') * dev_display (Image) dev_set_draw ('margin') dev_set_line_width (5) dev_set_color ('goldenrod') dev_display (RegionFillUpOranges) dev_set_color ('yellow') dev_display (RegionFillUpLemons) disp_message (WindowHandle, 'Classify Image ' + I + ' with Post Processing', 'window', 10, 10, 'black', 'true') disp_continue_message (WindowHandle, 'black', 'true') disp_message (WindowHandle, 'Class: oranges', 'window', RowsOranges, ColumnsOranges - 50, 'black', 'true') disp_message (WindowHandle, 'Class: lemons', 'window', RowsLemons, ColumnsLemons - 50, 'black', 'true') stop () endfor dev_clear_window () * * Clear the classifier from memory clear_class_mlp (MLPHandle) disp_message (WindowHandle, 'No more lines to execute', 'window', 10, 10, 'black', 'true')
最新发布
06-04
* IC检查 **** 1、读取图片并显示 **************************** dev_close_window () read_image (Image, './ic.png') get_image_size (Image, Width, Height) dev_open_window (0, 0, Width, Height, 'black', WindowID) dev_set_draw ('fill') dev_set_part (0, 0, Height - 1, Width - 1) dev_display (Image) dev_set_colored (12) **** 2、彩色图片 转换为hsv分量 **************************** * 彩色图片抽取 RGB decompose3 (Image, Red, Green, Blue) * RGB 转换为 HSV图片 Hue 色度 Saturation饱度 Intensity 亮度 trans_from_rgb (Red, Green, Blue, Hue, Saturation, Intensity, 'hsv') **** 3、饱度图片 获取红色矩形区域 **************************** * 使用饱度图片 红色区域 threshold (Saturation, Colored, 100, 255) * 色度图片中 聚焦红色区域 reduce_domain (Hue, Colored, HueColored) * 二值化 黑色区域(红色) threshold (HueColored, Red, 10, 19) * 连通域分析 connection (Red, RedConnect) * 挑选电阻红色标识区域 select_shape (RedConnect, RedLarge, 'area', 'and', 150.000000, 99999.000000) * 电阻外接矩形 shape_trans (RedLarge, Resistors, 'rectangle2') dev_clear_window () dev_set_draw ('margin') dev_display (Image) dev_display(Resistors) **** 4、饱度图片 获取蓝色标签区域 **************************** * 二值化 threshold (HueColored, BlueLabel, 114, 137) * 连通域分析 connection (BlueLabel, BlueConnect) * 连通域挑选(面积筛选) select_shape (BlueConnect, BlueLarge, 'area', 'and', 150.000000, 99999.000000) * 最小外接矩形 shape_trans (BlueLarge, Capacitors, 'rectangle2') **** 5、亮度图片 获取芯片主体区域 **************************** * Intensity亮度图片 暗区芯片主体 threshold (Intensity, Dark, 0, 50) * 芯片主体 矩形膨胀 dilation_rectangle1 (Dark, DarkDilation, 14, 14) * 连通域分析 connection (DarkDilation, ICLarge) * 亮度图中 每个连通域获取灰度图 add_channels (ICLarge, Intensity, ICLargeGray) * 二值化(芯片主体) threshold (ICLargeGray, ICDark, 0, 50) * 获取外接矩形 shape_trans (ICDark, IC, 'rectangle2') **** 6、芯片PIN接口区域 **************************** * 芯片区域左右膨胀 dilation_rectangle1 (IC, ICDilation, 5, 1) * 芯片左右搜索区域中心线 difference (ICDilation, IC, SearchSpace) * 搜索区域膨胀(中心线) dilation_rectangle1 (SearchSpace, SearchSpaceDilation, 14, 1) * 合并搜索膨胀区 union1 (SearchSpaceDilation, SearchSpaceUnion) * 获取搜索灰度图 reduce_domain (Intensity, SearchSpaceUnion, SearchGray) * 动态二值化 mean_image (SearchGray, SearchMean, 15, 15) dyn_threshold (SearchGray, SearchMean, PinsRaw, 5.000000, 'light') * 连通域分析 connection (PinsRaw, PinsConnect) * 填充连通域 fill_up (PinsConnect, PinsFilled) * 面积筛选 PIN select_shape (PinsFilled, Pins, 'area', 'and', 10, 100) **** 7、显示结果 **************************** * 显示IC区域 dev_display (Image) dev_set_draw ('margin') dev_set_line_width (3) dev_set_color ('red') dev_display (IC) * 显示红色矩形区域 dev_set_color ('green') dev_display (Resistors) * 显示标签 dev_set_color ('blue') dev_display (Capacitors) * 显示pin dev_set_color ('yellow') dev_display (Pins)
05-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值