在学习halcon算子sub_image(ImageMinuend, ImageSubtrahend : ImageSub : Mult, Add : )时,在样例中遇到了一个操作
* This example demonstrates how to subtract two images * using the operator 'sub_image'. * * dev_close_window () dev_update_off () * * Read two images and convert them read_image (Scene00, 'autobahn/scene_00') read_image (Scene01, 'autobahn/scene_01') convert_image_type (Scene00, ImageConverted1, 'int2') convert_image_type (Scene01, ImageConverted2, 'int2') * * Display the input images for the subtraction dev_open_window_fit_image (ImageConverted1, 0, 0, -1, -1, WindowHandle) set_display_font (WindowHandle, 16, 'mono', 'true', 'false') dev_display (ImageConverted1) disp_message (WindowHandle, 'Image 1', 'window', 12, 12, 'black', 'true') disp_continue_message (WindowHandle, 'black', 'true') stop () dev_display (ImageConverted2) disp_message (WindowHandle, 'Image 2', 'window', 12, 12, 'black', 'true') disp_continue_message (WindowHandle, 'black', 'true') stop () * * Subtract the input images and display the resulting image sub_image (ImageConverted1, ImageConverted2, ImageSub, 1, 50) dev_display (ImageSub)
将图片的类型转换为‘int2’
convert_image_type (Scene00, ImageConverted1, 'int2') convert_image_type (Scene01, ImageConverted2, 'int2')
产生了疑惑:为什么在图像相减前要转换成这种类型?int2是什么?
在网上找了一圈,只有这个文档里的介绍比较详细
14年大恒图像培训3 halcon structure and programming
知道了int2是一种像素类型
以及各种类型的大小
至于为什么要在sub_image前进行转换还没弄清。。。
比较了一下转换和不转换做sub_image的差别:
1、将转换后的图像进行相减操作
sub_image (ImageConverted1, ImageConverted2, ImageSub, 1, 50) dev_display (ImageSub)
2、将转换前的图像进行相减操作
sub_image(Scene00,Scene01,Imagesub,1,50) dev_display(Imagesub)
另外附上网上另一篇讲解像素格式的文章:
常用像素格式
要进行图像编程的化对像素格式不了解似乎说不过去。我想应该有较多的人并不太了解,所以这里简要的介绍一下。
1. 8bit
也叫做256色模式。每个像素占一个字节, 使用调色板。调色板实际上是一个颜色表,简单的讲就是,我们有256个油漆桶(因为像素的取值范围是0到255),每个油漆桶里面漆的颜色都由红,绿,蓝(RGB)三中基本的油漆按不同比例配置而成。所以我们指定一个像素的颜色的时候只需要指定它用的第几号桶就好了。
这种模式造就了DOS时代的神奇模式—13H(320*200*256色),因为320*200*1Byte正好是16bit指针寻址能力的范围。这种模式有2的18次方种颜色(通过改变调色板实现),可以同时显示256中颜色。这模式刚刚推出的时候,有人惊呼这是人类智慧的结晶呢!也是这种模式造就了1992年WestWood的<<卡兰蒂亚传奇>>和1995年大宇资讯的<<仙剑奇侠传>>这样的经典游戏。
在Windows下硬件调色板应该极少用到,但是你可以用软件调色板来压缩你的动画,这也是在2D游戏中常用的技巧。
2. 16bit
这也是笔者最喜欢的模式。它不使用调色板。每个像素占两个字节,存储RGB值。我觉得这种像素格式的效果(同时显示颜色数)和存储量(也影响速度)取得了比较好的统一。但是如果你是写应用程序的话,我劝你不要用它。因为它的RGB值都不是整个BYTE,例如565模式(16bit的一种模式),它的RGB所占用的bit就是这样的:
RRRR RGGG GGGB BBBB
3. 24bit
每个像素有三个BYTE,分别存储RGB值,这对你来说是不是很方便?是不是太好了?可惜对我们可怜的计算机却不是,因为CPU访问奇数的地址会很费劲,而且在硬件工艺上也有很多困难(具体我也不太清楚,请做过硬件的高手指点),所以你会发现你的显卡不支持这种模式,但是你可以在自己的软件中使用。
4. 32bit
每个像素4个BYTE,分别存储RGBA,A值就是Alpha,也就是透明度,可以用像素混合算法实现多种效果,后面你就会看到。

