In Halcon/c++, Hobject is a base class that can represent an image variable. In addition, there are three kinds of inherited from Hobject. Class Himage processing Image Class Hregion processing region class HXLD processing polygon
Regions
A region is a collection of image plane coordinate points. Such an area does not need to be connected, and there may be many holes. A region can be larger than the actual image. Regions can be implemented in Halcon by so-called stroke codes. The class Hregion represents an area in the halcon/c++. The member functions of the hregion are as follows (enumerating several important): Hregion (void)
The default constructor. Create an empty region, that is, the area of the region is 0. Not all operators can use null region as input parameters, such as some shape property operations. Hregion (const hregion ®)
Copy constructor Hregion &operator = (const hregion ®)
Assignment operator void Display (const hwindow &w) const
Output region in a window
Geometric transformations of Regions hregion operator * (double scale) const
Shrink the area to any one scale. Shrink Center for (0,0) hregion operator + (const HDPOINT2D &point) const
Hregion &operator + = (const HDPOINT2D &point)
Translation
Morphological processing of the area: hregion operator >> (double radius) const
hregion &operator >>= (double radius) &nb Sp The
is corroded with a circle, with erosion_circle hregion operator << (double radius) const
Hregion &operator <<= (do uble radius)
with a circle, with Dilation_circle. Hregion &operator + + (void)
expands with a cross that contains five dots. Hregion &operator -- (void)
Corrode with a cross that contains five dots. Hregion operator + (const hregion ®) const
Hregion &operator + = (const hregion ®)
with another A region of Minkowsky tax, with MINKOWSKI_ADD1. Hregion operator-(const hregion ®) const
Hregion &operator-= (const hregion ®)
with another A region of Minkowsky subtraction, with Minkowski_sub1.
Properties of the Zone: Double Phi (void) const
An equivalent ellipse of angle, with Elliptic_axis. Double Ra (void) const
An area of the equivalent ellipse of the long half axis, with Elliptic_axis. Double Rb (void) const
A short half axis of the equivalent ellipse of an area, with Elliptic_axis. Long area (void) const
The area of the area, that is, the number of pixels included, see area_center. Double X (void) const
Double Y (void) const
The center point coordinates of the area, see Area_center. HRectangle1 SmallestRectangle1 (void) const
The smallest bounding box of the area, this bounding box is parallel to the axis, with Smallest_rectangle1. Hbool in (const HDPOINT2D &p) const
Check whether a point is within the region, with Test_region_point. Hbool isempty (void) const;
Verify that the area is empty, that is, whether the area is 0
Example 1
#include "HalconCpp.h"
using namespace Halcon;
void main()
{
HImage image("E:\\halcon\\images\\mreut.png"); // Reading an aerial image
HRegion region = image >= 190; // Calculating a threshold
HWindow w; // Display window
w.SetColor("red"); // Set color for regions
region.Display(w); // Display the region
HRegion filled = region.FillUp(); // Fill holes in region
filled.Display(w); // Display the region
// Opening: erosion followed by a dilation with a circle mask
HRegion open = (filled >> 4.5) << 4.5;
w.SetColor("green"); // Set color for regions
open.Display(w); // Display the region
HDPoint2D trans(-100, -150); // Vector for translation
HRegion moved = open + trans; // Translation
HRegion zoomed = moved * 2.0; // Zooming the region
}
First, an aerial image (mreut.png) is read from a file. All pixels with a gray value ≥ 190 are selected. This results in one region (region). This region is transformed by the next steps: All holes in the region are filled (FillUp), small parts of the region are eliminated by two morphological operations, first an erosion, a kind of shrinking the region, followed by a dilation, a kind of enlarging the region. The last step is the zooming of the region. For that the region is first shifted by a translation vector ( − 100, − 150) to the upper left corner and then zoomed by the factor two. Figure 6.2 shows the input image and the result of the opening operation.
Region Arrays
Hregionarray is a container that contains region. The member functions are represented as follows: Long Num (void)
Number of series, the largest number is num () −1. hregion Const &operator [] (long index) const
Reads the first element of the array, the ordinal number is 0 ... Num () −1. Hregion &operator [] (long Index)
Assigns a region to the first J element of the region, the index Index can be≥num (). Hregionarray operator () (Long min, long max) const
Select the data between Min and Max Hregionarray &append (const hregion ®)
Attaches a region to the back of the region array
Many operators that accept region accept the region array as an input parameter. such as morphological operations.
Example 2
#include "HalconCpp.h"
using namespace Halcon;
void main()
{
HImage image("E:\\halcon\\images\\control_unit.png"); // Reading an image from file
// Segmentation by regiongrowing
HRegionArray regs = image.Regiongrowing(1, 1, 4, 100);
HWindow w; // Display window
w.SetColored(12); // Set colors for regions
regs.Display(w); // Display the regions
HRegionArray rect; // New array
for (long i = 0; i < regs.Num(); i++) // For all regions in array
{ // Test size and shape of each region
if ((regs[i].Area() > 1000) && (regs[i].Compactness() < 1.5))
rect.Append(regs[i]); // If test true, append region
}
image.Display(w); // Display the image
rect.Display(w); // Display resulting regions
}
Original
Transformed image
The first step is to read an image. In this case it shows a control unit in a manufacturing environment, see figure 6.4 on the left side. By applying a regiongrowing algorithm from the HALCON library the image is segmented into regions. Each region inside the resulting region array regs is now selected according to its size and its compactness. Each region of a size larger than 1000 pixels and of a compactness value smaller than 1.5 is appended to the region array rect. After the processing of the for loop only the regions showing on the right side of figure 6.4 are left.
Images
In Halcon, a matrix is called a channel, and an image may consist of several channels. For example, grayscale images are made up of one channel, while color images are made up of 3 channels. The type of channel is not just 8-bit (btype), but it can have other types (such as int2) and real type. In addition to preserving pixel information, each Halcon image also stores the so-called domain, which is the region format described above. Region can be understood as an area of interest, i.e. ROI. In general, except for a few exceptions, Halcon operators are processed on region. This is the same thing as Sepera.
Image Objects
Class Himage is the root class for all inherited image classes. By using himage, all different pixel types can be processed in a uniform format (polymorphism). Class Himage is not a virtual class and can therefore be instantiated. Several important member functions are listed below: himage (void)
The default constructor, an empty image. Himage (const char* file)
Reads an image from a file, with read_image himage (int width,int height,const char* type)
Constructs an image that specifies the size and type. Same Gen_image_const himage (void *ptr, int width, int height, const char *type)
Constructs an image, using a copy method, specifying the size and type of the image, with Gen_image1. irtual const char *pixtype (void) const
Pixel type, same get_image_type. int Width (void) const
Image width, see get_image_size. int Height (void) const
High image, see get_image_size. Hpixval getpixval (int x, int y) const
Gets the pixel value at (x,y), see Get_grayval. Hpixval Getpixval (long k) const
Linear get K pixel value virtual void setpixval (int x, int y, const hpixval &val)
Sets the pixel value (x,y) to the same set_grayval. virtual void Setpixval (long k, const hpixval &val)
Set K pixel value virtual void Display (const hwindow &w) const
Display an image on a window
Geometric operations
-Himage operator & (const hregion ®) const
Crops part of an image, and then returns an image of that part. With Reduce_domain.
Comments: This function is designed to be very good, more in line with intuition. An image and region to do & operations, is to obtain a common part, that is, the cropped image. Himage operator + (const himage &add) const
The image is added together with the add_image. Himage operator-(const himage &sub) const
Image subtraction, with Sub_image. Himage operator * (const himage &mult) const
The image is multiplied by the same mult_image. Himage operator-(void) const
The image is reversed and invert_image. Himage operator + (double add) const
Himage operator-(double sub) const
Himage operator * (double mult) const
Himage operator/(double div) const
Image subtraction, with scale_image hregion operator >= (const himage &image) const
Hregion operator <= (const himage &image) const
Selecting all pixel with gray values brighter than or equal to (or darker than or equal to, respectively) those of the INP UT image, see**dyn_threshold**
Comments: Dynamic threshold, local threshold processing, general and both refer to the image for comparison. Hregion operator >= (double thresh) const
Hregion operator <= (double thresh) const
Hregion operator = = = (double thresh) const
Hregion operator!= (double thresh) const
Threshold processing, with threshold.
Example 3
#include "HalconCpp.h"
using namespace Halcon;
#include "HIOStream.h"
#if !defined(USE_IOSTREAM_H)
using namespace std;
#endif
void main()
{
HImage image("E:\\halcon\\images\\mreut.png"); // Aerial image
HWindow w; // Output window
image.Display(w); // Display image
// Returning the size of the image
cout << "width = " << image.Width();
cout << "height = " << image.Height() << endl;
// Interactive drawing of a region by using the mouse
HRegion mask = w.DrawRegion();
// Reduce the domain of the image to the mask
HImage reduced = image & mask;
w.ClearWindow(); // Clear the window
reduced.Display(w); // Display the reduced image
// Applying the mean filter in the reduced image
HImage mean = reduced.MeanImage(61, 61);
mean.Display(w);
HRegion reg = reduced <= (mean -3);
reg.Display(w);
}
This example first reads a grayscale image from a file in order to extract the darker part. Interception of partial area processing is only to save time. You can use the mouse to draw any part of the region to select the part of our image processing area. This part of the area mask is used to intercept the image (operator &) as input. A 61x61 mask with a size is applied to the last captured image to obtain a mean image. Dark pixels are selected by applying operator <=. All pixels not exceeding the mean-3 are selected. Specific reference to Dyn_threshold.
Pixel Values
Hpixval is used to access the pixel value of the class Himage. Grayscale values can be returned and set independently of their type.
The common member functions are described below:
//constructs hpixval (void) Default constructor.
Hpixval (const Hcomplex &val) Constructing a pixel value from a complex number.
Hpixval (int Val) constructing a pixel value from the 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.//cast operator int (void) const converting a pixel value to int.
operator long (void) const converting a pixel value to long. operator