石鑫华视觉 发表于 2017-4-22 17:51:36

两幅图像叠加的三种方法

两幅图像叠加的三种方法有些时候可能需要叠加两幅图像,这时可以直接使用运算中的加来叠加两幅图像:两幅图像直接叠加效果图**** Hidden Message *****两幅图像直接叠加程序框图但是从上面的效果图中可以看到。如果两幅图像都比较白时,则会丢失数据。上面的是两幅8位灰度图的叠加,输出的图像仍然是8位图。而8位图像最大值为255。这时,只要两幅图像对应的像素点的值之和大于255时,就会变成全白的,也就是溢出丢失数据。例如,1图中的点灰度值为200,2图中对应点灰度值为180时,这时两个点之和为380。但是在输出的叠加图像中,只能有最大255的灰度值。可以从上面的效果图中看到,两幅图像的卡片处因为比较白,叠加后丢失了很多信息,很多都变成全白的了。一种比较有效避免这种问题的方法,就是将原始U8灰度图像转换成U16图像,然后再使用加法计算其值。再将叠加后的U16位图像转换成U8图像,这时叠加后的图像不会丢失信息。但是两幅图像的所有信息会变化。或者是先将原始的两个U8灰度图像分别除以2,这时最大值只有128,然后再叠加,这时最大值为256,会强制变成255,但时这时只会丢失1个灰度级的信息。U8转U16后叠加效果**** Hidden Message *****U8转16后叠加程序框图使用这种方法,可以对移位的位数进行控制。例如可以移位2位,这时叠加后的图像会更黑一些:U8转U16后叠加效果-移位2位下面的效果则为U8除以2以后再叠加U8除以2后再叠加效果图**** Hidden Message *****U8除以 2后再叠加程序框图当然,其实还有一些方法,如NI的范例中就还有一种叠加方法Image to EDVR。不过个人觉得不是很直接。大家有兴趣可以去研究下。NI范围的运算符下的平均值,也是转换成U16叠加后求平均值后再转换成U8的。NI范例-Image toEDVR示例程序下载:LabVIEW2014SP1**** Hidden Message *****

1104755958 发表于 2017-7-9 16:58:28

IMAQ Cast Image转换图像
转换图像,在实际使用时,还是有一定的使用价值的,可以将某种图像转换成其它指定类型的图像。例如将彩色图像转换成灰度图像,或将U8转换成U16图像。
IMAQ Cast Image转换图像函数在程序选板中的位置
IMAQCast Image转换图像函数在程序选板中的位置
IMAQ Cast Image转换图像函数功能说明与接线端
IMAQCast Image转换图像函数功能说明与接线端
转换当前的图像类型为指定(由Image Type指定)的图像类型。如果指定了查找表,由转换图像函数使用查找表转换图像。如果转换一个16位图像到8位图像,该函数执行转换的方法为:将16位的像素值右移指定数量的移位操作(16位到8位需要右移8位),然后截取剩下的8位值。
有关于转换图像的概念,可参考NI视觉概念帮助手册《NI Vision Concepts Help》。
参考下面的Casting Images转换图像表来学习该函数是如何转换像素值的,当原始图像ImageSrc的类型和图像类型Image Type参数不相同时。
Casting Images转换图像表

Image Src Type

原始图像类型
       
Image Type

图像类型
Result

结果
U8
U16I16SGL
If you provide a lookup table, thedestination pixel will have the lookup value of the source pixel. If you donot provide a lookup table, the VI copies the source value to the destinationunmodified.

如果提供了一个查找表,目标像素将赋值源像素的查找值。如果不提供查找表,该函数将源像素值不修改复制到目标像素。
U8U16I16SGL
RGBU32
Each color component of the destination isset to the source value. If the source value is greater than 255, the VI setseach color component to 255. If the source value is less than 0, the VI setseach color component to 0. If the source image has a specified bit depth, theVI uses the bit depth when performing this conversion.

目标的每个颜色分量设置为源值。如果源值大于255,则该函数将每个颜色分量设置为255。如果源值小于0,则将每个颜色分量设置为0。如果源图像具有指定的位深度,该函数使用指定位深度在执行此转换时。
U8U16I16SGL
HSLU32
The VIsets the luminance component of the destination to the source value. If thesource value is greater than 255, the VI sets the luminance to 255. If thesource value is less than 0, the VI sets the luminance to 0. The VI sets hueand saturation component of the destination to 0. If the source image has aspecified bit depth, the VI uses the bit depth when performing thisconversion.

