[go: up one dir, main page]

HK1168185A1 - Method and system for dividing an image - Google Patents

Method and system for dividing an image Download PDF

Info

Publication number
HK1168185A1
HK1168185A1 HK12108961.4A HK12108961A HK1168185A1 HK 1168185 A1 HK1168185 A1 HK 1168185A1 HK 12108961 A HK12108961 A HK 12108961A HK 1168185 A1 HK1168185 A1 HK 1168185A1
Authority
HK
Hong Kong
Prior art keywords
image
line
boundary
formal
determining
Prior art date
Application number
HK12108961.4A
Other languages
Chinese (zh)
Other versions
HK1168185B (en
Inventor
王永攀
Original Assignee
阿里巴巴集團控股有限公司 號郵箱
阿里巴巴集团控股有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 阿里巴巴集團控股有限公司 號郵箱, 阿里巴巴集团控股有限公司 filed Critical 阿里巴巴集團控股有限公司 號郵箱
Publication of HK1168185A1 publication Critical patent/HK1168185A1/en
Publication of HK1168185B publication Critical patent/HK1168185B/en

Links

Landscapes

  • Image Analysis (AREA)

Abstract

The application discloses image segmentation method and a system. The image segmentation method comprises the steps of according to the pixel characteristics of rows and lines of an image to be cut, determining an alternative cutting line in an image to be cut; determining a line section clamped by the intersection points of the row and the line on which the alternative cutting line is positioned as a formal cutting line of the image to be cut, and determining a line section clamped by the intersection points of an original border line and the alternative cutting line of the image to be cut as a formal cutting line of the image to be cut; utilizing the formal cutting line to form a rectangular region so as to store the information of the rectangular region; and cutting the rectangular region corresponding to the stored information from the image to be cut. In the technical scheme, according to the pixel characteristics of the rows and lines of the image to be cut, a possible cutting line of the image can be determined, then an independent region block in the image can be determined in the rectangular region formed by the cutting lines, and finally, the region blocks are cut from an original image, so that the automatic segmentation of a large-size splicing image can be realized.

Description

Image segmentation method and system
Technical Field
The present application relates to the field of image processing technologies, and in particular, to an image segmentation method and system.
Background
The development of image processing technology has made images an important information bearing form in the fields of computers and internet.
Generally, one image should be able to independently express relatively complete information, but in practical application, a large image is often encountered, which is formed by splicing a plurality of simple images, and although the display effect is similar to that of a common image, the post-processing of the image is not facilitated. For example, in application requirements such as image recognition, image classification, image retrieval, image database establishment and the like, operations such as image analysis, feature extraction and the like are required, on one hand, due to the fact that the size of an image is too large, a large amount of computing resources are required to be consumed during image analysis and processing, and the computing resources consumed for processing a large image are far larger than those consumed for processing a plurality of simple images obtained by segmenting the large image; on the other hand, the information contained in the stitched image is too much, and it is difficult to extract the feature representing the image.
In order to meet various application requirements, the large-scale image obtained by splicing needs to be segmented as much as possible into a state before splicing. The existing image segmentation technology mainly adopts a contour extraction and iteration mode to segment the foreground and the background of an image. This method is mainly used to segment irregular regions from images, and is not suitable for segmentation processing of large-scale stitched images. Therefore, the segmentation processing operation on the large image still needs to be completed by human intervention at present.
Disclosure of Invention
In order to solve the above technical problems, embodiments of the present application provide an image segmentation method and system to implement automatic segmentation processing on a large-scale stitched image, and the technical scheme is as follows:
the embodiment of the application provides an image segmentation method, which comprises the following steps:
determining alternative segmentation lines in the image to be segmented according to the pixel characteristics of the rows and the columns of the image to be segmented;
determining a line segment clamped by intersection points of the rows and the columns of the alternative dividing lines as a formal dividing line of the image to be divided, and determining a line segment clamped by intersection points of a primary boundary line of the image to be divided and the alternative dividing lines as a formal dividing line of the image to be divided;
forming a rectangular area by using the formal dividing line, and storing information of the rectangular area;
and cutting the rectangular area corresponding to the stored information from the image to be segmented.
An embodiment of the present application further provides an image segmentation system, including:
the alternative segmentation line determining module is used for determining alternative segmentation lines in the image to be selected according to the pixel characteristics of the image to be segmented;
the formal dividing line determining module is used for determining a line segment which is sandwiched by intersection points of rows and columns of the alternative dividing lines determined by the alternative dividing line determining module as a formal dividing line of the image to be divided and determining a line segment which is sandwiched by intersection points of a primary boundary line of the image to be divided and the alternative dividing lines as a formal dividing line of the image to be divided;
the rectangular area determining module is used for forming a rectangular area by using the formal parting line determined by the formal parting line determining module and storing rectangular area information;
and the rectangular region cutting module is used for cutting the rectangular region corresponding to the rectangular region information stored in the rectangular region determining module from the image to be segmented.
According to the technical scheme provided by the embodiment of the application, possible segmentation lines of the image are determined according to the pixel characteristics of rows and columns of the image to be segmented, then the independent area blocks in the image are determined from the rectangular area formed by the segmentation lines, and finally the area blocks are cut from the original image, so that the automatic segmentation processing of the large-size spliced image is realized.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments described in the present application, and other drawings can be obtained by those skilled in the art according to the drawings.
FIG. 1 is a schematic flowchart of an image segmentation method according to an embodiment of the present disclosure;
FIG. 2 is a first diagram illustrating an image segmentation result according to an embodiment of the present disclosure;
FIG. 3 is a second schematic diagram of an image segmentation result according to an embodiment of the present application;
FIG. 4 is a third schematic diagram of an image segmentation result according to an embodiment of the present application;
FIG. 5 is a schematic diagram of an intersection of formal parting lines of the image parting method according to the embodiment of the present application;
FIG. 6 is a second flowchart illustrating an image segmentation method according to an embodiment of the present application;
FIG. 7 is a fourth image schematic diagram of the image segmentation method according to the embodiment of the present application;
FIG. 8 is a third flowchart illustrating an image segmentation method according to an embodiment of the present disclosure;
FIG. 9 is a fifth diagram illustrating an image segmentation result according to an embodiment of the present application;
FIG. 10 is a sixth schematic diagram of an image segmentation result according to an embodiment of the present application;
FIG. 11 is a seventh schematic diagram illustrating an image segmentation result according to an embodiment of the present application;
FIG. 12 is a diagram illustrating an image segmentation result according to an embodiment of the present application;
FIG. 13 is a schematic diagram of an embodiment of an image segmentation system;
fig. 14 is a schematic structural diagram of a first alternative partition line determining submodule according to an embodiment of the present application.
Detailed Description
Aiming at various application requirements of images, a user hopes to divide a large spliced image into a state before splicing or a plurality of rectangular areas with independent significance as much as possible. The scheme provided by the embodiment of the application can realize automatic segmentation processing of a large-scale spliced image, and the image segmentation method provided by the embodiment of the application is firstly explained below, and comprises the following steps:
determining alternative segmentation lines in the image to be segmented according to the pixel characteristics of the rows and the columns of the image to be segmented;
determining a line segment clamped by intersection points of the rows and the columns of the alternative dividing lines as a formal dividing line of the image to be divided, and determining a line segment clamped by intersection points of a primary boundary line of the image to be divided and the alternative dividing lines as a formal dividing line of the image to be divided;
forming a rectangular area by using the formal dividing line, and storing information of the rectangular area;
and cutting the rectangular area corresponding to the stored information from the image to be segmented.
According to the technical scheme provided by the embodiment of the application, possible segmentation lines of the image are determined according to the pixel characteristics of rows and columns of the image to be segmented, then the independent area blocks in the image are determined from the rectangular area formed by the segmentation lines, and finally the area blocks are cut from the original image, so that the automatic segmentation processing of the large-size spliced image is realized.
In order to make those skilled in the art better understand the technical solutions in the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments that can be derived from the embodiments given herein by a person of ordinary skill in the art are intended to be within the scope of the present disclosure.
Fig. 1 is a flowchart of an image segmentation method according to an embodiment of the present application, including the following steps:
s101: determining alternative segmentation lines in the image to be segmented according to the pixel characteristics of the rows and the columns of the image to be segmented;
the method comprises the steps of determining alternative segmentation lines which are possibly image boundaries in an image to be segmented according to pixel characteristics of pixel points in each row and each column. (wherein the alternative dividing lines may specifically include a first type alternative dividing line and a second type alternative dividing line, which will be described in detail later). The specific process of determining the alternative segmentation line according to the pixel characteristics comprises the following steps:
respectively calculating relative gradient values of each row and each column of the image to be segmented, and determining the row and the column of which the relative gradient values are greater than a preset first gradient threshold as a first-class alternative segmentation line;
respectively judging whether each row and each column of the image to be segmented are smooth, if the smooth states of two adjacent rows are different, determining any row in the two rows as a second type of alternative segmentation line; and if the smooth states of the two adjacent columns are different, determining any column in the two columns as the second type alternative dividing line.
The embodiment of the present application determines a possible segmentation line according to the gradient change of rows and columns and the smooth state change, which is described below:
1) determining possible segmentation lines from row and column gradient changes:
the relative gradient value is a parameter for measuring the gray scale change of a certain row (column) relative to the adjacent row (column). Where the relative gradient values of the rows are defined as: the average value of the gray level absolute difference value of the pixel point of the row relative to the pixel point corresponding to the adjacent row is that: the absolute difference value between a certain pixel point of the row and the corresponding pixel point of the adjacent row is the relative gradient value of the point in the row, and the relative gradient values of all the pixel points in the row are added to calculate the average value, namely the relative gradient value of the row. It will be appreciated that the "relative gradient value" is a measure of the variation between two lines, so that for an n-line image, there are actually only n-1 such parameters, and for ease of recording, the "two-line" parameter can be attributed to either an ascending or descending parameter. Accordingly, the above-mentioned "adjacent row" may be specifically an "upper adjacent row" or a "lower adjacent row", and of course, for one image, the "upper adjacent row" or the "lower adjacent row" should be uniformly used to calculate the relative gradient value of each row.
Similarly, the relative gradient values for a column are defined as: the average value of the gray level absolute difference of the pixel points corresponding to the row relative to the adjacent row, wherein the adjacent row may be: left adjacent column or right adjacent column.
Since the rows and columns with large image gradient change are likely to be the boundaries of the image, the relative gradient values of each row and each column of the image to be segmented are calculated according to the calculation mode of the relative gradient values of the rows and the columns. And judging whether the relative gradient value of each row and each column is larger than a certain threshold value or not in turn row by row and column by column, if so, indicating that the gradient change of the row or the column relative to the adjacent row or the adjacent column is obvious and possibly being an image boundary, and determining the row or the column as the first type alternative dividing line.
For the sake of distinction, in the present embodiment, the above threshold is referred to as a first gradient threshold, and empirically, in a 256-level gray scale system, the first gradient threshold may be set to be about 20, which, of course, does not constitute a limitation to the present embodiment, and a person skilled in the art may set the first gradient threshold according to actual application requirements.
Fig. 2 is an illustration of an image of a first class of alternative segmentation lines determined according to the method described above.
2) Determining possible segmentation lines from the smooth state changes of the rows and columns:
in addition to determining possible segmentation lines based on gradient changes, embodiments of the present application also determine possible segmentation lines based on row and column smoothing states. The specific method comprises the following steps: and judging whether each row and each column are in a smooth state row by row and column by column, and marking that each row and each column are smooth or not. If two adjacent lines have different smooth states, it is considered that there may be a boundary line in the middle of the two lines, for convenience of recording, the "middle line" may be classified as the upper line or the lower line, and from a macroscopic perspective, the two adjacent lines may both be used as boundaries of the partition area, so it is reasonable to record any one of the two lines as the second type of alternative partition line. Similarly, if the smooth states of two adjacent columns are different, any one of the two columns may also be determined as the second type candidate partition line.
The specific method for judging whether the rows and the columns are in the smooth state comprises the following steps:
judging whether the line simultaneously meets a color smoothing condition and a gradient smoothing condition, if so, judging that the line is smooth, otherwise, judging that the line is not smooth;
similarly, whether the column meets the color smoothing condition and the gradient smoothing condition at the same time is judged, if so, the column is judged to be smooth, otherwise, the column is judged to be not smooth;
wherein the gradient smoothing condition is: the relative gradient value of the row or the column is smaller than a preset zero gradient threshold value; that is, a row or column is considered to satisfy the gradient smoothing condition when the gradient of the row or column with respect to an adjacent row or column changes little (close to 0).
Here, it is possible to determine whether a row or a column satisfies the gradient smoothing condition using the relative gradient value of the row or the column calculated when the first-type dividing line is determined. In addition, according to the experience, in the 256-level gray scale system, the zero gradient threshold value can be set to 0.5-2, of course, this does not constitute a limitation to the embodiment of the present application, and the skilled person can set the zero gradient threshold value according to the actual application requirement.
The color smoothing conditions are: the color variation range of the row or the column is smaller than a preset color range threshold value. That is, when the color variation width of a row or column itself is small, the row or column is considered to satisfy the color smoothing condition.
The calculation method of the color variation range is as follows: and calculating the color distance between any two pixel points of the row or the column, and taking the maximum value of the color distance as the color change range of the row or the column.
In a 256-level RGB color system, a color distance calculation formula of two pixel points can be calculated by using a euclidean distance function weighted by coupling, and a color range threshold is set to be about 50, where the expression of the euclidean distance function is:
wherein, Δ C is the color distance between two pixels,Δr=r1-r2,Δg=g1-g2,Δb=b1-b2,(r1、g1、b1) And (r)2、g2、b2) The RGB values of the two pixels are respectively.
Of course, in practical application, the color distance between two pixels may also be calculated in other manners, or other color range thresholds may be set, which is not limited in this embodiment.
Fig. 3 is an illustration of an image of the determination of alternative segmentation lines of the second type according to the method described above.
In practical applications, the two steps may not have an execution order relationship, that is, a certain row or a certain column may be determined as both the first type alternative dividing line and the second type alternative dividing line. However, it can be found in the subsequent step S102 that the second type of candidate partition line can be directly determined as the formal partition line, so in this step, the second type of candidate partition line can also be determined first, and then the first type of candidate partition line is determined in the remaining rows and columns.
In another implementation manner of this embodiment, in order to make the first class candidate partition line obtained according to the gradient change more accurate, in addition to determining whether the relative gradient value of the row is greater than the first gradient threshold, it may be further determined whether a ratio of the relative gradient value of the row to the relative gradient value of an adjacent row is greater than a preset gradient ratio threshold, and if both of these two conditions are satisfied, the row is determined as the first class candidate partition line. The purpose of this is: not only should the position of the dividing line be ensured to be sufficiently large relative to the gradient change of the adjacent row or the adjacent column, but also the determined position of the dividing line should be ensured to be in the extreme value region of the image gradient change, rather than in the region of the continuously increasing or decreasing gradient. In a 256-level gray scale system, the gradient ratio threshold can be set to about 4, which, of course, does not constitute a limitation on the embodiment of the present application.
Similarly, when determining whether each column is the first-class candidate partition line, it is also necessary to determine whether the relative gradient value of the column is greater than the first gradient threshold and whether the ratio of the relative gradient value of the column to the relative gradient value of the adjacent column is greater than the gradient ratio threshold, and when both conditions are satisfied, the column is determined as the first-class candidate partition line.
S102: determining a line segment clamped by intersection points of the rows and the columns of the alternative dividing lines as a formal dividing line of the image to be divided, and determining a line segment clamped by intersection points of a primary boundary line of the image to be divided and the alternative dividing lines as a formal dividing line of the image to be divided;
through S101, a large number of rows and columns that are not likely to include the image boundary are already excluded, and since the rectangular region to be cut finally is composed of line segments, in this step, all line segments sandwiched by intersections of rows and columns where the candidate partition lines composed of the first-type candidate partition line and the second-type candidate partition line are located may be directly determined as the formal partition lines of the image to be divided.
It is understood that, in addition to considering the line segment sandwiched by the intersection points of the row and the column where the alternative dividing line is located, the determination of the formal dividing line should also consider the line segment sandwiched by the intersection points of the primary boundary line of the image to be divided and the alternative dividing line.
In another implementation manner of the embodiment, a formal parting line may be further determined among the alternative parting lines through a certain selection algorithm, so as to reduce the calculation amount of the subsequent cutting work. The specific process of determining the formal dividing line of the image to be divided according to all line segments sandwiched by the alternative dividing lines may include:
obtaining line segments clamped by intersection points of rows and columns where all the alternative dividing lines are located;
directly determining the line segment which is overlapped with the second type of alternative segmentation line as a formal segmentation line of the image to be segmented;
and determining the line segment meeting the gradient condition of the pixel point as a formal segmentation line of the image to be segmented in the line segment superposed with the first type of alternative segmentation line.
Since the second type of candidate segmentation line obtained through smooth change has a high possibility of being an image boundary, line segments which are overlapped with the second type of candidate segmentation line can be directly determined as the formal segmentation line of the image to be segmented and stored.
And the possibility that the first-class alternative segmentation line is an image boundary is smaller than that of the second-class alternative segmentation line, so that in order to enable the selection result to be more accurate, certain line segments with extremely low possibility of becoming the image boundary are omitted, the line segments which are overlapped with the first-class alternative segmentation line can be further judged, and the line segments which accord with the gradient condition of the pixel points are determined as formal segmentation lines of the image to be segmented. The process of judging whether the line segment coincident with the first type of alternative dividing line meets the gradient condition of the pixel point is as follows:
acquiring the number A of pixels of a segment which is coincident with the first-class alternative dividing line and belongs to a preset gradient interval relative to the gradient value and the total number B of pixels of the current segment; and if the A/B is smaller than a preset ratio threshold, determining the current line segment as a formal segmentation line of the image to be segmented. The left end point and the right end point of the preset gradient interval may be the zero gradient threshold and the first gradient threshold, respectively, or may be set as other values according to actual conditions, and the proportional threshold may be set as 20% according to experience.
The above section divides the pixel points into three categories:
1. points where the relative gradient values are large; such dots appear in the image as very distinct gray-scale changes from adjacent rows or columns, for example from black to white.
2. A point where the relative gradient value is small; such dots appear in the image as substantially unchanged from adjacent row or column gray levels.
3. The relative gradient value belongs to a point of a preset gradient interval.
If a line segment contains more type 1 points, the line segment is obviously likely to be a dividing line, and meanwhile, if a certain number of type 2 points are available while a lot of type 1 points exist, the line segment can still be a dividing line. As shown in fig. 4, the left half of the image boundary has a large relative gradient value, and the second half of the image boundary has a small relative gradient value, but the line segment may still be a dividing line.
However, if the number of class 3 points included in a line segment is too large (exceeds the ratio threshold), which indicates that the line segment is likely to be in an area with naturally changing gray levels in the image to be segmented, the line segment should not become the segmentation line.
As shown in fig. 4, most of the line segments identified by the arrows are the type 1 pixel points and the type 2 pixel points, that is, the ratio of the number of points whose relative gradient value belongs to the preset gradient interval to the total number of points is smaller than the proportional threshold, so that the line segment can be determined as a formal dividing line.
For subsequent cutting, the line segments that have been identified as formal dividing lines need to be correspondingly saved. In saving, it is considered that for a horizontal segment, it may be the upper boundary or the lower boundary of an image, and similarly, for a vertical segment, it may be the left boundary or the right boundary of an image. Therefore, such a segment is stored twice in actual storage. In addition, for two completely adjacent segmentation line segments, if the line segments in the vertical direction near the intersection point of the two completely adjacent segmentation line segments are removed, the intersection point is a virtual intersection point, and for the adjacent segmentation line segments with the virtual intersection point, the two completely adjacent segmentation line segments are connected during storage and are treated separately for the upper boundary, the lower boundary, the left boundary and the right boundary. The following describes the manner of storing the normal dividing line with reference to fig. 5:
the formal dividing lines stored in fig. 5(a) are: a1o1, o1b1, c1o1, o1d1, a1o1, o1b1, c1o1, o1d 1;
the formal dividing lines stored in fig. 5(b) are: a2o2, a2b2, o2b2, c2o2, c2o 2;
the formal dividing lines stored in fig. 5(c) are: c3o3, c3d3, o3d3, o3b3, o3b 3.
Note that the formal dividing lines stored in fig. 5(a) do not include: a1b1 and c1d1 because: for a1b1 and c1d1 which intersect, they cannot be either the upper and lower boundaries or the left and right boundaries, and only a1o1, o1b1, c1o1, and o1d1 need to be stored. In fig. 5(b), a2b2 may be the upper boundary but may not be the lower boundary, and therefore, it is only necessary to store it once. Similarly, in fig. 5(b), c3d3 may be the right boundary, but not the left boundary, so it is only saved once.
S103: forming a rectangular area by using the formal dividing line, and storing information of the rectangular area;
in S102, the formal dividing line of the image to be divided is determined, and therefore, in this step, all rectangular regions formed by the formal dividing line can be directly saved as rectangular region information.
In another implementation manner of this embodiment, a more accurate rectangular region may be further determined in the rectangular regions through a certain algorithm, so as to reduce the workload of subsequent cutting.
As shown in fig. 6, the process of forming a rectangle by using formal dividing lines may include the following steps:
s103 a: starting;
s103 b: determining a certain formal dividing line as a first boundary;
the purpose of this step is to confirm the first boundary of the rectangular region, and in practical applications, a horizontal formal dividing line may be confirmed as the first boundary, or a vertical formal dividing line may be confirmed as the first boundary.
The first boundary of the horizontal row may be an upper boundary or a lower boundary, and the first boundary of the vertical row may be a left boundary or a right boundary.
S103 c: judging whether two formal dividing lines are respectively and vertically connected with two end points of the first boundary, wherein the two formal dividing lines are positioned on the same side of the first boundary, if so, entering step S103d, and if not, entering step S103 j;
the purpose of this step and S103d is to identify the second and third boundaries of the rectangular region. It will be appreciated that the second and third boundaries of the rectangular area should be located on the same side of the first boundary. For example:
when the first boundary is a lower boundary, the second boundary and the third boundary should be located at the upper side of the first boundary to form a left boundary and a right boundary;
when the first boundary is an upper boundary, the second boundary and the third boundary should be located at the lower side of the first boundary to form a left boundary and a right boundary;
when the first boundary is a left boundary, the second boundary and the third boundary should be located on the right side of the first boundary to form an upper boundary and a lower boundary;
when the first boundary is a right boundary, the second boundary and the third boundary should be positioned on the left side of the first boundary to form an upper boundary and a lower boundary;
in an actual image, end points of two mutually perpendicular line segments may or may not coincide, and in this embodiment, "vertically connected" is defined as follows:
and if the first line segment is vertical to the second line segment and the distance between the first end point of the first line segment and any end point of the second line segment is less than a preset threshold value, the first end point of the second line segment and the first end point of the first line segment meet the vertical connection condition.
That is, two vertical line segments whose end points do not coincide but are relatively close to each other may be approximated as two mutually perpendicular boundaries constituting a rectangular region. In this case "the second boundary and the third boundary should be located on the same side of the first boundary" should be understood as "the other end points of the second boundary and the third boundary (i.e. the end points which are at a greater distance from the first boundary) should be located on the same side of the first boundary".
It is understood that, in practical applications, the distance threshold should be specifically set according to the size of the image to be segmented, and if the size of the image is larger, a larger distance threshold may be set, which is not required to be limited in this embodiment.
S103 d: confirming two formal dividing lines vertically connected with two end points of the first boundary as a second boundary and a third boundary;
s103 e: determining the longest line segment in the second boundary and the third boundary;
the purpose of this step to S103h is to confirm the fourth boundary of the rectangular area.
It will be appreciated that where the second and third boundaries are equal in length, both the second and third boundaries meet the condition of being "longest".
S103 f: judging whether a formal dividing line which is vertically connected with the end point of the longest line segment and does not overlap with the first boundary exists, if so, going to step S103g, and if not, going to step S103 j;
since the first boundary is also vertically connected to the second boundary and the third boundary, respectively, it should be ensured that the line segment does not coincide with the first boundary during the process of identifying the fourth boundary.
S103 g: judging whether the ratio of the formal dividing line to the first boundary is in a preset ratio interval, if so, going to step S103h, and if not, going to step S103 j;
empirically, the ratio interval can be set between 1/3 and 3, although this embodiment is not limited in this respect. The effect of this step is to exclude some cases where the side length ratio is significantly misadjusted. As shown in fig. 7, when rs is the first boundary, the second three boundaries may be yr and zs, respectively, and the formal dividing line vertically connected to yr is xz; since the ratio of the length of the formal dividing line xz to the rs is not within the preset ratio interval, xz cannot satisfy the confirmation condition of the fourth boundary, and a rectangular area such as yzrs cannot be cut in the image.
S103 h: confirming the formal dividing line as a fourth boundary;
s103 i: forming a rectangular area by using the four boundaries, and storing rectangular area information;
it will be understood that the fourth boundary should lie on the same side of the longest line segment between the second and third boundaries as the first boundary, and that, where the definition of "vertically connected" is considered, "the fourth boundary and the first boundary lie on the same side of the longest line segment" should be understood as "the other end point of the first boundary and the fourth boundary (i.e., the end point that is further from the longest line segment) lies on the same side of the longest line segment".
S103 j: and (6) ending.
It should be noted that, in step S103c, there may be more than two formal dividing lines satisfying the condition, and in this case, any two formal dividing lines satisfying the condition need to be taken as the second boundary and the third boundary to perform the subsequent steps until all possible cases are traversed.
Similarly, there may be multiple formal dividing lines satisfying both steps S103f and S103g, and in this case, it is also necessary to identify each formal dividing line as a fourth boundary and perform the subsequent steps until all possible cases are traversed.
It can be seen that, after confirming a first boundary at S103b, by performing S103c-S103j, a plurality of rectangular regions may be obtained.
For other formal dividing lines parallel to the first boundary, repeating the above steps S103a to S103j, wherein the fourth boundary determined each time execution has the same relative positional relationship with the first boundary; the "relative positional relationship" herein includes "upper and lower relationships" or "left and right relationships". For example, the following steps are carried out: if the first boundary determined for the first time is a lower boundary, then the first boundary determined for the subsequent time should also be the lower boundary, rather than the upper boundary.
According to another implementation manner of this embodiment, after S103h and before S103i, the method may further include:
and judging whether the four boundaries are all larger than a preset length threshold value, if so, entering the step S103i, and if not, ending the step. The effect of this step is to exclude rectangular regions with too short sides, since such regions often do not have practical cutting significance. In practical applications, the length threshold should be specifically set according to the size of the image to be segmented, and if the size of the image is larger, a larger length threshold may be set, which is not limited in this embodiment.
Of course, this step may be performed after each boundary is determined, so that if the boundary just confirmed is determined to be smaller than the preset length threshold, the process may directly go to the ending step.
Further, in order to ensure that all the rectangular areas are determined, the above process of determining the rectangular areas may be performed again after the definition of the "first boundary" is replaced. For example, in the first round of determination, the first boundary determined first is taken as the lower boundary, and then in the second round of determination, the first boundary may be taken as the upper boundary, and then the above-described process of confirming the rectangular area may be performed again. And finally, the areas determined by the two processes are jointly used as the alternative areas to be cut.
S104: and cutting the rectangular area corresponding to the stored information from the image to be segmented.
Through S103, the information of the rectangular areas to be cut is stored, and all the rectangular areas can be cut according to the information of the rectangular areas, wherein the cut rectangular areas are the final cutting results of the images to be cut.
In another implementation manner of this embodiment, only the rectangular region with practical significance may be retained for subsequent cutting through a certain comparison algorithm, so as to reduce the workload of subsequent cutting. The cutting the rectangular region corresponding to the stored information from the image to be segmented may include the following steps:
s104 a: selecting any two areas in the rectangular area corresponding to the stored information for comparison, and reserving the information of at least one area according to the comparison result;
s104 b: selecting other regions which are not compared in the rectangular regions corresponding to the stored information, comparing the selected regions with each region which is compared and reserved, reserving information of one or two regions according to a comparison result, and repeating the step until all the rectangular regions are compared at least once;
s104 c: cutting the finally reserved rectangular area from the image to be segmented;
wherein, comparing the two areas, and reserving the information of at least one area according to the comparison result, specifically comprising:
if the second area is contained in the first area and the ratio of the area of the second area to the area of the first area is greater than a first threshold value, deleting the information of the first area and reserving the information of the second area;
if the second area comprises the first area and the ratio of the area of the second area to the area of the first area is smaller than a second threshold value, deleting the information of the second area and reserving the information of the first area;
and if the second area comprises the first area and the area of the second area is larger than a preset area threshold, deleting the information of the second area and reserving the information of the first area.
In practical applications, the first threshold and the second threshold may be set to 1/4 and 4, respectively, according to experience, and the area threshold should be specifically set according to the actual size of the image to be segmented. Of course, these should not be construed as limitations on the practice of the present application.
In addition, when the second area is compared with the first area, if none of the above three conditions are met, the information of the first area and the information of the second area should be simultaneously retained.
According to the image segmentation method provided by the embodiment of the application, possible segmentation lines of an image are determined according to pixel characteristics of rows and columns of the image to be segmented, independent area blocks in the image are determined from a rectangular area formed by line segments sandwiched by intersection points of the segmentation lines, and the area blocks are cut from the original image, so that automatic segmentation processing of a large spliced image is realized.
In another embodiment of the present application, appropriate sampling points may be pre-selected from an image to be segmented, and then the relative gradient values of rows and columns of the image to be segmented are respectively calculated by using the pre-selected sampling points, so as to improve the processing speed of image segmentation. The sampling points can be selected according to the length of the rows and the columns of the image to be segmented so as to ensure that important pixel information is not missed as much as possible. For example, let x be the length of a row/5, the sampling points of a row can be chosen as follows:
if x is less than 5, not taking a sampling point;
if x is larger than or equal to 10, selecting a sampling point by 10 pixel points;
if x is more than or equal to 5 and less than 10, selecting a sampling point by separating 5 pixel points.
In a similar way, the sampling points of the columns can be obtained. Of course, the embodiment of the present application does not need to limit the specific manner of selecting the sampling point.
The image segmentation method provided by the present application is described below with reference to a specific application example. Taking e-commerce application as an example, when a merchant publishes own goods on the internet, one or more drawings of the goods can be uploaded, and compared with characters, the images can more intuitively display the goods, and in many cases, the drawings of the goods can also be used as an important basis for a buyer to confirm the authenticity of goods information. In practice, however, for some subjective or objective reasons, the merchant uploads a number of large images that are stitched together. These large images are very disadvantageous for later data mining of e-commerce systems, (e.g., sorting goods according to their appearance, etc.).
Fig. 9, fig. 10, and fig. 11 are schematic images of a stitched image processed according to the image segmentation method provided in the present application, and fig. 8 is a flowchart of processing of the image by the method provided in the present application. The following describes in detail the process of cutting the stitched image by the method provided in the present application with reference to fig. 8, 9, 10 and 11:
as shown in fig. 8, the flow of processing for the stitched image is as follows:
s201: selecting proper sampling points according to the length of the rows and the columns of the image;
s202: calculating the relative gradient value of each row and each column according to the selected sampling points;
s203: determining the rows and columns meeting the condition of becoming the first-class alternative dividing lines as the first-class alternative dividing lines according to the relative gradient values of the rows and the columns;
the conditions for forming the first-class alternative dividing line are as follows: the relative gradient value of the row is greater than a first gradient threshold 20 and the ratio of the relative gradient value of the row to the relative gradient value of the next row is greater than a gradient ratio threshold of 4. Similarly, the condition for a column to be a first class of alternative partition lines is: the relative gradient value of the column is greater than a first gradient threshold 20 and the ratio of the relative gradient value of the column to the relative gradient value of the right-adjacent column is greater than a gradient ratio threshold of 4.
S204: calculating the color variation range of each row and each column;
s205: marking the lines which simultaneously meet the color smoothing condition and the gradient smoothing condition as smooth, and marking other lines as unsmooth; similarly, the columns that satisfy both the color smoothing condition and the gradient smoothing condition are marked as smooth, and the other columns are marked as not smooth;
wherein, the color smoothing condition is as follows: the color variation range of a row or column is less than the color range threshold 50; the gradient smoothing conditions were: the relative gradient value of a row or column is less than the zero gradient threshold 1.
S206: determining the rows and columns meeting the condition of becoming second-class alternative dividing lines as second-class alternative dividing lines according to the smooth state of each row and each column;
the conditions for the row to become the second type of alternative dividing line are as follows: the smooth states of the row and the next row are different; similarly, the condition for a column to be a second type of alternative partition line is: the smooth state of the column and the right adjacent column is different.
As shown in fig. 9, the dividing lines 01, 02, 03, 04, and 05 are candidate dividing lines of the second type of the image determined through the above-described processing, and the other dividing lines are candidate dividing lines of the first type determined.
S207: determining a line segment meeting the conditions as a formal dividing line from line segments clamped by row and column intersection points where all the alternative dividing lines formed by the first type of alternative dividing line and the second type of alternative dividing line are located;
the specific process of determining the line segment meeting the conditions as the formal dividing line comprises the following steps:
directly determining the line segment superposed with the second type of alternative dividing line as a formal dividing line of the image;
and determining the line segment meeting the gradient condition of the pixel point as a formal segmentation line in the line segment superposed with the first type of alternative segmentation line. The process of judging whether the gradient condition of the pixel point is met is as follows:
acquiring the number A of pixels of a segment which is coincident with the first-class alternative dividing line and belongs to a preset gradient interval [1, 20] relative to the gradient value, and the total number B of pixels of the current segment; and if the A/B is less than 20 percent of the ratio threshold, determining the current line segment as a formal segmentation line of the image to be segmented.
Of course, the determination of the formal dividing line should also take into account the line segment sandwiched by the intersection points of the original boundary of the image to be divided and the alternative dividing line, and will not be described in detail here.
As shown in fig. 10, all the formal parting lines that meet the conditions include: mn, fj, fk, fg, jk, jg, kg, hp, hi, pi, cd, ce, de, ab, cf, dj, dh, hj, lk, be, bi, bg, bn, ei, eg, en, ig, in, gn. In fig. 10, q is a point at which an extension line of a dividing line jd intersects with a dividing line ab, and p is a point at which an extension line of a dividing line kl intersects with a dividing line hi.
S208: forming a rectangular area by using the formal dividing line, and storing information of the rectangular area;
with reference to fig. 10, the specific process of forming the rectangular region by using the formal dividing line is as follows:
from the position of each formal dividing line, it is known
Formal parting lines that may be lower boundaries include: mn, fj, fk, fg, jk, jg, kg, hi, ce, de, ab, (mn, fj, jk, fk can only be the lower bound);
the formal parting line, which may be an upper boundary, includes: fg. jg, kg, hi, cd, ce, de, ab (cd can only be the upper bound);
the formal split lines, which may be left boundaries, include: cf. dh, dj, hj, lk, (cf is only left boundary);
the formal split line, which may be the right boundary, includes: dh. dj, hj, lk, bn, bg, bi, be, ei, eg, en, ig, in, gn, (bn, bg, bi, be, ei, eg, en, ig, in, gn are only possible right borders).
Wherein hj, lk and ig are all smaller than a preset length threshold.
The process of judging whether each formal parting line can form a rectangular area or not by taking the formal parting line which is possibly the lower boundary of the image as a first boundary is as follows:
1) and determining mn as the lower boundary of the image, wherein only a right boundary vertically connected with mn can be found in all formal dividing lines, and no left boundary exists, so that a rectangular area cannot be formed by taking mn as the lower boundary of the image.
2) Determining fj as the lower boundary of the image, wherein formal dividing lines vertically connected with two ends of fj comprise cf, dj and hj; cf can only be the left boundary of the image, and the right boundary may be dj or hj. When the right boundary is dj, the dj and cf are equal in length, cd and ce which are vertically connected with the dj and cf respectively are possible upper boundaries, the ratio of cd to fj is 1, and the lengths of the upper boundary, the lower boundary, the left boundary and the right boundary are all larger than the length threshold, so that the information of the cdjf of the area is stored; the ratio of ce to fj is in a preset ratio interval [1/3, 3], and the four boundaries are all larger than the length threshold, so the rectangular area formed by the four boundaries is also cdjf.
When the right boundary is hj, the left boundary cf is the longest, and the formal dividing lines cd and ce vertically connected with cf have the ratios of cd, ce and fj within the ratio interval, but the right boundary is smaller than the length threshold, so that the lower boundary fj and the right boundary hj cannot form a rectangular area.
Therefore, fj is defined as the lower boundary of the image, and the rectangular region that can be formed is cdjf.
3) And determining fk as a lower boundary of the image, wherein a formal dividing line vertically connected with two ends of fk comprises cf and lk, wherein cf is a left boundary, and lk is a right boundary. No matter whether an upper boundary vertically connected to cf can be found, since lk is smaller than the length threshold, a rectangular region cannot be formed with fk as the lower boundary.
4) Determining fg as the lower boundary of the image, and the formal dividing lines vertically connected with the two ends of fg are cf, ge, bg and ig;
the upper boundaries determined by taking cf as a left boundary and ge as a right boundary are ce, cd and de, because the ratios of the three determined upper boundaries to fg are all in a preset ratio area, and the lengths of the boundaries are all larger than a length threshold, the fg is taken as a lower boundary, and the rectangular areas formed by respectively taking ce, cd and de as the upper boundaries are all ceff;
taking cf as a left boundary, bg as a right boundary, bg is the longest, a formal dividing line which is vertically connected with the bg is ab, the ratio of the ab to the fg is 1, and the four boundaries at the moment are all larger than a length threshold, so that the fc is extended to be intersected with the ab to form a rectangular area abgf;
with cf as a left boundary and ig as a right boundary, because ig is smaller than the length threshold, no matter whether a formal dividing line vertically connected with the longer cf can be found, a rectangular area cannot be formed;
therefore, a rectangular region that can be formed by using fg as a lower boundary of an image is referred to as a cgf or abgf.
5) Determining jk as the lower boundary of the image, wherein the left boundary is provided with hj and dj and the right boundary is provided with lk, which are vertically connected with the two ends of jk. Since the length of lk is smaller than the length threshold, a rectangular region cannot be formed with jk as a lower boundary.
6) Determining jg as the lower boundary of the image, wherein the left boundary is provided with hj and dj which are vertically connected with the two ends of the jg, the right boundary is provided with eg, ig and bg, and because the lengths of hj and ig are smaller than the length threshold value, the rectangular area determined by taking jg as the lower boundary only has degj and qbgj.
7) The kg is determined as the lower boundary of the image, and since the length of the lk vertically connected to the left end of the kg is smaller than the length threshold, the lower boundary of the image in kg cannot constitute a rectangular region.
8) Determining hi as the lower boundary of the image, wherein the formal dividing lines vertically connected with the two ends of hi have dh, ei and bi, and because the ratios of de, ce and hi vertically connected with ei are all in a preset interval, and the length of each boundary is greater than a length threshold, a rectangular area deih can be formed; similarly, with bi as the right boundary, a rectangular region qbih may be constructed. Therefore, the image lower boundary hi can form rectangular areas deih and qbih.
9) Since ce is determined as the lower boundary of the image and there is no formal dividing line vertically connected to the left end of ce, a rectangular region cannot be formed by using ce as the lower boundary of the image.
10) De is determined as the lower boundary of the image, and no formal dividing line is vertically connected with the left end of de, so that a rectangular area cannot be formed by taking de as the lower boundary of the image.
11) Ab is defined as the lower boundary of the image, and there is no formal dividing line vertically connected to the left end of ab, so that a rectangular region cannot be formed with ab as the lower boundary of the image.
In order to find all possible rectangular areas, it is also necessary to determine a rectangular area starting from the upper boundary, the determined rectangular area being already included in the plurality of rectangular areas determined above.
In summary, the rectangular region formed by the formal dividing line includes: cdjf, cegf, degj, qbgj, deih, qbih, abgf.
S209: and comparing and judging each rectangular area according to the stored information of the rectangular areas, and cutting out the rectangular area which is reserved finally.
The specific process is as follows:
comparing the cdjf and the cegf in the stored rectangular regions cdjf, cegf, degj, qbgj, deih, qbih and abgf, wherein the rectangular region cdjf is contained in the rectangular region cegf, and the ratio of the area of the cdjf to the area of the cegf is greater than a first threshold value 1/4, so that the rectangular region cdjf is reserved, and the rectangular region cegf is deleted;
comparing the rectangular area degj with the rectangular area cdjf, and reserving the rectangular areas degj and cdjf because degj and cdjf are two completely independent rectangular areas and have no inclusion relationship;
comparing the rectangular area qbgj with the rectangular areas degj and cdjf respectively, and when the qbgj is compared with the cdjf, because the qbgj and the cdjf are two independent rectangular areas and have no included relation, simultaneously keeping the qbgj and the cdjf; when qbgj is compared with degj, the rectangular area qbgj is deleted and the rectangular area degj is reserved as the qbgj comprises the degj and the ratio of the area of the qbgj to the area of the degj is smaller than a second threshold value 4;
comparing the rectangular area deih with cdjf and degj respectively; when deih is compared to cdjf, they are two independent rectangular regions, and so remain at the same time; when deih is compared with degj, since deih is included in degj and the ratio of the area of deih to the area of degj is greater than the first threshold 1/4, the rectangular region degj is deleted and the rectangular region deih is reserved;
comparing the rectangular area qbih with the previously reserved rectangular areas cdjf and deih respectively; qbih and cdjf are two independent rectangular areas, so both remain; when qbih is compared with deih, because qbih contains deih and the ratio of the area of qbih to the area of deih is less than a second threshold value 4, deleting the rectangular area qbih and reserving the rectangular area deih;
comparing the rectangular area abgf with the previously reserved rectangular areas cdjf, deih; since abgf contains cdjf and the ratio of the area of abgf to cdjf is smaller than the second threshold 4, the rectangular region abgf is deleted, leaving the rectangular regions cdjf and deih.
In summary, after comparison, the remaining rectangular regions are cdjf and deih, and the two rectangular regions are cut from the image to be segmented. As shown in fig. 11, the rectangular region cdjf and the rectangular region deih are the final segmentation result of the image to be segmented.
In addition, for some images to be segmented with larger sizes, the gradient change and the change of the smooth state cannot well reflect the local boundary characteristics of the images, and the images to be processed can be incompletely cut after being processed by the scheme. Therefore, after the image with the size larger than a certain threshold value is segmented, if the aspect ratio of the segmented image is still very different, the segmentation result can be further segmented for the second time, even for multiple times. Fig. 12 illustrates a case where two segmentations are performed, in which three elongated images in the vertical direction are the result of the first segmentation.
Corresponding to the above method embodiment, the present application further provides an image segmentation system, as shown in fig. 13, the system comprising:
the alternative segmentation line determining module 110 is configured to determine an alternative segmentation line in the image to be selected according to the pixel characteristics of the image to be segmented;
a formal dividing line determining module 120, configured to determine, as a formal dividing line of the image to be divided, a line segment sandwiched by intersections of rows and columns of the alternative dividing lines determined by the alternative dividing line determining module 110, and determine, as a formal dividing line of the image to be divided, a line segment sandwiched by intersections of a primary boundary line of the image to be divided and the alternative dividing lines;
a rectangular region determining module 130, configured to utilize the formal parting line determined by the formal parting line determining module 120 to form a rectangular region, and store information of the rectangular region;
a rectangular region cutting module 140, configured to cut a rectangular region corresponding to the rectangular region information stored in the rectangular region determining module 130 from the image to be segmented;
the alternative dividing line determining module 110 may include:
a pixel feature calculation sub-module 111 for calculating relative gradient values of each row and each column and a smooth state;
a first candidate partition line determining submodule 112, configured to determine, according to the relative gradient values of each row and each column calculated by the pixel feature calculating submodule 111, the row and the column of which the relative gradient values are greater than a preset first gradient threshold value as a first class of candidate partition lines;
a second alternative dividing line determining submodule 113, configured to determine a second type of alternative dividing line according to the smooth state of each row and each column calculated by the pixel feature calculating submodule 111: if the smooth states of two adjacent rows are different, determining any one of the two rows as a second type of alternative dividing line; and if the smooth states of the two adjacent columns are different, determining any column in the two columns as the second type alternative dividing line.
As shown in fig. 14, the first alternative partition line determining sub-module 112 may specifically include: a first judging unit 112a, a second judging unit 112b, and a first determining unit 112 c;
a first judging unit 112a for judging whether the relative gradient value of the row is greater than a first gradient threshold value;
a second determining unit 112b, configured to determine whether a ratio of the relative gradient value of the row to the relative gradient value of the adjacent row is greater than a preset gradient ratio threshold;
a first determining unit 112c, configured to determine the row as the first class candidate dividing line if the determination results of the first determining unit 112a and the second determining unit 112b are both yes;
a first judging unit 112a, further configured to judge whether the relative gradient value of the column is greater than a first gradient threshold;
the second determining unit 112b is further configured to determine whether a ratio of the relative gradient value of the column to the relative gradient value of the adjacent row is greater than a preset gradient ratio threshold;
and a first determining unit 112c, configured to determine the column as the first type candidate dividing line if the determination results of the first determining unit 112a and the second determining unit 112b are both yes.
The pixel feature calculating sub-module 111 may include a relative gradient value calculating unit and a smooth state calculating unit;
the smooth state calculating unit is used for judging whether the line simultaneously meets a color smooth condition and a gradient smooth condition, if so, the line is judged to be smooth, and if not, the line is judged to be not smooth; and
the method is used for judging whether the row simultaneously meets a color smoothing condition and a gradient smoothing condition, if so, the row is judged to be smooth, otherwise, the row is judged to be not smooth;
the color smoothing conditions are: the color variation range of the row or the column is smaller than a preset color range threshold value;
the gradient smoothing condition is: the relative gradient value of a row or column is less than a preset zero gradient threshold.
In an embodiment of the present application, the pixel characteristic calculating sub-module 111 may use pre-selected sampling points to calculate the relative gradient values of the rows and columns of the image to be segmented, respectively.
The formal parting line determining module 120 may include:
a line segment obtaining submodule, configured to obtain a line segment included in a row and column intersection where the alternative dividing line determined by the alternative dividing line determining module 110 is located;
the line segment judgment submodule is used for directly determining the line segment which is superposed with the second type alternative dividing line as a formal dividing line of the image to be divided; and determining the line segment meeting the gradient condition of the pixel point as a formal segmentation line of the image to be segmented in the line segment superposed with the first type of alternative segmentation line.
Wherein, the pixel point gradient condition set by the line segment judgment submodule is as follows:
and A/B is smaller than a preset proportion threshold, wherein A is the number of pixel points of which the relative gradient value belongs to a preset gradient interval, and B is the total number of the pixel points of the current line segment.
The rectangular region determining module 130 may include:
the first boundary determining submodule is used for respectively determining a group of formal parting lines which are parallel to each other as first boundaries;
the second and third boundary determining sub-modules are used for determining two formal dividing lines which are respectively and vertically connected with two end points of the first boundary as a second boundary and a third boundary according to the determination result of the first boundary determining sub-module;
the fourth boundary determining submodule is used for selecting the longest line segment in the second boundary and the third boundary, and if a formal dividing line vertically connected with the end point of the line segment exists and the ratio of the line segment to the first boundary belongs to a preset ratio interval, determining the formal dividing line as a fourth boundary;
the area information storage submodule is used for forming a rectangular area by using the determined four boundaries and storing rectangular area information;
if the first line segment is perpendicular to the second line segment and the distance between the first end point of the first line segment and any end point of the second line segment is smaller than a preset threshold value, the first end point of the second line segment and the first end point of the first line segment meet a perpendicular connection condition.
In addition, the rectangular area determining module 130 may further include:
the judgment submodule is used for judging whether the four boundaries are all larger than a preset length threshold value before the four determined boundaries are used for forming the rectangular area;
and the area information storage submodule further forms a rectangular area by using the four determined boundaries and stores rectangular area information when the judgment result of the judgment submodule is yes.
The rectangular area cutting module 140 may include: a selection submodule, a comparison submodule and a cutting submodule:
the selection submodule is used for selecting any two areas in the rectangular area corresponding to the stored information; and sending the selection result to the comparison submodule;
after the comparison submodule performs at least one comparison, the selection submodule is further configured to select one other area which is not compared and one area which is compared and reserved in sequence in the rectangular area corresponding to the stored information, and send a selection result to the comparison submodule;
the comparison submodule is used for comparing the areas selected by the selection submodule and reserving information of at least one area according to a comparison result;
the cutting submodule is used for cutting the rectangular area which is finally reserved from the image to be segmented under the condition that all the rectangular areas are compared for at least one time;
wherein the comparison submodule is specifically configured to:
if the second area is contained in the first area and the ratio of the area of the second area to the area of the first area is greater than a first threshold value, deleting the information of the first area;
if the second region comprises the first region and the ratio of the area of the second region to the area of the first region is smaller than a second threshold value, deleting the information of the second region;
and if the second area comprises the first area and the area of the second area is larger than a preset area threshold value, deleting the information of the second area.
For convenience of description, the above devices are described as being divided into various modules or units by function, respectively. Of course, the functionality of the various modules or units may be implemented in the same one or more software and/or hardware when implementing the present application.
From the above description of the embodiments, it is clear to those skilled in the art that the present application can be implemented by software plus necessary general hardware platform. Based on such understanding, the technical solutions of the present application may be essentially or partially implemented in the form of a software product, which may be stored in a storage medium, such as a ROM/RAM, a magnetic disk, an optical disk, etc., and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method according to the embodiments or some parts of the embodiments of the present application.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for system embodiments, since they are substantially similar to method embodiments, they are described in a relatively simple manner, and reference may be made to some descriptions of method embodiments for relevant points. The above-described system embodiments are merely illustrative, wherein the modules or units described as separate parts may or may not be physically separate, and the parts displayed as modules or units may or may not be physical modules or units, may be located in one place, or may be distributed on a plurality of network modules or units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
The application is operational with numerous general purpose or special purpose computing system environments or configurations. For example: personal computers, server computers, hand-held or portable devices, tablet-type devices, multiprocessor systems, microprocessor-based systems, set top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments that include any of the above systems or devices, and the like.
The application may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The application may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
The foregoing is directed to embodiments of the present application and it is noted that numerous modifications and adaptations may be made by those skilled in the art without departing from the principles of the present application and are intended to be within the scope of the present application.

