- This example demonstrates the use of the operator set_shape_model_param.
// 这个例子演示了“设置形状模板的最小对比度”操作符的使用
dev_close_window ()
read_image (Image, 'rings_and_nuts')
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_set_color ('green')
/* 关闭活动窗口
读取图像
打开活动窗口
设置显示字体
dev_set_color 设置用于区域,图形或轮廓的显示颜色,该颜色也可以用于今后打开的图形窗口,它的有效时间为直到下次dev_set_color()定义的有效颜色
ColorName 有效的颜色名称,默认为‘white’ */
- First, a shape model is created from a very noisy image.
- This leads to a large value of (the automatically determined) MinContrast.
// 首先,从一个非常嘈杂的图像创建一个形状模型。
这导致(自动确定的)最小对比度值很大。
add_noise_white (Image, ImageNoise, 60)
dev_display (ImageNoise)
/* 向一个图像添加噪声
Image 输入一个需要增加噪音的图像
ImageNoise 输出一个已经增加噪音的图像
Amp 输入最大噪音振幅,默认:60.0,1.0<=Amp<=1000.0 */
gen_rectangle1 (Rectangle, 60, 60, 200, 200)
// 创建水平矩形区域,第一点Y与X,第二点Y与X
reduce_domain (ImageNoise, Rectangle, ImageReduced)
// 缩小一个图像的位置,新图像尺寸未发生变化
determine_shape_model_params (ImageReduced, 'auto', -0.39, 0.79, 0.9, 1.1, 'auto', 'use_polarity', 'auto', 'auto', 'all', ParameterName, ParameterValue)
disp_message (WindowHandle, ''Auto' MinContrast on a Noisy Image: ' + ParameterValue[7], 'window', -1, -1, 'black', 'true')
// 测定匹配模型的各项参数及对应值,显示消息
create_shape_model (ImageReduced, 'auto', -0.39, 0.79, 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID)
dev_inspect_ctrl ([ParameterName,ParameterValue])
disp_continue_message (WindowHandle, 'black', 'true')
disp_message (WindowHandle, ''Auto' MinContrast on a Noisy Image: ' + ParameterValue[7], 'window', -1, -1, 'black', 'true')
stop ()
dev_close_inspect_ctrl ([ParameterName,ParameterValue])
// 创建一个不可缩放的区域匹配模板
打开一个窗口来检查一个或多个控制变量
显示消息
关闭一个或多个控制变量的检查窗口。
- Then an image with low contrast is used as search image.
// 然后使用低对比度的图像作为搜索图像。
scale_image (Image, ImageLowContrast, 0.1, 50)
dev_display (ImageLowContrast)
disp_message (WindowHandle, 'Creating Search Image with low Contrast', 'window', -1, -1, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
// 为一个图像的灰度值分级
Image 输入图像
ImageScaled 输出灰度值分级图像
Mult 输入灰度适用值
Add 输入灰度变化值
- Find_shape_model will not be able to find an instance in ImageLowContrast
- because the edge amplitude in ImageLowContrast is below the automatically
- determined MinContrast.
- Internally, only edges with an amplitude larger than MinContrast are used.
- This corresponds to the result of edges_image with the threshold set to the
- value of MinContrast.
// Find_shape_model将无法在低对比度图像中找到实例,因为低对比度图像中的边缘振幅低于自动确定的最小对比度。在内部,只使用振幅大于最小对比度的边缘。这对应于图像边缘的结果,其阈值设置为最小对比度的值。
edges_image (ImageLowContrast, ImaAmp, ImaDir, 'sobel_fast', 0.5, 'nms', ParameterValue[7] - 20, ParameterValue[7] - 20)
// 使用滤波器提取边缘
get_domain (ImaAmp, Domain)
// 获取一个图像的区域
full_domain (ImaAmp, ImageFull)
dev_clear_window ()
dev_display (Domain)
disp_message (WindowHandle, 'Edge Amplitude of Search Image is\nbelow MinContrast of Noisy Image\n=> no Edges can be extracted', 'window', -1, -1, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
// 把一个图像的区域扩大到最大值
- With the above created shape model, no match is found in the low-contrast image
- because of the high value of MinContrast.
// 以上创建的形状模型,由于最小对比度的值较高,所以在低对比度的图像中找不到匹配
find_shape_model (ImageLowContrast, ModelID, -0.39, 0.78, 0.5, 1, 0.5, 'least_squares', 0, 0.9, Row, Column, Angle, Score)
// 搜索图像中不可缩放的单个外形匹配模型
NumMatches := |Score|
dev_display (ImageLowContrast)
dev_inspect_ctrl (NumMatches)
disp_message (WindowHandle, 'Hence, no Matches found on the Search Image', 'window', -1, -1, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
dev_close_inspect_ctrl (NumMatches)
// 打开一个窗口来检查一个或多个控制变量
关闭一个或多个控制变量的检查窗口
- If the threshold is set to a smaller value, the edges can be extracted in the low-contrast image.
// 如果阈值设置为较小的值,则可以在低对比度图像中提取边缘。
edges_image (ImageLowContrast, ImaAmp, ImaDir, 'sobel_fast', 0.5, 'nms', 5, 5)
get_domain (ImaAmp, Domain)
dev_clear_window ()
dev_display (ImageLowContrast)
dev_display (Domain)
disp_message (WindowHandle, 'Extracted Edges on Search Image\nwith Threshold lower than MinContrast', 'window', -1, -1, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
// 使用滤波器提取边缘
获取一个图像的区域
- Consequently, if MinContrast is set to a sufficiently small value, find_shape_model finds the correct match.
// 因此,如果最小对比度设置为一个足够小的值,find_shape_model将找到正确的匹配。
set_shape_model_param (ModelID, 'min_contrast', 5)
find_shape_model (ImageLowContrast, ModelID, -0.39, 0.78, 0.5, 1, 0.5, 'least_squares', 0, 0.9, Row, Column, Angle, Score)
// 设置轮廓匹配模型的参数
搜索图像中不可缩放的单个外形匹配模型
get_shape_model_contours (ModelContours, ModelID, 1)
// 提取轮廓匹配模型的外形轮廓
vector_angle_to_rigid (0, 0, 0, Row, Column, Angle, HomMat2D)
// 通过点和角度来计算一个近似的二维变换矩阵
affine_trans_contour_xld (ModelContours, ContoursAffinTrans, HomMat2D)
dev_clear_window ()
dev_display (ImageLowContrast)
dev_display (ContoursAffinTrans)
disp_message (WindowHandle, 'Change MinContrast in Shape Model to lower Threshold\n => Match found for new MinContrast', 'window', -1, -1, 'black', 'true')
clear_shape_model (ModelID)
// 对XLD轮廓进行一个任意二维仿射变换