函数将目标的亮度分量设置为源值。如果源值大于255,则函数将亮度设置为255。如果源值小于0,则函数将亮度设置为0。函数将目标的色调和饱和度分量设置为0。如果源图像具有指定的位深度,该函数使用指定位深度在执行此转换时。
U8U16I16SGL
CSG
The VI sets the real component of thedestination to the source value. The VI sets the imaginary component of thedestination to 0.

函数设置目标的实部分量为源值。函数设置目标的虚部为0。
U16I16
U8
The VI shifts the source value to theright by the given shift value (divides each source pixel value by 2^shift )and stores the value in the destination. If the shifted value is greater than255, the VI sets the destination value to 255. If the shift value is zero,the VI uses the specified bit depth of the source image.

函数将源值右移指定的位数N(右移N位即为除以2的N次方,N为移动位数),并将其存储该移位后的值在目标里。如果右移后的值大于255,则函数将目标值设置为255。如果移位值为零(N为0),则函数使用源图像的指定位深度。
image3.gifU16I16SGL
RGBU64
Each color component of thedestination is set to the source value. If the source value is greater than65535, the VI sets each color component to 65535. If the source value is lessthan 0, the VI sets each color component to 0.

目标的每个颜色分量设置为源值。如果源值大于65535,则该函数将每个颜色分量设置为65535。如果源值小于0,则将每个颜色分量设置为0。
RGBU64
U8
The VI shifts the source value to the 8-bit range using the specifiedbit depth of the source image. Then the VI sets the destination value tothe average of the three color components of the source.

该函数使用指定位深度源图像将其源值转换为8位范围(应该是每个颜色分量都使用右移,NI没有介绍)。然后将目标值设置为转换后源值的三个颜色分量的平均值。
RGBU64
U16I16SGL
The VI sets the destinationvalue to the average of the three color components of the source. If theaverage of the source color components is out of the range of thedestination, the VI coerces the average to the range.

函数将目标值设置为源值的三个颜色分量的平均值的。如果源值的颜色分量平均值超出目标范围,函数强制转换平均值到范围内。
RGBU64
RGBU32
The VIshifts the source value to the 8-bit range using the specified bit depth ofthe source image. Then the VI sets each color component in the destinationvalue to the corresponding component in the source value.

函数使用指定位深度的源图像将其源值转换为8位范围。然后,将目标值中的每个颜色分量设置为源值中的相应分量。
RGBU64
HSLU32
The VI shiftsthe source value to the 8-bit range using the specified bit depth of thesource image. Then the VI converts each pixel from the RGB color space to theHSL color space.

函数使用指定位深度的源图像将其源值转换为8位范围。然后函数转换每个像素的RGB颜色空间到HSL颜色空间。
U16I16
SGL
If you provide a lookup table, thedestination pixel will have the lookup value of the source pixel. If you donot provide a lookup table, the VI copies the source value to the destinationunmodified.

如果提供了一个查找表,目标像素将由源像素的查找值赋值。如果不提供查找表,该函数将未修改的源值复制到目标中。
SGL
U8U16I16
The VIsets the destination value to the source value. If the source value is out ofthe range of the destination, the VI coerces the source to the range.

函数将目标值设置为源值。如果源值超出目标的范围,函数强制转换到范围内。
RGBU32
U8U16I16SGL
The VI sets the destination value to the average of the three color componentsof the source.

函数将目标值设置为源值三个颜色分量的平均值。
RGBU32
HSLU32
The VI converts each pixel from the RGBcolor space to the HSL color space.

函数转换每个像素的RGB颜色空间到HSL颜色空间。
RGBU32RGBU64
CSG
The VIsets the real portion of the destination value to the average of the threecolor components of the source, and it sets the imaginary portion of thedestination to 0.

函数将目标值的实部设置为源值三个颜色分量的平均值,并将目标值的虚部设置为0。
HSLU32
U8U16I16SGL
The VI sets the destinationvalue to the luminance component of the source value.

