CN116489288A - Method and device for solving maximum connected domain in image - Google Patents

Method and device for solving maximum connected domain in image Download PDF

Info

Publication number
CN116489288A
CN116489288A CN202310731096.8A CN202310731096A CN116489288A CN 116489288 A CN116489288 A CN 116489288A CN 202310731096 A CN202310731096 A CN 202310731096A CN 116489288 A CN116489288 A CN 116489288A
Authority
CN
China
Prior art keywords
line
connected domain
line segment
image
adjacent
Prior art date
Legal status (The legal status 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 status listed.)
Granted
Application number
CN202310731096.8A
Other languages
Chinese (zh)
Other versions
CN116489288B (en
Inventor
李方
郭丽
黄缚鹏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Jiangsu Yibaijuzhi Technology Co ltd
Beijing Yibai Technology Co ltd
Original Assignee
Jiangsu Yibaijuzhi Technology Co ltd
Beijing Yibai Technology Co ltd
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 Jiangsu Yibaijuzhi Technology Co ltd, Beijing Yibai Technology Co ltd filed Critical Jiangsu Yibaijuzhi Technology Co ltd
Priority to CN202310731096.8A priority Critical patent/CN116489288B/en
Publication of CN116489288A publication Critical patent/CN116489288A/en
Application granted granted Critical
Publication of CN116489288B publication Critical patent/CN116489288B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N5/00Details of television systems
    • H04N5/14Picture signal circuitry for video frequency region
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/187Segmentation; Edge detection involving region growing; involving region merging; involving connected component labelling
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/60Analysis of geometric attributes
    • G06T7/62Analysis of geometric attributes of area, perimeter, diameter or volume
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N7/00Television systems
    • H04N7/14Systems for two-way working
    • H04N7/15Conference systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/10Image acquisition modality
    • G06T2207/10016Video; Image sequence

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Multimedia (AREA)
  • Signal Processing (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Geometry (AREA)
  • Image Analysis (AREA)

Abstract

The method scans each line of an image according to a preset direction in a line scanning mode, establishes a binding relation between a connected domain to which a line segment in a current scanning line belongs and a connected domain to which a line segment adjacent to the current scanning line segment in a previous line scanning line belongs, and calculates the area of the largest connected domain with the binding relation as the largest connected domain of the image after all scanning is completed. According to the scheme provided by the application, the access of the whole image pixel can be completed through one-time scanning under the condition that a plurality of connected domains coexist, and the maximum connected domain of the image is obtained, so that the method has the advantages of being small in memory occupation and high in running speed.

Description

Method and device for solving maximum connected domain in image
Technical Field
The present invention relates to the field of image detection editing, and in particular, to a method and apparatus for obtaining a maximum connected domain in an image.
Background
The natural matting is an algorithm for detecting images by using a neural network under the condition of not limiting the background, and has been widely applied to video conferences. In a video conference scenario, it is necessary to keep the largest part of the image, for example, when someone breaks in during a single video conference, only the main character is wanted to be left, and other unnecessary parts are deleted from the image frame. This need to preserve the main character can be reduced to the problem of solving the maximum connected domain.
The existing method for solving the maximum connected domain in the image searches each connected domain by using a filling algorithm of an irregular graph, and most commonly comprises a 4 connected domain point diffusion method and a traditional line scanning algorithm. The existing methods have the following problems: (1) Based on recursive program structure, there is a risk of stack too deep in the middle of the push; (2) It is only responsible for finding one connected domain, since the original purpose of the algorithm is to fill in. Therefore, for a graph with a plurality of connected domains, the algorithm must be repeatedly executed until all the connected domains are found out; (3) An additional image-size memory space is required to store the tracks that have been accessed.
Disclosure of Invention
Aiming at the problems in the prior art, a method for completing the access of the whole image pixels through one scanning under the condition that a plurality of connected domains coexist and obtaining the largest connected domain of the image is needed. The method scans each row of the image according to a preset direction in a line scanning mode, establishes a binding relation between the connected domain to which a line segment in a current scanning line belongs and the connected domain to which a line segment adjacent to the current scanning line segment in a previous row of scanning line belongs, and calculates the area of the largest connected domain with the binding relation as the largest connected domain of the image after all scanning is completed.
According to a first aspect of the present application, a method for obtaining a maximum connected domain in an image is provided, including:
step S101, scanning the image line according to a preset scanning direction, and generating a current scanning line;
step S102, determining whether continuous target format pixel points exist on the current scanning line;
step S103, under the condition that continuous target format pixel points exist in the current scanning line, the continuous target format pixel points are used as first line segments;
step S104, judging whether a second adjacent line segment exists in the last scanning line or not in the first line segment under the condition that the current scanning line is not the first scanning line of the image;
step S105, when the first line segment does not have the adjacent second line segment in the previous scan line, generating a new connected domain as the connected domain to which the first line segment belongs, adding the newly generated connected domain to the connected domain set, taking the next line of the image as the current scan line, and returning to step S102;
step S106, when one or more adjacent second line segments exist in the previous scanning line in the first line segment, establishing a binding relationship between the connected domain to which the first line segment belongs and the connected domain to which the one or more adjacent second line segments respectively belong, and returning to step S102 by taking the next line of the image as the current scanning line;
step S107, when the current scanning line is the last scanning line of the image, calculating total areas of connected domains with binding relations in the connected domain set respectively, and determining the connected domain with the binding relations corresponding to the maximum total area as the maximum connected domain of the image.
According to some embodiments, the establishing a binding relationship between the connected domain to which the first line segment belongs and the connected domain corresponding to each of the one or more adjacent second line segments includes:
determining the connected domain to which the first line segment belongs as the connected domain to which one second line segment selected from the one or more second line segments belongs, and taking the connected domain to which the selected second line segment belongs as a root connected domain;
when there are a plurality of adjacent second line segments, the connected domain to which another second line segment among the plurality of second line segments belongs is regarded as a sub connected domain corresponding to the root connected domain.
According to some embodiments, the calculating the total area of the connected domains having the binding relationship in the connected domain set includes:
and respectively solving the areas of all root connected domains and sub connected domains in the connected domain collection.
According to some embodiments, the establishing a binding relationship between the connected domain to which the first line segment belongs and the connected domain corresponding to each of the plurality of adjacent second line segments includes:
and marking the connected domain to which the first line segment belongs and the connected domain corresponding to each of the plurality of adjacent second line segments with the same mark.
According to some embodiments, the calculating the total area of the connected domains having the binding relationship in the connected domain set includes:
the areas of all connected domains having the same identity are added.
According to some embodiments, the establishing a binding relationship between the connected domain to which the first line segment belongs and the connected domain corresponding to each of the plurality of adjacent second line segments includes:
and determining the connected domain to which the first line segment belongs as the connected domain to which the second line segment belongs when the first line segment has an adjacent second line segment on the last scanning line.
According to some embodiments, the method further comprises:
a first line segment formed by each segment of continuous target format pixel points in the current scanning line generates a line segment set of the current scanning line.
According to some embodiments, the determining whether the first line segment has an adjacent second line segment in the previous scan line includes:
and determining that a second adjacent line segment exists in the first line segment.
According to a second aspect of the present application, a matting method is provided, including:
processing pixel point formats of a target object and a non-target object in the image to generate a target format pixel point and a non-target format pixel point;
generating a maximum connected domain formed by the target format pixel points according to the method in the first aspect of the application;
and reserving a maximum connected domain formed by the pixel points in the target format, and setting other pixel points in the image as a preset filtering format.
According to a third aspect of the present application, a device for solving a maximum connected domain in an image is provided, including an initial scanning module, a line segment judging module, a line segment generating module, an adjacent judging module, a connected domain generating module, a binding relation module and an area calculating module, wherein:
the initial scanning module is used for scanning the image line according to a preset scanning direction to generate a current scanning line;
the line segment judging module is used for determining whether continuous target format pixel points exist on the current scanning line;
the line segment generation module is used for taking the continuous target format pixel points as a first line segment under the condition that the continuous target format pixel points exist in the current scanning line;
the adjacency judging module is used for judging whether the first line segment has an adjacency second line segment or not in the last scanning line under the condition that the current scanning line is not the first scanning line of the image;
the connected domain generation module is used for generating a new connected domain as a connected domain to which the first line segment belongs when the first line segment does not have the adjacent second line segment in the previous scanning line, adding the newly generated connected domain into a connected domain set, taking the next line of an image as the current scanning line, and re-determining whether continuous target format pixel points exist on the current scanning line;
the binding relation module is used for establishing a binding relation between a connected domain to which the first line segment belongs and a connected domain to which the one or more adjacent second line segments respectively belong under the condition that one or more adjacent second line segments exist in the previous scanning line of the first line segment, and re-determining whether continuous target format pixel points exist on the current scanning line or not by taking the next line of an image as the current scanning line;
the area calculation module is used for respectively calculating the total area of the connected domains with binding relation in the connected domain set under the condition that the current scanning line is the last scanning line of the image, and determining the connected domain with binding relation corresponding to the maximum total area as the maximum connected domain of the image.
According to a fourth aspect of the present application, there is provided an electronic device comprising:
a processor;
a memory storing a computer program which, when executed by the processor, causes the processor to perform the method according to the first aspect of the present application.
According to a fifth aspect of the present application, there is provided a non-transitory computer readable storage medium having stored thereon computer readable instructions which, when executed by a processor, cause the processor to perform a method as described in the first aspect of the present application.
According to the method and the device for solving the maximum connected domain in the image, each line of the image is scanned according to the preset direction in a line scanning mode, the binding relation between the connected domain to which the line segment in the current scanning line belongs and the connected domain to which the line segment adjacent to the current scanning line segment in the previous line scanning line belongs is established, and after all scanning is completed, the area of the maximum connected domain with the binding relation is calculated to serve as the maximum connected domain of the image. According to the scheme provided by the application, the access of the whole image pixel can be completed through one-time scanning under the condition that a plurality of connected domains coexist, and the maximum connected domain of the image is obtained, so that the method has the advantages of being small in memory occupation and high in running speed.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the description of the embodiments will be briefly described below, and it is apparent that the drawings in the following description are only some embodiments of the present application, and that other drawings can be obtained by those skilled in the art from these drawings without departing from the scope of protection of the present application.
FIG. 1 is a flow chart of a method of finding a maximum connected domain in an image according to the present application;
FIG. 2 is a flow chart of a matting method of the present application;
FIG. 3 is a schematic diagram of an apparatus for determining a maximum connected domain in an image according to the present application;
FIG. 4 is a schematic diagram of an embodiment of solving an area of a connected domain in a method of solving a maximum connected domain in an image according to the present application;
fig. 5 is a block diagram of an electronic device provided in the present application.
Detailed Description
The following description of the embodiments of the present application will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are some, but not all, of the embodiments of the present application. All other embodiments, which can be made by those skilled in the art based on the embodiments herein without making any inventive effort, are intended to be within the scope of the present application.
Fig. 1 is a flowchart of a method for determining a maximum connected domain in an image according to the present application. As shown in fig. 1, the method includes the following steps.
Step S101, scanning the image line according to a preset scanning direction, and generating a current scanning line.
Step S102, determining whether there are continuous pixels in the target format on the current scan line.
Step S103, in the case that there is a continuous target format pixel point in the current scan line, the continuous target format pixel point is taken as a first line segment.
In some embodiments, the predetermined scanning direction is a horizontal direction. In some embodiments, all rows of pixels of the entire image are scanned in a preset scanning direction. In some embodiments, the current scan line is generated in the scan.
In some embodiments, the image includes target format pixels and non-target format pixels. In some embodiments, the target is a person. In some embodiments, the image content is identified, pixels associated with the person are identified as target format pixels, and pixels not associated with the person are identified as non-target format pixels. In some embodiments, the target format pixel is set to a white pixel and the non-target format pixel is set to a black pixel.
In some embodiments, there are consecutive pixels in the target format on the current scan line, and the consecutive pixels in the target format are used as the first line segment. In some embodiments, there are a plurality of first line segments on the current scan line. In some embodiments, a set of line segments for a current scan line is generated from a plurality of first line segments present on the current scan line.
Step S104, judging whether the first line segment has an adjacent second line segment in the last scanning line or not under the condition that the current scanning line is not the first scanning line of the image.
In some embodiments, the current scan line is the first scan line of the image, and the next line of the image is taken as the current scan line, and the process returns to step S102.
In some embodiments, the current scan line is not the first scan line of the image, and it is determined whether each first line segment on the current scan line has an adjacent second line segment on the previous scan line. In some embodiments, the target format pixel point with the same coordinate in the direction perpendicular to the preset scanning direction on the first line segment exists on the previous scanning line, and the first line segment exists on the next second line segment on the previous scanning line. In some embodiments, the line segment of the previous scan line to which the pixel points of the target format having the same coordinates in the direction perpendicular to the preset scan direction belong is the second line segment.
Step S105, when the first line segment does not have the adjacent second line segment in the previous scan line, generating a new connected domain as the connected domain to which the first line segment belongs, adding the newly generated connected domain to the connected domain set, taking the next line of the image as the current scan line, and returning to step S102.
In some embodiments, the first line segment does not have an adjacent second line segment in the previous scan line, and a new connected domain is generated as the connected domain to which the first line segment belongs. In some embodiments, the newly generated connected domain is added to the connected domain set. In some embodiments, the next line of the image is taken as the current scan line, returning to step S102.
Step S106, when one or more adjacent second line segments exist in the previous scan line in the first line segment, a binding relationship between the connected domain to which the first line segment belongs and the connected domain to which the one or more adjacent second line segments respectively belong is established, and the next line of the image is taken as the current scan line, and the step S102 is returned.
In some embodiments, the first line segment has a second adjacent line segment on the previous scan line, and the connected domain to which the first line segment belongs is determined as the connected domain to which the second line segment belongs.
In some embodiments, the first line segment has a plurality of adjacent second line segments on the previous scan line, the connected domain to which the first line segment belongs is determined as the connected domain to which the selected one of the plurality of second line segments belongs, and the connected domain to which the selected second line segment belongs is taken as the root connected domain. In some embodiments, there are a plurality of adjacent second line segments, and a connected domain to which another second line segment other than the selected second line segment belongs from the plurality of second line segments is taken as a sub connected domain corresponding to the root connected domain.
In some embodiments, the first line segment has a plurality of adjacent second line segments on the previous scan line, and the connected domain marks corresponding to each of the plurality of adjacent second line segments and the connected domain to which the first line segment belongs are labeled with the same identifier.
Step S107, when the current scanning line is the last scanning line of the image, calculating total areas of connected domains with binding relations in the connected domain set respectively, and determining the connected domain with the binding relations corresponding to the maximum total area as the maximum connected domain of the image.
In some embodiments, the first line segment has an adjacent second line segment on the previous scan line, the areas of all the root connected domains and the sub connected domains in the connected domain aggregate are solved respectively, and the root connected domain and the sub connected domain with the largest area are used as the largest connected domain of the image.
In some embodiments, the first line segment has a second adjacent line segment on the previous scan line, the areas of all connected domains with the same identifier are added, and the connected domain set with the same identifier with the largest area is used as the largest connected domain of the image.
According to the method and the device for solving the maximum connected domain in the image, each line of the image is scanned according to the preset direction in a line scanning mode, the binding relation between the connected domain to which the line segment in the current scanning line belongs and the connected domain to which the line segment adjacent to the current scanning line segment in the previous line scanning line belongs is established, and after all scanning is completed, the area of the maximum connected domain with the binding relation is calculated to serve as the maximum connected domain of the image. According to the scheme provided by the application, the access of the whole image pixel can be completed through one-time scanning under the condition that a plurality of connected domains coexist, the maximum connected domain of the image is obtained, and the method has the advantages of being small in memory occupation and high in running speed.
Fig. 2 is a flow chart of a matting method of the present application. As shown in fig. 2, the method includes the following steps.
Step S201, processing the pixel formats of the target object and the non-target object in the image, and generating a target format pixel and a non-target format pixel.
In some embodiments, the image includes target format pixels and non-target format pixels. In some embodiments, the target is a person. In some embodiments, the image content is identified, pixels associated with the person are identified as target format pixels, and pixels not associated with the person are identified as non-target format pixels. In some embodiments, the target format pixel is set to a white pixel and the non-target format pixel is set to a black pixel.
Step S202, generating the maximum connected domain formed by the pixel points in the target format according to the method as described in fig. 1.
Step S203, reserving a maximum connected domain formed by the pixel points in the target format, and setting other pixel points in the image as a preset filtering format.
In some embodiments, the image is scanned to generate a maximum connected domain of pixels in the target format. In some embodiments, the pixels of the maximum connected domain are reserved, and other pixels in the image are set to a preset filtering format. In some embodiments, the predetermined filtering format is to set the pixel value to 0.
Fig. 3 is a schematic diagram of an apparatus for obtaining a maximum connected domain in an image according to the present application. As shown in fig. 3, the device for obtaining the maximum connected domain in the image includes an initial scanning module, a line segment judging module, a line segment generating module, an adjacent judging module, a connected domain generating module, a binding relation module and an area calculating module.
The initial scanning module is used for scanning the image line according to a preset scanning direction and generating a current scanning line.
The line segment judging module is used for determining whether continuous target format pixel points exist on the current scanning line.
The line segment generation module is used for taking the continuous target format pixel points as a first line segment under the condition that the continuous target format pixel points exist in the current scanning line.
In some embodiments, the predetermined scanning direction is a horizontal direction. In some embodiments, all rows of pixels of the entire image are scanned in a preset scanning direction. In some embodiments, the current scan line is generated in the scan.
In some embodiments, the image includes target format pixels and non-target format pixels. In some embodiments, the target is a person. In some embodiments, the image content is identified, pixels associated with the person are identified as target format pixels, and pixels not associated with the person are identified as non-target format pixels. In some embodiments, the target format pixel is set to a white pixel and the non-target format pixel is set to a black pixel.
In some embodiments, there are consecutive pixels in the target format on the current scan line, and the consecutive pixels in the target format are used as the first line segment. In some embodiments, there are a plurality of first line segments on the current scan line. In some embodiments, a set of line segments for a current scan line is generated from a plurality of first line segments present on the current scan line.
And the adjacency judging module is used for judging whether the first line segment has an adjacency second line segment in the last scanning line or not under the condition that the current scanning line is not the first scanning line of the image.
In some embodiments, the current scan line is the first scan line of the image, and the next line of the image is taken as the current scan line, and whether continuous pixels in the target format exist on the current scan line is determined again.
In some embodiments, the current scan line is not the first scan line of the image, and it is determined whether each first line segment on the current scan line has an adjacent second line segment on the previous scan line. In some embodiments, the target format pixel point with the same coordinate in the direction perpendicular to the preset scanning direction on the first line segment exists on the previous scanning line, and the first line segment exists on the next second line segment on the previous scanning line. In some embodiments, the line segment of the previous scan line to which the pixel points of the target format having the same coordinates in the direction perpendicular to the preset scan direction belong is the second line segment.
The connected domain generation module is used for generating a new connected domain as the connected domain to which the first line segment belongs when the first line segment does not have the adjacent second line segment in the last scanning line, adding the newly generated connected domain into the connected domain set, taking the next line of the image as the current scanning line, and re-determining whether continuous target format pixel points exist on the current scanning line.
In some embodiments, the first line segment does not have an adjacent second line segment in the previous scan line, and a new connected domain is generated as the connected domain to which the first line segment belongs. In some embodiments, the newly generated connected domain is added to the connected domain set. In some embodiments, the next line of the image is taken as the current scanning line, and whether continuous pixels in the target format exist on the current scanning line is determined again.
The binding relation module is used for establishing a binding relation between a connected domain to which the first line segment belongs and a connected domain to which the one or more adjacent second line segments respectively belong under the condition that one or more adjacent second line segments exist in the previous scanning line of the first line segment, and re-determining whether continuous target format pixel points exist on the current scanning line or not by taking the next line of the image as the current scanning line.
In some embodiments, the first line segment has a second adjacent line segment on the previous scan line, and the connected domain to which the first line segment belongs is determined as the connected domain to which the second line segment belongs.
In some embodiments, the first line segment has a plurality of adjacent second line segments on the previous scan line, the connected domain to which the first line segment belongs is determined as the connected domain to which the selected one of the plurality of second line segments belongs, and the connected domain to which the selected second line segment belongs is taken as the root connected domain. In some embodiments, there are a plurality of adjacent second line segments, and a connected domain to which another second line segment other than the selected second line segment belongs from the plurality of second line segments is taken as a sub connected domain corresponding to the root connected domain.
In some embodiments, the first line segment has a plurality of adjacent second line segments on the previous scan line, and the connected domain marks corresponding to each of the plurality of adjacent second line segments and the connected domain to which the first line segment belongs are labeled with the same identifier.
The area calculation module is used for respectively calculating the total area of the connected domains with binding relation in the connected domain set under the condition that the current scanning line is the last scanning line of the image, and determining the connected domain with binding relation corresponding to the maximum total area as the maximum connected domain of the image.
In some embodiments, the first line segment has an adjacent second line segment on the previous scan line, the areas of all the root connected domains and the sub connected domains in the connected domain aggregate are solved respectively, and the root connected domain and the sub connected domain with the largest area are used as the largest connected domain of the image.
In some embodiments, the first line segment has a second adjacent line segment on the previous scan line, the areas of all connected domains with the same identifier are added, and the connected domain set with the same identifier with the largest area is used as the largest connected domain of the image.
Fig. 4 is a schematic diagram of an embodiment of solving an area of a connected domain in the method for solving a maximum connected domain in an image in the present application.
Referring to fig. 4, in some embodiments, the current scan line is scan line 1, and the line segments of the scan line 1 having consecutive pixels in the preset format include line segments 1 and 2. The line segment 1 is a line on the line above the line segment 1, and is not a pixel point with a preset format at the same coordinate in the direction perpendicular to the scanning direction, so that the line segment 1 is generated into a new connected domain 3 to which the line segment belongs. The line segment 2 is a scanning line in the last row, and pixels with preset formats exist at the same coordinate in the direction perpendicular to the scanning direction. The first continuous pixel point with the preset format in the previous line of scanning line belongs to a line segment 3, and the connected domain to which the line segment 3 belongs is a connected domain 1, so that the connected domain to which the line segment 2 belongs is determined as the connected domain 1.
In some embodiments, the line segment 2 is also in an adjacent relationship with the line segment 4 belonging to the connected domain 2, so that the connected domain 1 and the connected domain 2 are set to be the same identifier as the connected domain set 1. Similarly, on the scanning line 2, the connected domain to which the line segment 7 belongs is determined as the connected domain 3, and the line segment 7 and the line segment 6 have an adjacent relationship, so that the connected domain 3 is set and identified as the connected domain set 1 as the connected domain 1. And after the scanning is finished, calculating the areas of all the connected domains with the connected domain set 1 marks, namely the areas of the currently-calculated connected domains.
In some embodiments, the line segment 2 is in an adjacent relationship with the line segment 3 and the line segment 4, so that the connected domain 1 to which the line segment 3 and the line segment 2 belong is determined as a root connected domain, and the connected domain 2 to which the line segment 4 belongs is determined as a sub connected domain corresponding to the root connected domain. Similarly, connected domain 3 to which line segment 5 and line segment 7 belong is defined as a root connected domain, and connected domain 1 to which line segment 6 belongs is defined as a child connected domain. Thus, the connected domain 3 is the root connected domain of the connected domain 1, and the connected domain 1 is the root connected domain of the connected domain 2. And calculating the area of the top-most root connected domain, namely connected domain 3 and all sub connected domains thereof, namely the area of the currently-calculated connected domain.
Referring to fig. 5, fig. 5 provides an electronic device including a processor and a memory. The memory stores computer instructions that, when executed by the processor, cause the processor to execute the computer instructions to implement the method and refinement as shown in fig. 1 or fig. 2.
It should be understood that the above-described device embodiments are illustrative only and that the disclosed device may be implemented in other ways. For example, the division of the units/modules in the above embodiments is merely a logic function division, and there may be another division manner in actual implementation. For example, multiple units, modules, or components may be combined, or may be integrated into another system, or some features may be omitted or not performed.
In addition, unless specifically described, each functional unit/module in each embodiment of the present invention may be integrated into one unit/module, or each unit/module may exist alone physically, or two or more units/modules may be integrated together. The integrated units/modules described above may be implemented either in hardware or in software program modules.
The integrated units/modules, if implemented in hardware, may be digital circuits, analog circuits, etc. Physical implementations of hardware structures include, but are not limited to, transistors, memristors, and the like. The processor or chip may be any suitable hardware processor, such as CPU, GPU, FPGA, DSP and ASIC, etc., unless otherwise specified. The on-chip cache, off-chip Memory, memory may be any suitable magnetic or magneto-optical storage medium, such as resistive Random Access Memory RRAM (Resistive Random Access Memory), dynamic Random Access Memory DRAM (Dynamic Random Access Memory), static Random Access Memory SRAM (Static Random Access Memory), enhanced dynamic Random Access Memory EDRAM (Enhanced Dynamic Random Access Memory), high-Bandwidth Memory HBM (High-Bandwidth Memory), hybrid Memory cube HMC (Hybrid Memory Cube), and the like, unless otherwise indicated.
The integrated units/modules may be stored in a computer readable memory if implemented in the form of software program modules and sold or used as a stand-alone product. Based on such understanding, the technical solution of the present invention may be embodied in essence or a part contributing to the prior art or all or part of the technical solution in the form of a software product stored in a memory, comprising several instructions for causing a computer device (which may be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present disclosure. And the aforementioned memory includes: a U-disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a removable hard disk, a magnetic disk, or an optical disk, or other various media capable of storing program codes.
Embodiments of the present application also provide a non-transitory computer storage medium storing a computer program that, when executed by a plurality of processors, causes the processors to perform the method and refinement as shown in fig. 1 or fig. 2.
The foregoing has outlined rather broadly the more detailed description of embodiments of the present application, wherein specific examples have been provided herein to illustrate the principles and embodiments of the present application, and wherein the above examples are provided to assist in the understanding of the methods and concepts of the present application. Meanwhile, based on the ideas of the present application, those skilled in the art can make changes or modifications on the specific embodiments and application scope of the present application, which belong to the scope of the protection of the present application. In view of the foregoing, this description should not be construed as limiting the application.

Claims (12)

1. A method of solving a maximum connected domain in an image, comprising:
step S101, scanning the image line according to a preset scanning direction, and generating a current scanning line;
step S102, determining whether continuous target format pixel points exist on the current scanning line;
step S103, under the condition that continuous target format pixel points exist in the current scanning line, the continuous target format pixel points are used as first line segments;
step S104, judging whether a second adjacent line segment exists in the last scanning line or not in the first line segment under the condition that the current scanning line is not the first scanning line of the image;
step S105, when the first line segment does not have the adjacent second line segment in the previous scan line, generating a new connected domain as the connected domain to which the first line segment belongs, adding the newly generated connected domain to the connected domain set, taking the next line of the image as the current scan line, and returning to step S102;
step S106, when one or more adjacent second line segments exist in the previous scanning line in the first line segment, establishing a binding relationship between the connected domain to which the first line segment belongs and the connected domain to which the one or more adjacent second line segments respectively belong, and returning to step S102 by taking the next line of the image as the current scanning line;
step S107, when the current scanning line is the last scanning line of the image, calculating total areas of connected domains with binding relations in the connected domain set respectively, and determining the connected domain with the binding relations corresponding to the maximum total area as the maximum connected domain of the image.
2. The method of claim 1, wherein the establishing a binding relationship between the connected domain to which the first line segment belongs and each corresponding connected domain in the one or more contiguous second line segments comprises:
determining the connected domain to which the first line segment belongs as the connected domain to which one second line segment selected from the one or more second line segments belongs, and taking the connected domain to which the selected second line segment belongs as a root connected domain;
when there are a plurality of adjacent second line segments, the connected domain to which another second line segment among the plurality of second line segments belongs is regarded as a sub connected domain corresponding to the root connected domain.
3. The method of claim 2, wherein the calculating the total area of connected domains having binding relations in the connected domain set, respectively, comprises:
and respectively solving the areas of all root connected domains and sub connected domains in the connected domain collection.
4. The method of claim 1, wherein the establishing a binding relationship between the connected domain to which the first line segment belongs and the connected domain corresponding to each of the plurality of adjacent second line segments comprises:
and marking the connected domain to which the first line segment belongs and the connected domain corresponding to each of the plurality of adjacent second line segments with the same mark.
5. The method of claim 4, wherein the calculating the total area of connected domains in the connected domain set having a binding relationship comprises:
the areas of all connected domains having the same identity are added.
6. The method of claim 1, wherein the establishing a binding relationship between the connected domain to which the first line segment belongs and the connected domain corresponding to each of the plurality of adjacent second line segments comprises:
and determining the connected domain to which the first line segment belongs as the connected domain to which the second line segment belongs when the first line segment has an adjacent second line segment on the last scanning line.
7. The method of claim 1, wherein the method further comprises:
a first line segment formed by each segment of continuous target format pixel points in the current scanning line generates a line segment set of the current scanning line.
8. The method of claim 7, wherein determining whether the first line segment has an adjacent second line segment on a previous scan line comprises:
and determining that a second adjacent line segment exists in the last scanning line of the first line segment in response to the existence of the pixel point with the target format, which is the same as the coordinate of the pixel point with the target format, on the last scanning line, in the direction perpendicular to the preset scanning direction.
9. A matting method comprising:
processing pixel point formats of a target object and a non-target object in the image to generate a target format pixel point and a non-target format pixel point;
generating a maximum connected domain formed by the target format pixel points according to the method of any one of claims 1-8;
and reserving a maximum connected domain formed by the pixel points in the target format, and setting other pixel points in the image as a preset filtering format.
10. The device for solving the maximum connected domain in the image comprises an initial scanning module, a line segment judging module, a line segment generating module, an adjacent judging module, a connected domain generating module, a binding relation module and an area calculating module, wherein:
the initial scanning module is used for scanning the image line according to a preset scanning direction to generate a current scanning line;
the line segment judging module is used for determining whether continuous target format pixel points exist on the current scanning line;
the line segment generation module is used for taking the continuous target format pixel points as a first line segment under the condition that the continuous target format pixel points exist in the current scanning line;
the adjacency judging module is used for judging whether the first line segment has an adjacency second line segment or not in the last scanning line under the condition that the current scanning line is not the first scanning line of the image;
the connected domain generation module is used for generating a new connected domain as a connected domain to which the first line segment belongs when the first line segment does not have the adjacent second line segment in the previous scanning line, adding the newly generated connected domain into a connected domain set, taking the next line of an image as the current scanning line, and re-determining whether continuous target format pixel points exist on the current scanning line;
the binding relation module is used for establishing a binding relation between a connected domain to which the first line segment belongs and a connected domain to which the one or more adjacent second line segments respectively belong under the condition that one or more adjacent second line segments exist in the previous scanning line of the first line segment, and re-determining whether continuous target format pixel points exist on the current scanning line or not by taking the next line of an image as the current scanning line;
the area calculation module is used for respectively calculating the total area of the connected domains with binding relation in the connected domain set under the condition that the current scanning line is the last scanning line of the image, and determining the connected domain with binding relation corresponding to the maximum total area as the maximum connected domain of the image.
11. An electronic device, comprising:
a processor;
a memory storing a computer program which, when executed by the processor, causes the processor to perform the method of any one of claims 1-9.
12. A non-transitory computer readable storage medium having stored thereon computer readable instructions which, when executed by a processor, cause the processor to perform the method of any of claims 1-9.
CN202310731096.8A 2023-06-20 2023-06-20 Method and device for solving maximum connected domain in image Active CN116489288B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310731096.8A CN116489288B (en) 2023-06-20 2023-06-20 Method and device for solving maximum connected domain in image

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310731096.8A CN116489288B (en) 2023-06-20 2023-06-20 Method and device for solving maximum connected domain in image

Publications (2)

Publication Number Publication Date
CN116489288A true CN116489288A (en) 2023-07-25
CN116489288B CN116489288B (en) 2023-09-05

Family

ID=87223594

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310731096.8A Active CN116489288B (en) 2023-06-20 2023-06-20 Method and device for solving maximum connected domain in image

Country Status (1)

Country Link
CN (1) CN116489288B (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101290656A (en) * 2008-05-23 2008-10-22 北京大学深圳研究生院 Connected region extraction method and apparatus for copy block analysis
US20090238458A1 (en) * 2008-03-24 2009-09-24 Oren Golan Method and system for line segment extraction
CN101957995A (en) * 2010-10-14 2011-01-26 华中科技大学 Method for detecting and extracting correlation pixels in image and application thereof
CN103065314A (en) * 2012-12-28 2013-04-24 中国电子科技集团公司第五十四研究所 Image communicated domain rapid marking method based on linear description
CN106686347A (en) * 2016-11-21 2017-05-17 国电南瑞科技股份有限公司 Video based method for judging translocation of metro camera

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090238458A1 (en) * 2008-03-24 2009-09-24 Oren Golan Method and system for line segment extraction
CN101290656A (en) * 2008-05-23 2008-10-22 北京大学深圳研究生院 Connected region extraction method and apparatus for copy block analysis
CN101957995A (en) * 2010-10-14 2011-01-26 华中科技大学 Method for detecting and extracting correlation pixels in image and application thereof
CN103065314A (en) * 2012-12-28 2013-04-24 中国电子科技集团公司第五十四研究所 Image communicated domain rapid marking method based on linear description
CN106686347A (en) * 2016-11-21 2017-05-17 国电南瑞科技股份有限公司 Video based method for judging translocation of metro camera

Also Published As

Publication number Publication date
CN116489288B (en) 2023-09-05

Similar Documents

Publication Publication Date Title
CN110177094A (en) A kind of user community recognition methods, device, electronic equipment and storage medium
CN112200117B (en) Form identification method and device
EP3779769B1 (en) Optical flow computing method and computing device
CN113034447A (en) Edge defect detection method and device
CN116489288B (en) Method and device for solving maximum connected domain in image
CN111209908B (en) Method, device, storage medium and computer equipment for updating annotation frame
CN111445487A (en) Image segmentation method and device, computer equipment and storage medium
CN103780863B (en) A kind of high-definition picture generation method and device
CN112036232B (en) Image table structure identification method, system, terminal and storage medium
CN106651944A (en) Algorithm and device for obtaining maximal horizontally inscribed rectangle for any connected domain based on run length encoding
TWI789158B (en) Image processing method, image processing system, and non-transitory computer readable storage medium
Seychell et al. An approach for objective quality assessment of image inpainting results
CN111126395B (en) Optimization method of selective search algorithm in R-CNN network and storage medium
CN111445411A (en) Image denoising method and device, computer equipment and storage medium
CN117649420A (en) Method and device for determining expansion domain of target area in image and electronic equipment
CN111126571B (en) R-CNN network optimization method based on DHT network and storage medium
JP2001101399A (en) Method for detecting image inclination, method for detecting margin, method for correcting image inclination and document image processor
CN116824611B (en) Table structure identification method, electronic device, and computer-readable storage medium
CN112669204B (en) Image processing method, training method and device of image processing model
JP7402931B2 (en) METHODS, COMPUTER READABLE PROGRAMS AND SYSTEM
JP4282467B2 (en) Image area separation method
JP2013126117A (en) Image processing device, image forming apparatus, image processing method, and image processing program
CN109886886B (en) Image restoration method and device
KR20230082230A (en) Method and apparatus for refining depth map and normal map
JPS5977577A (en) Frame extracting method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant