Algorithm for rapidly processing interested area image

文档序号:1738167 发布日期:2019-12-20 浏览:4次 中文

阅读说明:本技术 一种快速处理感兴趣区域图像的算法 (Algorithm for rapidly processing interested area image ) 是由 毛善 于 2019-08-14 设计创作,主要内容包括:本发明属于机器视觉图像处理技术领域,具体涉及一种快速处理感兴趣区域图像的算法,包括如下步骤:S1、对感兴趣区域进行分析,得到它的关键参数;S2、计算不同形状感兴趣区域的正外接矩形;S3、分A方法和B方法,其中A方法是从正外接矩形Y方向最小值开始,按行递增时,求得每行临界值,B方法则按列递增求得每列临界值。S4、利用TBB运算结合S1,S2,S3的计算结果对图像进行处理。本发明将不在特殊形状中的图像数据屏蔽,极大地减少了数据的冗余性,避免了无用的运算,提高了计算效率。(The invention belongs to the technical field of machine vision image processing, and particularly relates to an algorithm for rapidly processing an image of a region of interest, which comprises the following steps: s1, analyzing the region of interest to obtain key parameters of the region of interest; s2, calculating the right circumscribed rectangle of the interested areas with different shapes; and S3, dividing the method A into a method A and a method B, wherein the method A is to obtain a critical value of each row when the minimum value of the positive circumscribed rectangle in the Y direction is increased progressively according to the row, and the method B is to obtain a critical value of each column when the minimum value of the positive circumscribed rectangle in the Y direction is increased progressively according to the column. And S4, processing the image by combining the TBB operation and the calculation results of S1, S2 and S3. The invention shields the image data which is not in the special shape, greatly reduces the redundancy of the data, avoids useless operation and improves the calculation efficiency.)

1. An algorithm for rapidly processing an image of a region of interest, comprising the steps of:

s1, analyzing the region of interest to obtain key parameters of the region of interest;

s2, calculating the right circumscribed rectangle of the interested areas with different shapes;

s3, dividing the method A into a method A and a method B, wherein the method A is started from the minimum Y value of the positive circumscribed rectangle, when the Y value is calculated to increase by 1 pixel (increase by rows), the leftmost value XLeft and the rightmost value XRight of the boundary of the current line of the region of interest are obtained, and the method A is ended when the Y value increases to the maximum Y value of the positive circumscribed rectangle; the method B is that starting from the minimum X value of the circumscribed rectangle, when the X value is increased by 1 pixel (increased by columns), the minimum YTop and the maximum YDown of the boundary of the current column region of interest are obtained, and the calculation is finished when the X value is increased to the maximum X value of the circumscribed rectangle;

and S4, performing parallel image processing operation of multiple rows or multiple columns by using TBB operation and combining the calculation results of S1, S2 and S3, and finally obtaining the processed image data result.

2. The algorithm for fast processing of an image of a region of interest according to claim 1, wherein: in step S1, when the region of interest is a tilted rectangle, its key parameters are the center point position, the angle, the length and the width; when the region of interest is circular, the key parameters of the region of interest are the circle center and the radius; when the interesting area is in an oval shape, the key parameters of the interesting area are a central point, an angle, a long axial length and a short sleeve length; when the region of interest is a circular ring, the key parameters of the region of interest are a circle center, an inner radius, an outer radius, an initial angle and a coverage angle; when the interesting area is a polygon, the key parameter is the point group; when the region of interest is irregular, the key parameter of the region of interest is the point array.

3. The algorithm for fast processing of an image of a region of interest according to claim 1, wherein: in step S1, the region of interest may be a single connected region of one image or a plurality of connected regions.

4. The algorithm for fast processing of an image of a region of interest according to claim 1, wherein: in the step S2, the circumscribed rectangle is a circumscribed positive rectangle of the region of interest portion.

