C# 图片分析处理

http://www.codeproject.com/Articles/196168/Contour-Analysis-for-Image-Recognition-in-C

Introduction

The article describes the theoretical bases of the contour analysis and aspects of its practical application for image recognition. The article also includes library for operation with the contour analysis, and a demo-example.

The first part of the article contains the main definitions and theorems of the contour analysis. I tried to select the principal moments which allow to understand quickly enough an essence of the contour analysis, and to begin its application in practice. Also, I added something from myself. In the core, it concerns some aspects of the theory, and also problems of optimization of algorithms of the contour analysis. The second part of the article is devoted to it. In the same place results of work of algorithms are brought, problems and deficiencies of the given method are described.

The third part describes C# library ContourAnalysis.

本文介绍了轮廓分析的理论基础,以及图像识别的应用。文中还实例演示了轮廓分析库的操作。文章的第一部分主要包含轮廓分析的定义和理论。我尽量挑主要的说,让大家可以更快的了解轮廓分析的本质,并在实践中应用。轮廓分析算法的优化,是理论的核心,本文将在第二部分,专门介绍。同样,算法带来的问题和不足之处,也会进行相关分析说明。

注:轮廓分析也要叫 字形分析 的!

Part 1: Bases of the Contour Analysis(轮廓分析)

What is Necessary for the Contour Analysis (CA)--轮廓分析的必要性(CA)

The CA allows to describe, store, compare and find the objects presented in the form of the exterior outlines - contours.

CA允许描述,存储,比较和查找对象的外部轮廓。

It is supposed that the contour contains the necessary information on the object shape. Interior points of the object are not accepted to attention. It restricts area of applicability of algorithms of a CA, but reviewing only contours allows to pass from two-dimensional space of the image - to space of contours and by that to lower computing and algorithmic complexity.

该理论是建立在,轮廓中包含了对象形状的必要信息,而不关心对象的内部的信息。

CA allows to effectively solve the main problems of a pattern recognition - transposition, turn and a rescaling of the image of object. CA methods are invariant to these transformations.

CA可以有效地识别:透明的,转向的和缩放的图形。

The Main Concepts--主要的概念

At first, we define such an object contour. The contour is a boundary of object, a population of points (pixels), separating object from a background.

首先,我们定义这样一个对象的轮廓。轮廓是一个对象的边界的,由许多像素组成,并从背景中分离出来。

In systems of computer vision, some formats of coding of a contour are used - the code of Freeman, two-dimensional coding, polygonal coding are most known. But all these formats of coding are not used in a CA.

在计算机的识别系统中,常规的轮廓编码有 - Freeman链码、二维图编码、多边形编码(三个都很有名,百度一个就有)。但在CA中都没有用到。

Instead, in a CA the contour is encoded by the sequence consisting of complex numbers. On a contour, the point which is called as starting point is fixed. Then, the contour is scanned (is admissible - clockwise), and each vector of offset is noted by a complex number a+ib. Where a - point offset on x axis, and b - offset on y axis. Offset is noted concerning the previous point.

取而代之的是复数组成的序列。首先在轮廓上定义一个固定的起始点,然后,对轮廓进行扫描(是顺时针方向),偏移量的每个向量是由复数a + ib表示。 a- X轴的偏移,b- y轴的偏移。偏移量与前一个点相关联。

注:下图中VC中的第一个1,不是start porint,是第二个点喔因为Y轴的位置没变,所以是0,X轴向右移了一个像素,所以是1,别的点就可以自己推测出来了。

Owing to the physical nature of three-dimensional objects, their contours are always closed and cannot have self-intersection. It allows to define unambiguously a way of bypass of a contour (to within a direction - on or counter-clockwise). The last vector of a contour always leads to the starting point.

根据三维物体的物理性质可知,其轮廓是始终闭合,且不能有自相交的。因此,它可以明确的定义轮廓(顺时针或逆时针的方向)。轮廓的最后的矢量总是起点。

Each vector of a contour we will name elementary vector (EV). And sequence of complex-valued numbers - vector-contour (VC).

每个向量的轮廓,我们将其命名的基本载体(EV)。复值序列我们命名为矢量轮廓(VC)。

