* 此示例程序显示了运算符compare_obj的用法。
* 特别是,它显示了 compare_obj 和 test_equal_obj 之间的区别,compare_obj 比较对象的实际内容,而 test_equal_obj 比较图像和 XLD 在内存中的位置。
* compare_obj——比较实际内容是否一致
* test_equal_obj——比较内存地址是否一致(当为Region类型对象时,效果同compare_obj)
*compare_obj——比较相似内容过程中,通过设置参数epsilon来管控相似图像结果判断
dev_update_off ()
*
* 读取输入图像
read_image (Images, ['particle','particle','monkey'])
select_obj (Images, Image1, 1)
select_obj (Images, Image2, 2)
select_obj (Images, Image3, 3)
*
TextColor := ['red','green']
TestObjectIndices := [1,1,1,2,1,3]
*比较图像显示在一起
disp_compared_images (Images, TestObjectIndices, Row1, Column1, WindowHandle)
disp_message (WindowHandle, 'compare_obj compares images pixelwise.\ntest_equal_obj only checks the location in memory.', 'window', 12, 12, 'black', 'true')
*
*
* 测试同一对象是否相等
*test_equal_obj 和 compare_obj 的结果均为 1。
test_equal_obj (Image1, Image1, EqualObj)
compare_obj (Image1, Image1, 0, CompareObj)
disp_message (WindowHandle, 'test_equal_obj = ' + EqualObj, 'image', Row1[1] + 150, Column1[1] + 600, TextColor[EqualObj], 'false')
disp_message (WindowHandle, 'compare_equal_obj = ' + CompareObj, 'image', Row1[1] + 250, Column1[1] + 600, TextColor[CompareObj], 'false')
*
*
* 测试具有相同内容的两个不同对象。
* 运算符的结果不同。test_equal_obj返回两个对象位于内存中不同位置的信息,而compare_obj告诉用户图像内容是相同的。
test_equal_obj (Image1, Image2, EqualObj)
compare_obj (Image1, Image2, 0, CompareObj)
disp_message (WindowHandle, 'test_equal_obj = ' + EqualObj, 'image', Row1[3] + 150, Column1[3] + 600, TextColor[EqualObj], 'false')
disp_message (WindowHandle, 'compare_equal_obj = ' + CompareObj, 'image', Row1[3] + 250, Column1[3] + 600, TextColor[CompareObj], 'false')
*
* 测试具有不同内容的两个不同对象
test_equal_obj (Image1, Image3, EqualObj)
compare_obj (Image1, Image3, 0, CompareObj)
disp_message (WindowHandle, 'test_equal_obj = ' + EqualObj, 'image', Row1[5] + 150, Column1[5] + 600, TextColor[EqualObj], 'false')
disp_message (WindowHandle, 'compare_equal_obj = ' + CompareObj, 'image', Row1[5] + 250, Column1[5] + 600, TextColor[CompareObj], 'false')
*
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* For regions, both operators compare the content.
*
threshold (Image1, Region1, 128, 255)
threshold (Image1, Region2, 128, 255)
threshold (Image3, Region3, 210, 255)
concat_obj (Region1, Region2, Regions)
concat_obj (Regions, Region3, Regions)
disp_compared_regions (Regions, TestObjectIndices, Row1, Column1, WindowHandle)
disp_message (WindowHandle, 'For regions, the results of both operators are identical.', 'window', 12, 12, 'black', 'true')
*
* 测试同一区域对象是否相等
*test_equal_obj 和 compare_obj 的结果均为 1。
test_equal_obj (Region1, Region1, EqualObj)
compare_obj (Region1, Region1, 0, CompareObj)
disp_message (WindowHandle, 'test_equal_obj = ' + EqualObj, 'image', Row1[1] + 150, Column1[1] + 600, TextColor[EqualObj], 'false')
disp_message (WindowHandle, 'compare_equal_obj = ' + CompareObj, 'image', Row1[1] + 250, Column1[1] + 600, TextColor[CompareObj], 'false')
*
*
** 测试具有相同内容的两个不同区域对象。
* 对于区域Regions运算符的结果相同
*test_equal_obj和compare_obj均为结果1。
test_equal_obj (Region1, Region2, EqualObj)
compare_obj (Region1, Region2, 0, CompareObj)
disp_message (WindowHandle, 'test_equal_obj = ' + EqualObj, 'image', Row1[3] + 150, Column1[3] + 600, TextColor[EqualObj], 'false')
disp_message (WindowHandle, 'compare_equal_obj = ' + CompareObj, 'image', Row1[3] + 250, Column1[3] + 600, TextColor[CompareObj], 'false')
*
* 测试具有不同内容的两个不同对象,结果值为0
test_equal_obj (Region1, Region3, EqualObj)
compare_obj (Region1, Region3, 0, CompareObj)
disp_message (WindowHandle, 'test_equal_obj = ' + EqualObj, 'image', Row1[5] + 150, Column1[5] + 600, TextColor[EqualObj], 'false')
disp_message (WindowHandle, 'compare_equal_obj = ' + CompareObj, 'image', Row1[5] + 250, Column1[5] + 600, TextColor[CompareObj], 'false')
*
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* When comparing images (or XLDs) with compare_obj,
* small changes of the gray values of a pixel (or
* the row or column coordinates of the XLD points)
* are tolerated up to the value of the parameter
* Epsilon.
* 将图像(或 XLD)与compare_obj进行比较时,像素的灰度值(或 XLD 点的行或列坐标)的微小变化是可以容忍的,直到参数 Epsilon 的值。
add_noise_white (Image1, ImageNoise15, 15)
add_noise_white (Image1, ImageNoise30, 30)
concat_obj (Image1, ImageNoise15, ImagesNoise)
concat_obj (ImagesNoise, ImageNoise30, ImagesNoise)
disp_compared_images (ImagesNoise, TestObjectIndices, Row1, Column1, WindowHandle)
disp_message (WindowHandle, '当将图像与compare_obj进行比较时,使用参数 Epsilon 可以容忍微小的变化.', 'window', 12, 12, 'black', 'true')
*
*
* Compare similar but not identical images using Epsilon
*使用Epsilon参数比较相似,但内容不同图像
*
* a) 相同图像内容对象,epsilon值不同,结果反馈也是一致的
compare_obj (Image1, Image1, 0, CompareObjEps0)
compare_obj (Image1, Image1, 20, CompareObjEps20)
disp_message (WindowHandle, 'compare_equal_obj ', 'image', Row1[1] + 050, Column1[1] + 600, 'white', 'false')
disp_message (WindowHandle, ' with Epsilon = 0: ' + CompareObjEps0, 'image', Row1[1] + 150, Column1[1] + 600, TextColor[CompareObjEps0], 'false')
disp_message (WindowHandle, ' with Epsilon = 20: ' + CompareObjEps20, 'image', Row1[1] + 250, Column1[1] + 600, TextColor[CompareObjEps20], 'false')
*
* b) 图像内容有2015个灰度像素值差异;epsilon值为0表示不启用,反馈结果为0,存在差异
compare_obj (Image1, ImageNoise15, 0, CompareObjEps0)
compare_obj (Image1, ImageNoise15, 20, CompareObjEps20)
disp_message (WindowHandle, 'compare_equal_obj (Noise = 15):', 'image', Row1[3] + 050, Column1[3] + 600, 'white', 'false')
disp_message (WindowHandle, ' with Epsilon = 0: ' + CompareObjEps0, 'image', Row1[3] + 150, Column1[3] + 600, TextColor[CompareObjEps0], 'false')
disp_message (WindowHandle, ' with Epsilon = 20: ' + CompareObjEps20, 'image', Row1[3] + 250, Column1[3] + 600, TextColor[CompareObjEps20], 'false')
*
* b)图像内容有30个灰度像素值差异
compare_obj (Image1, ImageNoise30, 0, CompareObjEps0)
compare_obj (Image1, ImageNoise30, 20, CompareObjEps20)
disp_message (WindowHandle, 'compare_equal_obj (Noise = 30):', 'image', Row1[5] + 050, Column1[5] + 600, 'white', 'false')
disp_message (WindowHandle, ' with Epsilon = 0: ' + CompareObjEps0, 'image', Row1[5] + 150, Column1[5] + 600, TextColor[CompareObjEps0], 'false')
disp_message (WindowHandle, ' with Epsilon = 20: ' + CompareObjEps20, 'image', Row1[5] + 250, Column1[5] + 600, TextColor[CompareObjEps20], 'false')
*