5. The algorithm for fast processing of an image of a region of interest according to claim 2, wherein: in the step S3 method a, when the region of interest is an oblique rectangle, starting from the line that has the smallest Y value of the bounding rectangle, and increasing by rows, the leftmost value XLeft and the rightmost value XRight of the current row area threshold are calculated by: substituting four vertexes of the oblique rectangle into a linear equation: solving 4 linear equations when Y is kX + b; then solving the intersection point of 4 linear equations and an equation (Y is a constant); and sorting the X coordinates of the 4 intersection points in a bubble mode, wherein the X coordinate sorted to the second is XLeft, and the X coordinate sorted to the third is XRight.

6. The algorithm for fast processing of an image of a region of interest according to claim 2, wherein: in the step S3 method a, when the region of interest is circular, starting from the line with the smallest Y value of the circumscribed rectangle, and increasing by lines, the critical leftmost value XLeft of the current line region and the rightmost value XRight are calculated by calculating the difference dy between the current Y value and the Y coordinate of the circle center, where dy is known, and the radius is according to the pythagorean theorem: a is2+b2=c2Then dx is obtained. Then, the XLeft of the current Y value is obtained by subtracting dx from the X coordinate of the center of circle, and the XRight of the current Y value is obtained by adding dx to the X coordinate of the center of circle.

7. The algorithm for fast processing of an image of a region of interest according to claim 2, wherein: in the step S3, method a, when the region of interest is elliptical, starting from the line with the smallest Y value of the positive circumscribed rectangle, the leftmost XLeft and the rightmost XRight of the current line region are calculated by increasing the number of lines: the coordinates of two fixed points C1 and C2 of the ellipse are obtained, the Y coordinate of a certain point on the ellipse is known, the X coordinate of the point is obtained, and the ellipse is defined as follows: the sum of the distances from any point P to two fixed points C1 on the ellipse and C2 is equal to a constant 2a, and an equation (the formula is | PC1| + | PC2| ═ 2a) is listed, two X coordinates are obtained, and finally, the two X coordinate values are compared and analyzed, the X coordinate with the smaller result value is XLeft, and the X coordinate with the larger result value is XRight.

8. The algorithm for fast processing of an image of a region of interest according to claim 2, wherein: in the step S3, method a, XLeft and XRight can be calculated by another method when the region of interest is in the shape of an oblique ellipse. Rotating according to the rotation angle of the oblique ellipse to change into a positive ellipse in the new coordinate system, wherein Y is constant and rotates in the new sitting positionEquation Y ═ kX + b, positive elliptic equationOr

And (3) solving intersection points with a linear equation Y & ltkX & gt + b, rotating after solving the coordinates of the two intersection points, returning to the original coordinate system, wherein the X coordinate with a smaller result value is XLeft, and the X coordinate with a larger result value is XRight.

9. The algorithm for fast processing of an image of a region of interest according to claim 1, wherein: in the step S3 method a, when the region of interest is in any shape, the gray-level value of the source image in the region of interest is 255, and the gray-level value of the non-region of interest is 0, starting from the minimum Y value of the circumscribed rectangle, an accumulation process is performed on the gray-level values of each line to obtain a curve, and a formula is used to calculate the curveAnd (3) derivation is carried out on the curve, wherein two jumping points are X coordinates of inflection points on the curve, the X coordinate of the first inflection point is used as XLeft, and the X coordinate of the second inflection point is used as XRight.

10. The algorithm for fast processing of an image of a region of interest according to claim 2, wherein: in the step S3 method B, when the region of interest is an oblique rectangle and the column is increased in number by column from the column that is the smallest X value of the circumscribed rectangle, the method for calculating the minimum Y YTop of the current column region and the maximum Y YDown of Y is: substituting four vertexes of the oblique rectangle into a linear equation: solving 4 linear equations when Y is kX + b; then solving the intersection point of 4 linear equations and an equation (X is a constant); and (3) carrying out bubble sorting on the Y coordinates of the 4 intersection points, wherein the second Y coordinate is YTop, and the third Y coordinate is YDown.

