使用labview读取一副位图,并进行BCG校准(或修改其BCG)程序解析

进行图像处理第一步肯定就是要读取一副图片,然后再进行图像的BCG校准。

首先讲解一下用到的函数第一个函数为IMAQ Create,位于  视觉与运动--Vision Utilities---Image Management---IMAQ create

函数如图,对于如何看函数功能,还是需要看帮助说明。其帮助说明如下图

Creates a temporary memory location for an image. Use IMAQ Create in conjunction with the IMAQ Dispose VI to create or dispose of NI Vision images in LabVIEW.

这一句为对次函数的功能描述,创建一个为图片创建一个缓冲空间,用于存放该图片,读取图片均是从这个缓冲区读出,若该缓存区的图片发生变化,则读取的图片也发生变化。所以如果要是两个读取同一缓存区的话,就要考虑该缓存区的图片是否发生变化。若要撤销该缓存区,使用IMAQ Dispose VI。这两个一般成对出现。

然后看每个输入参数的功能描述

第一个输入参数为边界大小设定,默认值是3,可以根据需要来调整边界。说明中说,该边界不会随图像存到文件中。

Image Name is the name associated with the created image. Each image created must have a unique name.

第二个输入参数为图像名字,此名字唯一标识该图像。

第三个输入参数为图像的类型,并对图像类型进行了说明,示例中的图像为8bit的位图。若是彩色图像则应选择RGB的图像类型。

(尝试中若输入是一个彩色图像,选择图像类型为8bit时,显示样式为一个灰度图)

 

New Image is the Image reference that is supplied as input to all subsequent (downstream) functions used by NI Vision. Multiple images can be created in a LabVIEW application.

输出参数为新图像,用于为下面的函数提供函数连接。

第二个函数为IMAQ Readfile 位于视觉与运动---Vision Utilities----Files

Reads an image file. The file format can be a standard format (BMP, TIFF, JPEG, JPEG2000, PNG, and AIPD) or a nonstandard format known to the user. In all cases, the read pixels are converted automatically into the image type passed by Image.

该函数的功能为读取一个图像文件,这个文件的格式可以是标准格式(BMP,TIFF,JPEG等),也可以是非标准格式的图像,非标准格式的图像就要根据File Options,进行配置。

下面对每个输入输出参数进行说明,取自函数帮助文档里。

File Path is the complete pathname, including drive, directory, and filename, of the file to read.

第一个参数为File Path,文件路径,即为所要导入图像的路径。

Image is a reference to the image to which data from the image file is applied.

第二个参数为图像的引用,可用于该图像的引用。可以理解为指向该图像的指针。

Load Color Palette? (No) determines whether to load the color table present in the file, if the color table exists. If loaded, this table is read and returned by the output Color Palette. The default is FALSE. 

第三个参数,询问是否加载颜色调色板的数据,如果加载将在输出端子Color Palette输出颜色数组。

File Options is a cluster of user-optional values that you can use to read nonstandard file formats. The structure must be known to the user. 

第四个参数为文件选择项,这个为导入一个自定义的图片时使用,一般我们使用的都是标准的图片,不需要设置该参数。

Color Palette out contains the RGB color table (if the file has one) read from the file when the user passes the value TRUE for the input Load Color Palette? (No).

第一个输出参数,颜色调色板的输出,RGB颜色的表格。在输入端子Load Color Palette? 为真时才有输出。

Image Out is a reference to the destination image. If Image Dst is connected, Image Dst Out is the same as Image Dst. Otherwise, Image Dst Out refers to the image referenced by Image Src

第二个输出参数为图像的输出引用。下面的说明很有用,如果Image Dst这个端子连接,则Image Dst Out的输出引用同Image Dst,否则,指代的是 Image Src的输出引用。比如说下面我们用到的函数就有Image Dst  Image Dst Out端子,如图。当遇到是否要替换掉原始缓存区的图像时需要考虑该点。

File Type out indicates the file type that is read. This string returns an identifier of the file format, which can be BMP, TIFF, JPEG, PNG, or AIPD (internal file format). File Type returns xxx if the file format is unknown. 