函数设置目标值为源值的亮度分量。
HSLU332
RGBU32RGBU64
The VI converts each pixel from the HSLcolor space to the RGB color space.

函数转换每个像素的HSL颜色空间为RGB颜色空间。
HSLU32
CSG
The VI sets the real portion of thedestination value to the value of the luminance component of the source, andit sets the imaginary portion of the destination to 0. If the source value isout of the range of the destination, the VI coerces the source to the range.

函数将目标值的实部设置为源值亮度分量的值,将目标的虚部设置为0。如果源值超出目标的范围,范围强制转换到范围内。
CSG
U8U16I16SGL
The VIsets the destination value to the magnitudeof the source value. If the source value is out of the range of thedestination, the VI coerces the source to the range.

函数将目标值设置为源值的模(复数的向量长度、大小或绝对值)。如果源值超出目标的范围,函数强制转换到范围内。
CSG
RGBU32RGBU64
The VI sets each color component of thedestination value to the magnitude of the source value. If the source valueis out of the range of the destination, the VI coerces the source to therange.

函数设置目标的每个颜色分量为源值的模。如果源值超出目标的范围,函数强制转换到范围内。
CSG
HSLU32
The VI sets the luminance component of thedestination value to the magnitude of the source value, and it sets the hueand saturation components to 0.

函数设置目标的亮度分量为源值的模,并且设置色调和饱和度分量为0。
CSG
I16
The VI sets the destination value to thesource value. If the source value is out of the range of the destination, theVI coerces the source to the range.

函数设置目标值为源值。如果源值超出目标值范围,函数强制转换源值到范围内。
CSG
U16
The VI sets the destination value to thesource value. If the source value is out of the range of the destination, theVI coerces the source to the range.

函数设置目标值为源值。如果源值超出目标值范围,函数强制转换源值到范围内。
下面看一下具体的实例效果:
本帖隐藏的内容

Cast Image转换图像程序框图
7 z8 b) _r8 v. Z4 I- @7 I
Cast Image转换图像程序框图
Cast Image转换图像实例效果-将RGB32彩色图像转换为U8灰度图像
Cast Image转换图像实例效果-将RGB32彩色图像转换为U8灰度图像
Cast Image转换图像实例效果-将RGB32彩色图像转换为HSL32图像
Cast Image转换图像实例效果-将RGB32彩色图像转换为HSL32图像
转换函数比较少用到实际项目中,如果是需要将彩色图像转换为灰度图像,一般使用抽取颜色平面即可,而且还可选择抽取哪个平面特征能最佳。所以,其实际作用并不是很明显。当然,如果是使用16位的图像,那么在某些时候可能必须要转换成8位的图像才可以处理,这里就有应用的价值了。
另外就是,有些图像,抽取其HSL空间是会有优势一点,这样就要将图像显示为HSL。而一般的相机输出的都是RGB图像,这时就需要使用该函数,将RGB空间转换成HSL空间。

158545614 发表于 2019-2-1 08:39:21

石鑫华视觉网http://shixinhua.com,工业相机、工业镜头、机器视觉光源、光源控制器、图像处理、系统集成服务商

btlec0553 发表于 2017-4-24 10:50:02

学习中,感谢

Moses 发表于 2017-6-2 11:16:42

謝謝知識分享~~ 受教囉

tony_ji 发表于 2017-6-16 17:08:38

11111111111111111

zs003048 发表于 2017-6-18 06:48:02

学习了。。。。。。。。。。。。

慕阿拂 发表于 2017-6-21 10:32:38

谢谢分享,好好学习

Trevorsong 发表于 2017-7-2 14:08:40

的点点滴滴多多多多多

蓝色希望 发表于 2017-7-10 00:59:09

学习........谢谢!

caifeng0404 发表于 2017-7-13 10:52:42

学习学习      
页: [1] 2 3 4 5 6 7 8 9 10
查看完整版本: 两幅图像叠加的三种方法

LabVIEW HALCON图像处理入门教程(第二版)
石鑫华机器视觉与LabVIEW Vision图像处理PDF+视频教程11种全套
《LabVIEW Vision函数实例详解》教程-NI Vision所有函数使用方法介绍,基于NI VISION2020,兼容VDM21/22/23