11. The algorithm for fast processing of an image of a region of interest according to claim 2, wherein: in the step S3, method B, when the region of interest is circular, starting from the column with the smallest X value of the circumscribed rectangle, and increasing progressively by columns, the minimum Y value YTop and the maximum Y value YDown of the current column region are calculated by calculating the difference dx between the current X value and the X coordinate of the circle center, where dx is known, and the radius is according to the pythagorean theorem: a is2+b2=c2Calculating dy; then, subtracting dy from the Y coordinate of the center of circle to obtain YTop of the current Y value, and adding dy to the Y coordinate of the center of circle to obtain YDown of the current Y value.

12. The algorithm for fast processing of an image of a region of interest according to claim 2, wherein: in the method B of step S3, when the region of interest is an ellipse, starting from the column with the smallest X value of the circumscribed rectangle, and increasing by columns, the method for calculating the minimum Y value YTop and the maximum Y value YDown of the current column region is: the coordinates of two fixed points C1 and C2 of the ellipse are obtained, the X coordinate of a certain point on the ellipse is known, the Y coordinate of the point is obtained, and the ellipse definition is as follows: the sum of the distances from any point P on the ellipse to two fixed points C1, C2 is equal to a constant 2a to set up an equation (the formula is | PC1| + | PC2| ═ 2a), two Y coordinates are obtained, and finally, the two Y coordinate values are compared and analyzed, the Y coordinate with the smaller result value is YTop, and the Y coordinate with the larger result value is YDown.

13. The algorithm for fast processing of an image of a region of interest according to claim 1, wherein: in the step S3 method B, when the region of interest is in any shape, the gray-level value of the source image in the region of interest is 255, and the gray-level value of the non-region of interest is 0, starting from the minimum X value of the circumscribed rectangle, an accumulation process is performed on the gray-level values of each column to obtain a curve, and a formula is used to calculate the curveDerivation is carried out on the curve, two jumping points are X coordinates of inflection points on the curve, and the X coordinate of the first inflection point is taken asYTop, the X coordinate of the second inflection point is defined as YDown.

14. The algorithm for fast processing of an image of a region of interest according to claim 1, wherein: in step S4, the primary functions of the TBB operation are parallel algorithm, task scheduling, parallel containers, and the like; the test data shows that when the number of columns is unchanged and fixed to 1000 columns, and the number of rows is 100 rows, 200 rows, 400 rows, 800 rows, 1600 rows, 3200 rows and 6400 rows, the TBB invoking operation time of the invention is as follows: 0.01 msec, 0.011 msec, 0.012 msec, 0.019 msec, 0.031 msec, 0.056 msec, 0.11 msec; the operation time without calling TBB is respectively as follows: 0.006 msec, 0.008 msec, 0.014 msec, 0.029 msec, 0.054 msec, 0.112 msec, 0.222 msec. In view of data, it is advantageous to use the TBB when the number of lines is large enough, so the present invention can determine whether to use the TBB parallel operation according to the size of the image.

Technical Field

The invention belongs to the technical field of machine vision image processing, and particularly relates to an algorithm for rapidly processing an interested area image.

Background

Machine vision is to use a machine to replace human eyes for measurement and judgment. With the rapid development of the microelectronic industry, machine vision systems with high resolution and high processing speed are continuously born, which puts new requirements on the speed, precision, stability and the like of image processing algorithms.

Processing images of a region of interest in machine vision is a common and widely applied image processing method, and only a part of the region of interest in millions or tens of millions of pixels of images is taken for image processing, so that the processing efficiency can be remarkably improved. In the prior art, only an interested region is processed in one image, and source pixels of other regions are kept unchanged, and the traditional algorithm comprises the following steps: 1. generating a black and white mask image capable of distinguishing interested areas from non-interested areas; 2. according to the mask image 1 (the mask image 1 with white non-interested region and black interested region), carrying out the AND operation of the source image and the mask image 1 to generate an image A with the non-interested region being a source pixel unchanged and the interested region being black; 3. according to the mask image 2 (the mask image 2 with black non-interested region and white interested region), the source image processing result and the mask image 2 are operated to generate an image B with black non-interested region and white interested region; 4. and performing OR operation on the image A and the image B to obtain an image which only processes the interested area and keeps the source pixels of other areas unchanged. In the process, the non-interested region participates in the operation, so that the operation time is long, and the operation efficiency is reduced.

