设为首页 加入收藏

TOP

halcon/c++接口基础 之 HALCON图像变量类(三)
2016-09-03 16:03:00 】 浏览:1355
Tags:halcon/c 接口 基础 HALCON 图像 变量
。暗的像素通过应用算子<= 选取。所有的像素不超过均值-3的都选取。 具体可以参考 dyn_threshold.

Pixel Values

HPixVal被用来访问类HImage的像素值。灰度值可以独立于他们的类型而返回和设置。
如下介绍常见的成员函数:

//构造
HPixVal(void)
Default constructor. 
HPixVal(const HComplex &Val)
Constructing a pixel value from a complex number. 
HPixVal(int Val)
Constructing a pixel value from an integer (int). 
HPixVal(long Val)
Constructing a pixel value from a long (long). 
HPixVal(HByte Val)
Constructing a pixel value from a byte (byte). 
HPixVal(double Val)
Constructing a pixel value from a double (double). 
HPixVal(const HPixVal &Val)
Copy constructor. 
HPixVal &operator = (const HPixVal &grey)
Assignment operator. 
operator HByte(void) const
Converting a pixel value to byte (0 … 255). //强制转换
operator int(void) const
Converting a pixel value to int. 
operator long(void) const
Converting a pixel value to long. 
operator double(void) const
Converting a pixel value to double. 
operator HComplex(void) const
Converting a pixel value to Complex. 

例4

#include "HalconCpp.h"
#include "HIOStream.h"
#if !defined(USE_IOSTREAM_H)
using namespace std;
#endif
using namespace Halcon;

void  main()
{
    HByteImage  in("E:\\halcon\\images\\mreut.png");         // Aerial image
    HWindow w;                       // Output window
    in.Display(w);                   // Displaying the image
    HByteImage out = in;             // Copying the image
    int  width = out.Width();       // Width of the image
    int  height = out.Height();      // Height of the image
    long end = width * height;    // Number of pixel of the image

    // 1. run: linear accessing
    for (long k = 0; k < end; k++) {
        int pix = in.GetPixVal(k);     // Reading the pixel
        out.SetPixVal(k, 255 - pix);      // Setting the pixel
    }
    // Displaying the transformation
    cout << "Transformed !" << endl;  out.Display(w);   w.Click();
    cout << "Original !" << endl;  in.Display(w);    w.Click();

    // 2. run: accessing the image via the coordinates (x,y)
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            int pix = in.GetPixVal(x, y); // Reading the pixel
            out.SetPixVal(x, y, 255 - pix);  // Setting the pixel
        }
    }
    // Displaying the transformation
    cout << "Transformed !" << endl;  out.Display(w);   w.Click();
    cout << "Original !" << endl;  in.Display(w);    w.Click();
}

类HPixVal可以由上面的例子(图像取反)说明。 输入图像是一个灰度图像。首先一幅图像被复制,并且获得了图像大小。第一次运行,像素线性获得。第二次运行像素值通过(x,y)坐标获得。

点评: 本例的实质是观察int与HPixVal的隐式转换。首先SetPixVal的第三个参数应该是HPixVal,但是输入实际上是int,由于类HPixVal提供了HPixVal(int Val)的构造函数,使得隐式转换可以成功。后面GetPixVal获取像素,又由于类HPixVal提供了operator int(void) const的转换函数,使得int pix = in.GetPixVal(k);是有效的。

Image Arrays

同之前定义region的数组,HImage也定义了其数组,即HImageArray.
成员函数如下:

 HImageArray(void) Default constructor: empty array, no element. HImageArray(const HImage ) Constructing an image array from a single image. HImageArray(const HImageArray &arr) Copy constructor. ~HImageArray(void) Destructor. HImageArray &operator = (const HImageArray &arr) Assignment operator. long Num(void) const Returning the number of elements in the array. HImage const &operator [] (long index) const Reading the element i of the array. The index is in the range 0 … Num()  1. HImage &operator [] (long index) Assigning an image to the element i of the array. The index index can be ≥ Num(). HImageArray operator () (long min, long max) Selecting a subset between the lower min and upper max index. HImageArray &Append(const HImage &image) Appending another image to the image array. HImageArray &Append(const HImageArray &images) Appending another image array to the image array. 

Byte Image

对于每一个像素类型,存在着从HImage继承的图像类,如对于像素类型byte(standard 8 bit),对应着HByteImage;对于像素类型int2(signed 16 bit),对应着HInt2Image。但是使用最广泛的是HByteImage,基本上覆盖了图像处理的大部分领域。HByteImage相对于HImage的优点是简化了像素值的访问机制。主要是因为HPixVal不再使用。除了HImage的成员函数外,HByteImage还包含了以下扩展:


像素的设置和获得

HByte &operator[] (long k)
线性设置第k个像素 HByte operator[] (long k) const
线性读取第k个像素 HByte &operator() (long k)
线性设置第k个像素 HByte operator() (long k) const
线性读取第k个像素 HByte &operator()(int x, int y)
通过坐标(x,y)设置像素 HByte operator()(int x, int y) const
阅读坐标(x,y)处的像素

位运算

HByteImage operator & (int i)
与i与运算 HByteImage operator << (int i)
每个像素做左移i位. HByteImage operator >> (int i)
每个像素
首页 上一页 1 2 3 4 下一页 尾页 3/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C++中的智能指针 下一篇C/C++中【提高程序效率的9个简单..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目