第三个输出参数为文件类型输出,比如例子中用到的文件为BMP文件,则输出为BMP。

File Data Type out indicates the pixel size defined in the header for standard image file types. File Options are not necessary for reading standard image files. For other types of image files, the returned values are passed from File Options/File Data Type

第四个输出参数为文件数据类型输出,表示的是定义在标准图像文件类型的像素大小。在程序运行时输出为3不知何意?

 使用这两个函数就可以将图像显示出来,程序和效果如下图。

使用这两个函数就可以将图像读出来了,注意一点是需要在图像显示控件上右击选择snapshot(快照),不然图片运行之后会被清除掉。

下面学习第三个函数IMAQ BCGLookup,该函数位于视觉与运动--Image Processing--IMAQ BCGLookup.

Applies a brightness, contrast, and gamma correction to an image. The correction is performed by computing and applying a lookup table. Brightness, Contrast, and Gamma control the changes made to the transfer function represented by the lookup table.

该函数功能是应用亮度,对比度,伽马校正图像,使用的方法是查表法,增加图像的对比效果
伽玛校正(Gamma Correction),对图象的伽玛曲线进行编辑,以对图象进行非线性色调编辑的方法。
(Gamma Correction,伽玛校正):所谓伽玛校正就是对图像的伽玛曲线进行编辑,以对图像进行非线性色调编辑的方法,检出图像信号中的深色部分和浅色部分,并使两者比例增大,从而提高图像对比度效果。计算机绘图领域惯以此屏幕输出电压与对应亮度的转换关系曲线,称为伽玛曲线(Gamma Curve)。
对比度只是增加画面的黑白对比,也就是说,亮的地方更亮,暗的地方更暗。
下面对其参数进行说明
第一个输入参数为BCG值,BCG分别是brightness,contrast 和gamma的首字母。这个元素为一个簇元素,里面分别是这三个量的值。详细每个量的说明看说明。

Image Src is a reference to the source image.

第二个输入参数为图像的引用。

Image Mask is an 8-bit image that specifies the region of the small image that will be copied. Only pixels in the Image Src (Small) image that correspond to a non-zero pixel in the mask image are copied. All other pixels keep their original values. The entire image is processed if Image Mask is not connected. 

第三个输入参数为图像掩膜,输入为掩膜图像的引用。

图像掩模 。英文: image masking,image mask 。释文: 用选定的图像、图形或物体,对待处理的图像(全部或局部)进行遮挡,来控制图像处理的区域或处理过程。用于覆盖的特定图像或物体称为掩模或模板。光学图像处理中,掩模可以是胶片、滤光片等。数字图像处理中,掩模为二维矩阵数组,有时也用多值图像。数字图像处理中,图像掩模主要用于:①提取感兴趣区,用预先制作的感兴趣区掩模与待处理图像相乘,得到感兴趣区图像,感兴趣区内图像值保持不变,而区外图像值都为0。②屏蔽作用,用掩模对图像上某些区域作屏蔽,使其不参加处理或不参加处理参数的计算,或仅对屏蔽区作处理或统计。③结构特征提取,用相似性变量或图像匹配方法检测和提取图像中与掩模相似的结构特征。④特殊形状图像的制作。

Image Dst is a reference to the destination image.

第四个输入参数为目的图像的引用。经过BCG校准之后的图像存放的缓存区。

Image Dst Out is a reference to the destination image. If Image Dst is connected, Image Dst Out is the same as Image Dst. Otherwise, Image Dst Out refers to the image referenced by Image Src.

第一个输出参数为目的图像的输出。

这个程序为利用上述的三个函数完成图像的BCG校准程序。

程序的显示效果图,通过更改BCG Values来改变对比度,亮度和伽马值。从而增加图像的对比度。
其中不明白的地方就是图像掩膜的使用,继续努力。
对于图像掩膜的含义见网页http://blog.csdn.net/meng4411yu/article/details/10033325

 如何获得8bit的位图,在图像保存时需要选择保存类型,如下图是在画图工具保存一张照片时可以有的图片类型

 

原文地址:https://www.cnblogs.com/yuexinzheng1989/p/4440040.html