Opencv learning notes (1)-basic and structure of Digital Graphics

Source: Internet
Author: User
Tags image processing library

 

I. Image Basics

 1. Digital ImageA digital image or digital image is a two-dimensional image represented by a finite number of pixels. Digital images are images that are digitalized by analog images with pixel as the basic element and can be stored and processed by digital computers or digital circuits.

 2. pixelsPixels (or pixels, pixel) are the basic elements of digital images. pixels are obtained by discretization of continuous spaces during Digital Simulation of images. Each pixel has the coordinates of the integer row (height) and column (width) positions, and each pixel has an integer gray value or color value. In general, pixels are stored as two-dimensional integer numbers in a computer. These values are often transmitted and stored in a compressed format.

 3. ChannelsBasically, describe a pixel. If it is grayscale, you only need a numerical value to describe it, that is, a single channel. If a pixel has three colors of RGB, it is three channels .. Windows BMP is sometimes a four-channel image, and R, G, and B plus a Channel A, indicating transparency.

4. ResolutionMeasure of the image definition or concentration. For example, the resolution represents the number of dots per inch (DPI) displayed vertically and horizontally. Bitware can send and receive fax documents with standard or standard (100 × 200 dpi) and fine resolution (200 × 200 dpi. Resolution is a concept that indicates the precision of a plane image. It is usually measured by the number of horizontal and vertical points, expressed in the form of horizontal points × vertical points. In a fixed plane, the higher the Resolution, the more points that can be used, the more detailed the image.

Binary Image Classification

Grayscale image: A monochrome digital image with only one intensity value per pixel

Doop image: a two-dimensional image with a intensity value vector at each spatial point or pixel position. For a color image, the vector has three elements.

Binary Image: a digital image with all pixel values either 0 or 1.

Tagged Image: a digital image with a limited pixel value. The character value of a pixel indicates the result of a certain decision on the pixel.

Three-Image Data Structure

1. Matrix

1.1 Basic Concept: The most common data structure represented by the underlying image. The matrix element is an integer value that corresponds to the brightness or other attributes of the corresponding pixel in the sampling grid. This type of image data is usually the direct output of Image devices. The image information in the matrix can be obtained through the pixel coordinate, which corresponds to the row and column numbers. The matrix image is a complete representation and is irrelevant to the content of the image data.

1.2 Matrix Representation of the image: Binary Image: represented by a matrix containing only 0 and 1; multi-spectral image: several matrices can be used for representation, each matrix contains an image of one band; layered Image Data Structure: obtained using matrices of different resolutions. This layered representation of images is very convenient for Parallel computers with a processor array structure.

2. Chain

2.1 chaincodes: commonly used to describe the boundary of an object or a line of pixel width in an image. The boundary is defined by its reference pixel coordinates and sequence number. The symbol corresponds to several lines with a defined direction in length. Note that the chaincode itself is relative, and the data is expressed relative to a certain reference point. The representation of Images Using chaincodes is suitable for Syntactic Pattern Recognition Based on the formal language theory.

2.2 stroke encoding: it is usually used to represent the symbol string in the image matrix.

 3. topological data structure

3.1 Value assignment: an arc, a node, or a graph with values.

3.2 area adjacent graph: the node wins and the area, and the adjacent area is connected by an arc.

4. Layered data structure

Layered data structure allows special algorithms to determine processing policies based on relatively small data volumes, and only performs the most precise resolution on the quality of the image.

4.1 pyramid: the simplest hierarchical data structure. There are M-type pyramid and T-type pyramid. It mainly describes the data structure of multiple image resolutions.

4.2 quad-tree: improved the T-type pyramid. The selected area in the image is stored at a resolution higher than that in other areas, allowing you to selectively extract details.

Iv. Basic Structure of opencv

For the data structure in opencv, here we will discuss three cvarr, cvmat, and iplimage

4.1 cvarr: an abstract base class. cvarr * is only a parameter used as a function. It indicates that the function can receive more than one array type, such as iplimage *, cvmat *, or even cvseq *. the final array type is determined at runtime by analyzing the first four bytes of the array header.

4.2 cvmat: Multi-Channel Matrix. Its structure is as follows:

Typedef struct cvmat
{
Int type;/* cvmat identifier (cv_mat_magic_val), element type and flag */
Int step;/* length of row data in bytes */
Int * refcount;/* data reference count */
Union
{
Uchar * PTR;
Short * s;
Int * I;
Float * FL;
Double * dB;
} Data;/* Data Pointer */
# Ifdef _ cplusplus
Union
{
Int rows;
Int height;
};
Union
{
Int Cols;
Int width;
};
# Else
Int rows;/* number of rows */
Int Cols;/* Number of columns */
# Endif
} Cvmat;
The cvmat class has two parts of data. One is the matrix header. The size of this part is fixed, including the size of the matrix, the storage method, and the address of the matrix storage, such as the above structure. The other part is a pointer to a matrix containing pixel values.

4.2.1create and access cvmat

Cvmat * cvcreatemat (INT rows, int cols, int type) // create a two-dimensional matrix where type can be of the following types (from http://blog.csdn.net/yang_xian521/article/details/7107786)

When it comes to data storage, this has always been a noteworthy issue. Mat _ <uchar> corresponds to cv_8u, And Mat _ <uchar> corresponds to cv_8u, mat _ <char> corresponds to cv_8s, mat _ <int> corresponds to cv_32s, mat _ <float> corresponds to cv_32f, And Mat _ <double> corresponds to cv_64f, the corresponding data depth is as follows:

Cv_8u-8-bit unsigned integers (0 .. 255)

Cv_8s-8-bit signed integers (-128 .. 127) • cv_16u-16-bit unsigned integers (0 .. 65535)

Cv_16s-16-bit signed integers (-32768 .. 32767)

Cv_32s-32-bit signed integers (-2147483648 .. 2147483647)

Cv_32f-32-bit upload oating-point numbers (-flt_max..flt_max, INF, Nan)

Cv_64f-64-bit parameter oating-point numbers (-dbl_max..dbl_max, INF, Nan)

Instance code

# Include <cv. h> # include 

For the above cvmat, we have now launched the mat class with powerful functions..., which will be introduced in the next article.

4.3 iplimge

 

Typedef struct _ iplimage {int nsize;/* iplimage size */int id;/* version (= 0) */INT nchannels;/* Most opencv Functions Support 1, 2, 3 or 4 channels */INT alphachannel;/* ignored by opencv */INT depth;/* bit depth of pixels: Fill, ipl_depth_8s, ipl_depth_16u, ipl_depth_16s, ipl_depth_32s, ipl_depth_32f and ipl_depth_64f support */Char colormodel [4];/* ignored by opencv */Char channelseq [4];/* same as above */INT dataorder; /* 0-Cross-access color channels, 1-separated color channels. cvcreateimage can only create cross-access images */INT origin;/* 0-top-left structure, 1-bottom-left structure (Windows bitmaps style) */INT align; /* arrange image rows (4 or 8 ). opencv ignores it and replaces */INT width with widthstep;/* Number of Image Width bins */INT height;/* Number of Image Height bins */struct _ iplroi * roi; /* areas of interest to the image. when this value is not null, only the region is processed */struct _ iplimage * maskroi;/* null */void * imageid must be set in opencv; /* same as above */struct _ ipltileinfo * tileinfo;/* same as above */INT imagesize; /* image data size (in cross-Access format, imagesize = image-> height * image-> widthstep), in bytes */char * imagedata; /* point to the arranged image data */INT widthstep;/* the size of the row of the arranged image, in bytes */INT bordermode [4];/* Edge End mode, ignored by opencv */INT borderconst [4];/* same as */char * imagedataorigin;/* the pointer points to a different image data structure (not necessarily arranged ), prepared to correct image memory allocation */}

Iplimage;
The iplimage structure comes from the Intel image processing Library (its own ). Opencv only supports one of the following subsets:

Alphachannel is ignored in opencv.
Colormodel and channelseq are ignored by opencv. Cvcvtcolor, the unique function of opencv color conversion, uses the color space of the Target Image in the color space of the original image as a parameter.
Dataorder must be ipl_data_order_pixel (the color channel is cross-Access). However, the selected channel of a plane image can be processed, just as the COI (Channel of interest) has been set.
Align is ignored by opencv and uses widthstep to access subsequent image rows.
Maskroi is not supported. The function that processes the mask treats it as a separate parameter. Mask is 8-bit in opencv, but 1-bit in IPL.
Tileinfo is not supported.
Bordermode and borderconst are not supported. Each opencv function processes adjacent pixels of pixels, usually using a single fixed code marginal mode.
In addition to the above restrictions, opencv has different requirements for ROI processing. The size of the original image and the target image or the size of the ROI must be (according to different operations, for example, the width (height) of the cvpyrdown target image must be equal to the width (height) of the original image) divided by 2 ± 1) precise matching, while IPL processes cross regions, the image size or ROI size may be completely independent.

The above is taken from the document.

# Include <cv. h> # include 

It can be said that this method is the fastest way to traverse, but it is not efficient to find an element separately.

In fact, these things are basically a reference. I still cannot understand the structure. I still need to work hard.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.