In view of the above, it is desirable to provide an algorithm for processing a region of interest graph quickly.

Disclosure of Invention

The invention aims to: aiming at the defects of the prior art, the algorithm for rapidly processing the image of the interested region is provided, the boundary information of the interested region is utilized, and the extraction processing is stably and reliably carried out on the interested region in the image by combining mathematical operation and parallel operation.

In order to achieve the purpose, the invention adopts the following technical scheme:

an algorithm for rapidly processing an image of a region of interest, comprising the steps of:

s1, analyzing the region of interest to obtain key parameters of the region of interest;

s2, calculating the circumscribed rectangles of the interested areas with different shapes;

s3, dividing the method A into a method A and a method B, wherein the method A starts from the minimum Y value of the positive circumscribed rectangle, calculates when the Y value is increased by 1 pixel (increased by rows), obtains the leftmost value XLeft and the rightmost value XRight of the boundary of the current row of the interested region, and ends when the Y value is increased to the maximum Y value of the positive circumscribed rectangle; the method B is started from the minimum X value of the circumscribed rectangle, and the calculation is finished when the X value is increased by 1 pixel (increased by columns), the minimum Y value YTop of the boundary of the current column region of interest and the maximum Y value YDown are obtained, and the X value is increased to the maximum X value of the circumscribed rectangle;

and S4, combining the calculation results of S1, S2 and S3 by using TBB operation to realize parallel image processing operation of multiple rows or multiple columns, and finally obtaining the processed image data result.

As an improvement of the algorithm for rapidly processing the image of the region of interest according to the present invention, in step S1, when the region of interest is a tilted rectangle, its key parameters are the center point position, the angle, the length and the width; when the region of interest is circular, the key parameters of the region of interest are the circle center and the radius; when the interesting area is oval, the key parameters of the interesting area are a central point, an angle, a long axis length and a short sleeve length; when the region of interest is a circular ring, the key parameters of the region of interest are a circle center, an inner radius, an outer radius, an initial angle and a coverage angle; when the interesting area is a polygon, the key parameter is the point group; when the interesting area is in an irregular shape, the key parameter of the interesting area is a point array.

As an improvement of the algorithm for processing an image of a region of interest quickly according to the present invention, in step S1, the region of interest may be a single connected region of an image or a plurality of connected regions.

As an improvement of the algorithm for rapidly processing the region-of-interest image according to the present invention, in the step S2, the circumscribed rectangle is a circumscribed regular rectangle of the region-of-interest portion.

As an improvement of the algorithm for processing an image of a region of interest quickly according to the present invention, in the method a in step S3, when the region of interest is an oblique rectangle, starting from the line that has the smallest Y value of the circumscribed rectangle, and increasing by lines, the method for calculating the critical leftmost value XLeft and rightmost value XRight of the current line area is as follows: substituting four vertexes of the oblique rectangle into a linear equation: solving 4 linear equations when Y is kX + b; then solving the intersection point of 4 linear equations and an equation (Y is a constant); and sorting the X coordinates of the 4 intersection points by bubbling, wherein the X coordinate sorted as the second is XLeft, and the X coordinate sorted as the third is XRight.

As an improvement of the algorithm for rapidly processing the image of the region of interest according to the present invention, in the step S3, method a, when the region of interest is circular, starting from the line with the smallest Y value of the right circumscribed rectangle, and increasing by lines, the critical leftmost value XLeft of the current line region and the rightmost value XRight are calculated by calculating the difference dy between the current Y value and the Y coordinate of the circle center, knowing dy, and the radius is according to the pythagorean theorem: a is2+b2=c2Then dx is obtained. Then, the XLeft of the current Y value is obtained by subtracting dx from the X coordinate of the center of circle, and the XRight of the current Y value is obtained by adding dx to the X coordinate of the center of circle.

As an improvement of the algorithm for processing an image of a region of interest quickly according to the present invention, in the method a in step S3, when the region of interest is elliptical, starting from the line with the smallest Y value of the circumscribed rectangle, and increasing by lines, the method for calculating the critical leftmost value XLeft and rightmost value XRight of the current line area is as follows: the coordinates of two fixed points C1 and C2 of the ellipse are obtained, the Y coordinate of a certain point on the ellipse is known, the X coordinate of the point is obtained, and the ellipse is defined as follows: the sum of the distances from any point P to two fixed points C1 on the ellipse and C2 is equal to a constant 2a, and an equation (the formula is | PC1| + | PC2| ═ 2a) is listed, two X coordinates are obtained, and finally, the two X coordinate values are compared and analyzed, the X coordinate with the smaller result value is XLeft, and the X coordinate with the larger result value is XRight.

As an improvement of the algorithm for processing the image of the region of interest quickly according to the present invention, in the step S3, method a, when the region of interest is in the oblique elliptical shape, XLeft and XRight can be calculated by another method. Rotating according to the rotation angle of the oblique ellipse to change the oblique ellipse into a positive ellipse in the new coordinate system, wherein Y is constant and the oblique ellipse is also rotated to change the oblique ellipse into a new equation Y kX + b in the new coordinate system, and the positive ellipse formulaOr

And (3) solving intersection points with a linear equation Y & ltkX & gt + b, rotating after solving the coordinates of the two intersection points, returning to the original coordinate system, wherein the X coordinate with a smaller result value is XLeft, and the X coordinate with a larger result value is XRight.

As an improvement of the algorithm for rapidly processing the image of the region of interest according to the present invention, in the method a of step S3, when the region of interest is in any shape, the gray-level value of the source image in the region of interest is 255, and the gray-level value of the non-region of interest is 0, starting from the minimum Y value of the circumscribed rectangle, an accumulation process is performed on the gray-level value of each line to obtain a curve, and a formula is used to calculate the curveAnd (3) derivation is carried out on the curve, wherein two jumping points are X coordinates of turning points on the curve, the X coordinate of a first turning point is used as XLeft, and the X coordinate of a second turning point is used as XRight.

As an improvement of the algorithm for processing the image of the region of interest quickly according to the present invention, in the method B in step S3, when the region of interest is an oblique rectangle, starting from the column that is just circumscribing the rectangle with the smallest X value, and increasing by columns, the method for calculating the minimum value YTop of Y and the maximum value YDown of Y critical to the current column region is as follows: substituting four vertexes of the oblique rectangle into a linear equation: solving 4 linear equations when Y is kX + b; then solving the intersection point of 4 linear equations and an equation (X is a constant); and (3) carrying out bubble sorting on the Y coordinates of the 4 intersection points, wherein the second Y coordinate is YTop, and the third Y coordinate is YDown.

As an improvement of the algorithm for rapidly processing the image of the region of interest, in the step S3, method B, when the region of interest is circular, starting from the column with the minimum X value of the circumscribed rectangle and increasing by columns, the minimum Y value YTop and the maximum Y value YDown of the critical area of the current column are calculated by calculating the difference dx between the current X value and the X coordinate of the circle center, knowing dx, and the radius according to the colluding thighTheorem: a is2+b2=c2Calculating dy; then, subtracting dy from the Y coordinate of the center of circle to obtain YTop of the current column, and adding dy to the Y coordinate of the center of circle to obtain YDown of the current column.