Vectors-contours we will designate the big Greek letters, and their elementary a vector - small Greek letters.

VC我们用大写字母表示,EV我们用小写字母表示。

Thus, vector-contour Γ of length k can be designated as:

因此,VC的向量表达式如下

Why in a CA complex-valued coding is used? Because operations over a contour as over a vector of complex numbers possesses remarkable mathematical properties, in comparison with other modes of coding.

为什么在CA复杂的值编码使用?由于操作超过一个轮廓作为复数的矢量具有显着的的数学性质,比较,与其他的编码方式。

Basically, complex coding is close to two-dimensional coding where the contour is defined as a population of the EVs presented in the two-dimensional coordinates. But a difference between operation of scalar product for vectors and for complex numbers - are various. This circumstance also gives priority to CA methods.

Properties of Contours

  1. The sum of an EV of a closed contour is equal to zero. It is trivial - as the elementary vectors result in starting point, their sum is equal to a zero-vector.
  2. The contour-vector does not depend on parallel transposition of the source image. As the contour is encoded relative to starting point, this mode of coding is invariant to shift of an initial contour.
  3. Image turn on certain angle is equivalent to turn of each EV of a contour on the same angle.
  4. The starting point modification conducts to VC cycle shift. As EVs are encoded concerning the previous point, it is clear that at a modification of starting point, the sequence of an EV will be the same, but the first EV will be what begins in the starting point.
  5. The source image rescaling can be considered as multiplication of each EV of a contour to scale factor.

Scalar Product of Contours

As scalar product of contours, Γ and N are called such complex number:

Where k - dimensionality of a VC, γn - n the elementary vector of contour Γ, νn - n EV of contour N. (γn, νn) - the scalar product of complex numbers calculated as:

Let's pay attention to that in a CA the scalar product only a VC of identical dimensionality is supposed. That is the number of the elementary vectors in contours should coincide.

The scalar product of usual vectors and scalar product of complex numbers - differ. If we multiplied an EV as simple a vector, their scalar product would look so:

Compare this formula to the formula (2) and you note that:

  • Outcome of scalar product of vectors is the real number. And outcome of product of complex numbers - a complex number.
  • The real part of scalar product of complex numbers coincides with scalar product of appropriate vectors. That is complex product includes vectorial scalar product.

And now let's remember linear algebra. To be exact - physical sense and properties of scalar product. The scalar product is equal in the linear algebra to product of lengths of vectors on a cosine of the angle in between. It means that two perpendicular vectors will always have zero scalar product, collinear a vector - opposite, will give maximum value of scalar product.

These properties of product allow to use it as a certain measure of closeness of vectors. If it is more - the less angle between vectors, the "more close" they are to each other. For perpendicular vectors - it is lowered to zero, and further becomes negative for the vectors directed every which way. It appears, scalar product (1) also possesses similar properties.

Let's introduce one more concept - the normalized scalar product (NSP):

Where |Γ| and |N| - the norms (length) of contours calculated as:

The NSP in space of complex numbers, also is a complex number.

Thus, unity is greatest possible value of norm of NSP (it follows from a Cauchy–Bunyakovsky–Schwarz inequality: |ab| <= |a||b|), and it is reached only if...

...where μ - the arbitrary complex number.

What does it mean in practice? We recall physical sense of multiplication of complex numbers. At multiplication of complex numbers, their lengths are multiplied, and arguments (angles) - are added. The contour μN means it is the same contour N, but turned both scaled. The scale and turn is defined by a complex number μ.

So, norm of NSP reaches maximum value - unity, only if contour Γ is the same contour N, but turned on some angle and scaled on certain coefficient.

For an example, we consider a scalar multiplication of a contour most on themselves, but turned on a certain angle.

So if to count a NSP of a vector most on itself, we receive NSP=1, if to turn a contour on 90 degrees, we receive NSP=0+i, turn on 180 degrees gives a NSP=-1. Thus, the real part a NSP will give us a cosine of the angle between contours, and the norm of NSP will be always equal to 1.

 

转载于:https://www.cnblogs.com/cyangluiqin/archive/2013/03/31/2991815.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值