Claims (10)

1. An image segmentation method, comprising:
determining alternative segmentation lines in the image to be segmented according to the pixel characteristics of the rows and the columns of the image to be segmented;
determining a line segment clamped by intersection points of the rows and the columns of the alternative dividing lines as a formal dividing line of the image to be divided, and determining a line segment clamped by intersection points of a primary boundary line of the image to be divided and the alternative dividing lines as a formal dividing line of the image to be divided;
forming a rectangular area by using the formal dividing line, and storing information of the rectangular area;
cutting a rectangular area corresponding to the stored information from the image to be segmented;
the forming of the rectangular area by the formal dividing line includes:
A. determining a certain formal dividing line as a first boundary;
B. confirming two formal dividing lines which are respectively vertically connected with two end points of the first boundary as a second boundary and a third boundary;
C. selecting the longest line segment in the second boundary and the third boundary, if a formal dividing line vertically connected with the end point of the selected line segment exists and the ratio of the formal dividing line to the first boundary belongs to a preset ratio interval, determining the formal dividing line as the fourth boundary, forming a rectangular area by using the four determined boundaries, and storing rectangular area information;
for other formal dividing lines parallel to the first boundary, repeating the steps A to C, wherein the fourth boundary determined by each execution has the same relative position relation with the first boundary;
if the first line segment is perpendicular to the second line segment and the distance between the first end point of the first line segment and any end point of the second line segment is smaller than a preset threshold value, the first end point of the second line segment and the first end point of the first line segment meet a perpendicular connection condition.
2. The method of claim 1, wherein:
the determining of the alternative segmentation lines in the image to be segmented comprises the following steps:
respectively calculating relative gradient values of each row and each column of the image to be segmented, and determining the row and the column of which the relative gradient values are greater than a preset first gradient threshold as a first-class alternative segmentation line;
respectively judging whether each row and each column of the image to be segmented are smooth, if the smooth states of two adjacent rows are different, determining any row in the two rows as a second type of alternative segmentation line; and if the smooth states of the two adjacent columns are different, determining any column in the two columns as the second type alternative dividing line.
3. The method according to claim 2, wherein the determining rows and columns with relative gradient values larger than a preset first gradient threshold as the first class candidate segmentation lines comprises:
judging whether the relative gradient value of the row is larger than a first gradient threshold value or not; and is
Judging whether the ratio of the relative gradient value of the row to the relative gradient value of the adjacent row is greater than a preset gradient ratio threshold or not;
if the results of the two judgments of the line are yes, determining the line as a first-class alternative dividing line;
judging whether the relative gradient value of the row is larger than a first gradient threshold value or not; and is
Judging whether the ratio of the relative gradient value of the row to the relative gradient value of the adjacent row is greater than a preset gradient ratio threshold or not;
and if the results of the two judgments of the column are yes, determining the column as the first-class alternative dividing line.
4. The method according to claim 2, wherein the determining whether each row and each column of the image to be segmented are smooth respectively comprises:
judging whether the line simultaneously meets a color smoothing condition and a gradient smoothing condition, if so, judging that the line is smooth, otherwise, judging that the line is not smooth;
judging whether the row simultaneously meets a color smoothing condition and a gradient smoothing condition, if so, judging that the row is smooth, otherwise, judging that the row is not smooth;
the color smoothing conditions are: the color variation range of the row or the column is smaller than a preset color range threshold value;
the gradient smoothing condition is: the relative gradient value of a row or column is less than a preset zero gradient threshold.
5. The method according to claim 2, wherein the line segment sandwiched by intersections of rows and columns where the alternative dividing lines are located is determined as a formal dividing line of the image to be divided, and specifically:
obtaining a line segment clamped by intersection points of rows and columns where the alternative dividing lines are located;
directly determining the line segment which is overlapped with the second type of alternative segmentation line as a formal segmentation line of the image to be segmented;
and determining the line segment meeting the gradient condition of the pixel point as a formal segmentation line of the image to be segmented in the line segment superposed with the first type of alternative segmentation line.
6. The method as claimed in claim 5, wherein the determining the line segment meeting the gradient condition of the pixel point as a formal segmentation line of the image to be segmented comprises:
acquiring the number A of pixel points of a current segment, the relative gradient value of which belongs to a preset gradient interval, and the total number B of the pixel points of the current segment;
and if the A/B is smaller than a preset ratio threshold, determining the current line segment as a formal segmentation line of the image to be segmented.
7. The method of claim 1, further comprising, before forming a rectangular region using the determined four boundaries:
and judging whether the four boundaries are all larger than a preset length threshold value, if so, further utilizing the four determined boundaries to form a rectangular area, and storing information of the rectangular area.
8. The method according to claim 2, wherein the cutting out the rectangular region corresponding to the saved information from the image to be segmented comprises:
selecting any two areas in the rectangular area corresponding to the stored information for comparison, and reserving the information of at least one area according to the comparison result;
selecting other regions which are not compared in the rectangular regions corresponding to the stored information, comparing the selected regions with each region which is compared and reserved, reserving information of one or two regions according to a comparison result, and repeating the step until all the rectangular regions are compared at least once;
cutting the finally reserved rectangular area from the image to be segmented;
wherein, comparing the two areas, and reserving the information of at least one area according to the comparison result, specifically comprising:
if the second area is contained in the first area and the ratio of the area of the second area to the area of the first area is greater than a first threshold value, deleting the information of the first area;
if the second region comprises the first region and the ratio of the area of the second region to the area of the first region is smaller than a second threshold value, deleting the information of the second region;
and if the second area comprises the first area and the area of the second area is larger than a preset area threshold value, deleting the information of the second area.
9. The method according to any one of claims 2 to 6 or 8, wherein the calculating the relative gradient values of each row and each column of the image to be segmented is performed by:
and respectively calculating the relative gradient values of the rows and the columns of the image to be segmented by utilizing the preselected sampling points.
10. An image segmentation system, comprising:
the alternative segmentation line determining module is used for determining alternative segmentation lines in the image to be selected according to the pixel characteristics of the image to be segmented;
the formal dividing line determining module is used for determining a line segment which is sandwiched by intersection points of rows and columns of the alternative dividing lines determined by the alternative dividing line determining module as a formal dividing line of the image to be divided and determining a line segment which is sandwiched by intersection points of a primary boundary line of the image to be divided and the alternative dividing lines as a formal dividing line of the image to be divided;
the rectangular area determining module is used for forming a rectangular area by using the formal parting line determined by the formal parting line determining module and storing rectangular area information;
the rectangular region cutting module is used for cutting the rectangular region corresponding to the rectangular region information stored in the rectangular region determining module from the image to be segmented;
the forming of the rectangular area by the formal parting line determined by the formal parting line determining module comprises the following steps:
A. determining a certain formal dividing line as a first boundary;
B. confirming two formal dividing lines which are respectively vertically connected with two end points of the first boundary as a second boundary and a third boundary;
C. selecting the longest line segment in the second boundary and the third boundary, if a formal dividing line vertically connected with the end point of the selected line segment exists and the ratio of the formal dividing line to the first boundary belongs to a preset ratio interval, determining the formal dividing line as the fourth boundary, forming a rectangular area by using the four determined boundaries, and storing rectangular area information;
for other formal dividing lines parallel to the first boundary, repeating the steps A to C, wherein the fourth boundary determined by each execution has the same relative position relation with the first boundary;
if the first line segment is perpendicular to the second line segment and the distance between the first end point of the first line segment and any end point of the second line segment is smaller than a preset threshold value, the first end point of the second line segment and the first end point of the first line segment meet a perpendicular connection condition.
HK12108961.4A 2012-09-13 Method and system for dividing an image HK1168185B (en)

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201010592877.6A CN102567952B (en) 2010-12-16 2010-12-16 Image segmentation method and system