As an improvement of the algorithm for processing the image of the region of interest rapidly according to the present invention, in the method B in step S3, when the region of interest is an ellipse, starting from the column that has the smallest X value of the circumscribed rectangle, and increasing by columns, the method for calculating the minimum Y value YTop of the critical Y of the current column region and the maximum Y value YDown of Y is as follows: the coordinates of two fixed points C1 and C2 of the ellipse are obtained, the X coordinate of a certain point on the ellipse is known, the Y coordinate of the point is obtained, and the ellipse definition is as follows: the sum of the distances from any point P on the ellipse to two fixed points C1, C2 is equal to a constant 2a to set up an equation (the formula is | PC1| + | PC2| ═ 2a), two Y coordinates are obtained, and finally, the two Y coordinate values are compared and analyzed, the Y coordinate with a smaller result value is YTop, and the Y coordinate with a larger result value is YDown.

As an improvement of the algorithm for rapidly processing the image of the region of interest according to the present invention, in the method B of step S3, when the region of interest is in any shape, the gray-level value of the source image in the region of interest is 255, and the gray-level value of the non-region of interest is 0, starting from the minimum X value of the circumscribed rectangle, an accumulation process is performed on the gray-level values of each column to obtain a curve, and a formula is used to calculate the curveAnd (3) derivation is carried out on the curve, wherein two jumping points are the X coordinates of turning points on the curve, the X coordinate of the first turning point is used as YTop, and the X coordinate of the second turning point is used as YDown.

As an improvement of the algorithm for rapidly processing the image of the region of interest according to the present invention, in step S4, the main functions of the TBB operation are parallel algorithm, task scheduling, parallel container, and the like; the test data shows that when the number of columns is unchanged and fixed to 1000 columns, and the number of rows is 100 rows, 200 rows, 400 rows, 800 rows, 1600 rows, 3200 rows and 6400 rows, the TBB calling operation time of the invention is as follows: 0.01 msec, 0.011 msec, 0.012 msec, 0.019 msec, 0.031 msec, 0.056 msec, 0.11 msec; the operation time without calling TBB is respectively as follows: 0.006 msec, 0.008 msec, 0.014 msec, 0.029 msec, 0.054 msec, 0.112 msec, 0.222 msec. In view of data, it is advantageous to use the TBB when the number of lines is large enough, so the present invention can determine whether to use the TBB parallel operation according to the size of the image.

Compared with the prior art, the invention at least has the following beneficial effects:

1) the invention shields the image data which are not in the region of interest, greatly reduces the redundancy of the data, avoids useless operation and improves the calculation efficiency.

2) The invention adopts mathematical definition to calculate the critical point of each row or each column of the interested region, thereby improving the reliability of calculation.

3) The invention adopts a TBB parallel operation method.

Drawings

The accompanying drawings, which are included to provide a further understanding of the invention and constitute a part of this specification, illustrate embodiments of the invention and together with the description serve to explain the invention without limiting the invention to the best mode contemplated. In the drawings:

FIG. 1 is a flow chart of a method of the present invention;

FIG. 2 is a schematic structural view of example 1 of the present invention;

FIG. 3 is a schematic structural view of example 2 of the present invention;

FIG. 4 is a schematic structural view of example 3 of the present invention;

FIG. 5 is a schematic structural diagram of examples 5 and 9 of the present invention;

FIG. 6 is a schematic structural view of example 6 of the present invention;

FIG. 7 is a schematic structural view of example 7 of the present invention;

FIG. 8 is a schematic structural view of example 8 of the present invention;

Detailed Description

As used in the specification and in the claims, certain terms are used to refer to particular components. As one skilled in the art will appreciate, manufacturers may refer to a component by different names. This specification and claims do not intend to distinguish between components that differ in name but not function. In the following description and in the claims, the terms "include" and "comprise" are used in an open-ended fashion, and thus should be interpreted to mean "include, but not limited to. "substantially" means within an acceptable error range, within which a person skilled in the art can solve the technical problem and substantially achieve the technical result.

The present invention will be described in further detail below with reference to the accompanying drawings, but the present invention is not limited thereto.

15页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种药品识别方法、装置和用于药品识别的装置

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!