Publications (2)

Publication Number Publication Date
HK1168185A1 true HK1168185A1 (en) 2012-12-21
HK1168185B HK1168185B (en) 2015-01-30

Family

ID=

Also Published As

Publication number Publication date
CN102567952B (en) 2014-07-16
CN102567952A (en) 2012-07-11

Similar Documents

Publication Publication Date Title
JP7016943B2 (en) Methods, devices and equipment for object detection
CN107784301B (en) Method and device for recognizing character area in image
CN102567952B (en) Image segmentation method and system
CN109670500A (en) A kind of character area acquisition methods, device, storage medium and terminal device
CN111797829A (en) License plate detection method and device, electronic equipment and storage medium
CN112686595A (en) Method, device, equipment and storage medium for detecting illegal behavior of logistics operation
CN113240623A (en) Pavement disease detection method and device
CN110599453A (en) Panel defect detection method and device based on image fusion and equipment terminal
CN109034136A (en) Image processing method, device, picture pick-up device and storage medium
US20170169056A1 (en) Logo detection system for automatic image search engines
CN112329548A (en) Document chapter segmentation method and device and storage medium
CN112488220A (en) Small target detection method based on deep learning
US20130294707A1 (en) Geometric modelization of images and applications
CN112070792B (en) Edge growth connection method and device for image segmentation
CN117523087A (en) Three-dimensional model optimization method based on content recognition
US11532106B2 (en) Color gradient capture from source image content
CN113570565B (en) Vehicle appearance defect detection method, device and storage medium
CN106503740A (en) Picture classification method and device
CN116994721B (en) Quick processing system of digital pathological section graph
CN112434585A (en) Method, system, electronic device and storage medium for identifying virtual reality of lane line
HK1168185B (en) Method and system for dividing an image
CN114511862B (en) Form identification method and device and electronic equipment
CN106845350A (en) A kind of tree-shaped node recognition methods based on image procossing
CN113361483B (en) A traffic speed limit sign detection method, device, equipment and storage medium
CN113487697B (en) Method and device for generating simple drawing, electronic equipment and storage medium