An image processing method, apparatus, device, medium and program product
By using the scanned point set in the image processing method to determine the starting point of the contour search, the problems of low efficiency and poor performance of traditional contour search are solved, and more accurate and efficient contour recognition is achieved.
Patent Information
- Application Number
- CN202311284066.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-28
- Publication Date
- 2025-06-24
- Estimated Expiration
- 2043-09-28
AI Technical Summary
Traditional contour search methods are inefficient and have poor performance, making it difficult to accurately identify contours in images.
By introducing a set of scanned points in the image processing method, it is determined whether the searched starting point belongs to the set of scanned points in the historical contour search. If it does not, a contour search is performed to identify the target contour.
Improves the accuracy and performance of contour searches, avoids repeated searches of the same contour, and ensures a complete search of each contour in the image.
Smart Images

Figure CN117314941B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, particularly to the field of chips, and specifically to an image processing method, an image processing device, a computer device, a computer-readable storage medium, and a computer program product. Background Art
[0002] Contour search refers to the technique of identifying the edge (or boundary) of an object in an image to achieve the identification of the object through the identified edge.
[0003] Currently, traditional techniques provide a serial contour search method; mainly when performing contour search on an image, starting from the starting point scanned from the image, serial contour search is performed to scan out the contour of the object from the image. However, this serial contour search method has problems such as low contour search efficiency and poor search performance of contour search. Summary of the Invention
[0004] Embodiments of the present application provide an image processing method, device, equipment, medium, and program product, which can improve the accuracy of the contour obtained by contour search and improve the search performance of contour search.
[0005] On the one hand, embodiments of the present application provide an image processing method, which includes:
[0006] During the process of performing contour search on the image to be processed, a starting point in the image is searched for;
[0007] An already scanned point set is obtained, and the already scanned point set is used to store pixel points that are searched for and meet the starting conditions of contour search during the historical contour search process;
[0008] If the searched starting point does not belong to the already scanned point set, then based on the starting point, contour search is performed in the image to obtain boundary points in the image;
[0009] Based on the starting point and the boundary points, the target contour connected by the starting point and the boundary points is marked in the image.
[0010] On the other hand, embodiments of the present application provide an image processing device, which includes: a contour search rule unit, a contour boundary conversion unit, and a scan state query unit; wherein,
[0011] The contour search rule unit is used to search for a starting point in the image during the process of performing contour search on the image to be processed;
[0012] A scanning status query unit, configured to output a set of scanned points to a contour search rule unit, where the set of scanned points is used to store pixel points that are searched during a historical contour search and meet the starting conditions of the contour search;
[0013] The contour search rule unit is further configured to obtain the set of scanned points from the scanning status query unit;
[0014] The contour search rule unit is further configured to, if the starting point found does not belong to the set of scanned points, perform a contour search in the image based on the starting point to obtain boundary points in the image;
[0015] The contour search rule unit is further configured to identify a target contour formed by connecting the starting point and the boundary points in the image based on the starting point and the boundary points.
[0016] In one implementation, the contour search for the target contour is a reverse contour search, where the reverse contour search means performing a contour search in the counterclockwise direction with the starting point as a reference; the reverse contour search includes one or more rounds of loop searches; the starting point of the target contour is represented as (i, j); when the contour search rule unit performs a contour search in the image based on the starting point to obtain boundary points in the image, it is specifically configured to:
[0017] Determine a starting boundary point (i2, j2) of the reverse contour search according to the search rules of the reverse contour search and based on the starting point (i, j), and add the starting point (i, j) to the set of scanned points;
[0018] Starting from the starting boundary point (i2, j2), search clockwise for a search base point (i1, j1) in the neighborhood of the starting point (i, j), and use the search base point (i1, j1) as the starting boundary point (i2, j2) of the first round of loop search, and use the starting point (i, j) as the neighborhood search center point (i3, j3) of the first round of loop search;
[0019] Perform a first round of loop search on the image based on the starting boundary point (i2, j2) and the neighborhood search center point (i3, j3) of the first round of loop search to obtain a first round of search result (i4, j4);
[0020] Determine whether the first round of search result (i4, j4) meets the loop end condition;
[0021] If it meets the condition, end the current reverse contour search; the only pixel point included in the target contour is the starting point (i, j) of the first round of loop search.
[0022] In one implementation, the contour search rule unit is further configured to:
[0023] If not, the neighborhood search center point (i3, j3) obtained in the first round of loop search is used as the starting boundary point (i2, j2) for the second round of loop search, and the first-round search result (i4, j4) of the first round of loop search is used as the neighborhood search center point (i3, j3) for the second round of loop search;
[0024] Based on the starting boundary point (i2, j2) and the neighborhood search center point (i3, j3) of the second round of loop search, perform a second round of loop search on the image to obtain a second-round search result (i4, j4);
[0025] Determine whether the second-round search result (i4, j4) meets the loop end condition;
[0026] Repeat the above steps until the k-th round search result (i4, j4) of the k-th round of loop search meets the loop end condition, where k is an integer greater than or equal to 2; The pixel points constituting the target contour include: the starting point (i, j) of the first round of loop search and the search results (i4, j4) of other loop searches except the first round of loop search in the k rounds of loop search.
[0027] In one implementation, when the contour search rule unit is used to perform a second round of loop search on the image based on the starting boundary point (i2, j2) and the neighborhood search center point (i3, j3) of the second round of loop search to obtain a second-round search result (i4, j4), it is specifically used for:
[0028] Starting from the starting boundary point (i2, j2) of the second round of loop search, find the first non-zero point in the neighborhood of the neighborhood search center point (i3, j3) of the second round of loop search counterclockwise;
[0029] Take the first non-zero point as the second-round search result (i4, j4) of the second round of loop search.
[0030] In one implementation, that the search result (i4, j4) obtained in any round of loop search meets the loop end condition includes:
[0031] The search result (i4, j4) obtained in any round of loop search is located in the set of scanned points; or,
[0032] The search result (i4, j4) obtained in any round of loop search is the same as the starting point (i, j) of the first round of loop search, and the neighborhood search center point (i3, j3) of any round of loop search is the same as the search base point (i1, j1).
[0033] In one implementation, the image processing device further includes a contour boundary conversion unit corresponding to the contour search rule unit; wherein,
[0034] A contour boundary conversion unit, configured to, during multiple rounds of cyclic searches for contour search, if the search result (i4, j4) obtained in any round of cyclic search is a boundary point that meets the starting condition of contour search, send the search result (i4, j4) obtained in any round of cyclic search to the scan status query unit;
[0035] A scan status query unit, configured to update the scanned point set based on the search result (i4, j4) obtained in any round of cyclic search, where the updated scanned point set includes the search result (i4, j4) obtained in any round of cyclic search;
[0036] Wherein, when i4 in the search result (i4, j4) obtained in the same round of cyclic search is greater than i3 in the neighborhood search center point (i3, j3) of the same round of cyclic search, it is determined that the search result (i4, j4) obtained in the same round of cyclic search is a boundary point that meets the starting condition of contour search; or,
[0037] When i4 in the search result (i4, j4) obtained in the same round of cyclic search is equal to i3 in the neighborhood search center point (i3, j3) of the same round of cyclic search, and j4 in the search result (i4, j4) obtained in the same round of cyclic search is greater than j3 in the neighborhood search center point (i3, j3) of the same round of cyclic search, it is determined that the search result (i4, j4) of the same round of cyclic search is a boundary point that meets the starting condition of contour search.
[0038] In one implementation, the contour search rule unit is further configured to obtain each pixel point of the historical contour search from the scan status query unit;
[0039] The contour search rule unit is further configured to, after the contour search for the target contour ends, determine whether there is a contour to be searched in the image based on each pixel point of the historical contour search;
[0040] The contour search rule unit is further configured to, if there is, continue to perform contour search using the search rule until all contours in the image are searched; and mark the searched contours in the image; the searched contours at least include the target contour;
[0041] The contour search rule unit is further configured to, if not, trigger the execution of the step of marking the target contour formed by connecting the starting point and the boundary point in the image based on the starting point and the boundary point.
[0042] In one implementation, when the contour search rule unit is configured to determine whether there is a contour to be searched in the image, it specifically is configured to:
[0043] Based on the coordinates of each scanned point in the scanned point set that is in the scanned state, rescan the starting point of the contour of the image;
[0044] If it is scanned that the coordinates of the starting point in the image do not belong to the scanned point set, it is determined that there is a contour to be searched in the image.
[0045] In one implementation, the image also includes a reference contour, and the reference contour is different from the target contour;
[0046] Among them, the execution order of the contour search for the target contour and the reference contour in the image is synchronous.
[0047] In one implementation, the image is a binary image, any pixel point in the binary image is represented as (i, j), and the pixel value of the pixel point (i, j) is represented as f(i, j) , ; the search types of the contour search include: forward contour search and reverse contour search; the forward contour search means performing a contour search in the clockwise direction with the starting point as the reference; the reverse contour search means performing a contour search in the counterclockwise direction with the starting point as the reference;
[0048] The judgment conditions for the starting point of the forward contour search include:
[0049] Scan the binary image in the scanning order from bottom to top and from right to left;
[0050] If it is scanned that f(i, j) = 1 and f(i, j + 1) = 0, then the pixel point (i, j) is used as the starting point of the target contour;
[0051] The judgment conditions for the starting point of the reverse contour search include:
[0052] Scan the binary image in the scanning order from left to right and from top to bottom;
[0053] If it is scanned that f(i, j) = 1 and f(i, j - 1) = 0, then the pixel point (i, j) is used as the starting point of the target contour.
[0054] In one implementation, the contour search rule unit includes: a forward contour search rule subunit and / or a reverse contour search rule subunit; each contour search rule subunit corresponds to a contour boundary conversion sub-device;
[0055] The forward contour search rule subunit deploys the search rules for the forward contour search; the forward contour search rule subunit is used to perform a forward contour search on the image; the forward contour search means performing a contour search in the clockwise direction with the starting point as the reference;
[0056] The reverse contour search rule subunit deploys the search rules for reverse contour search; the reverse contour search rule subunit is used to perform reverse contour search on an image; reverse contour search refers to performing contour search in the clockwise direction with the starting point as the reference; forward contour search refers to performing contour search in the counterclockwise direction with the starting point as the reference.
[0057] In one implementation, the number of contour search rule units is the same as that of contour boundary conversion units, and the number of contour search rule units and contour boundary conversion units can be one or more;
[0058] When the number of reverse contour search rule subunits included in the reverse contour search rule unit is multiple, multiple reverse contour search rule subunits and contour boundary conversion subunits are used to perform multiple contour searches on the image;
[0059] Among them, the search types of the contour searches performed by the multiple reverse contour search rule subunits are the same or different.
[0060] On the other hand, an embodiment of the present application provides a computer device. A chip is provided in the computer device, and an image processing device is provided in the chip. The image processing device is used to implement the above-mentioned image processing method.
[0061] On the other hand, an embodiment of the present application provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and the computer program is adapted to be loaded and executed by a processor to perform the above-mentioned image processing method.
[0062] On the other hand, an embodiment of the present application provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the above-mentioned image processing method is implemented.
[0063] In the embodiments of the present application, during the process of contour search for the image to be processed, when the starting point in the image to be processed is searched, a status query is first performed on the starting point. Specifically, it is determined whether the starting point falls into the set of scanned points, and the set of scanned points is used to store the pixel points that are searched during the historical contour search process and meet the starting conditions of the contour search; that is to say, after the starting point is searched, it is first detected whether the starting point has been scanned during the historical contour search. If not, it indicates that the contour with the starting point as the boundary point has not been searched yet, and then the contour search can continue in the image to be processed based on the starting point to obtain the target contour formed by the starting point and other boundary points. On the contrary, if so, it indicates that the contour with the starting point as the boundary point has been searched in the historical time, and the current contour search with the starting point as the boundary point is cancelled. It can be seen from the above solution that the embodiments of the present application provide a new contour search method, which supports caching the pixel points that are scanned (or searched) during each contour search and meet the starting conditions of the contour search; in this way, during any contour search process, only when the searched starting point is not the stored pixel point, the contour search continues; compared with directly performing the contour search after scanning the starting point, it can avoid repeated searches for the same contour in the image to be processed, and can also ensure that each contour in the image to be processed is searched, ensuring the integrity (that is, all contours are searched) and consistency (that is, the searched contour is the actual contour in the image to be processed) of the contour search in the image to be processed. In addition, considering that each contour search will cache the scanned pixel points that meet the starting conditions, this makes the embodiments of the present application not have repeated search situations when performing multiple contour searches on the image to be processed at the same time. On the basis of ensuring the accuracy of the contour search, it effectively improves the rapidity of the contour search and improves the contour search efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0065] Figure 1 It is a schematic diagram of the contour of an object provided by an exemplary embodiment of the present application;
[0066] Figure 2 It is a schematic diagram of an image processing scenario provided by an exemplary embodiment of the present application;
[0067] Figure 3 It is a schematic flowchart of an image processing method provided by an exemplary embodiment of the present application;
[0068] Figure 4 is a schematic diagram of searching for a starting point provided by an exemplary embodiment of the present application;
[0069] Figure 5a is a schematic diagram of the structure of a 4-neighborhood provided by an exemplary embodiment of the present application;
[0070] Figure 5b is a schematic diagram of the structure of an 8-neighborhood provided by an exemplary embodiment of the present application;
[0071] Figure 5c is a schematic diagram of the structure of a D-neighborhood provided by an exemplary embodiment of the present application;
[0072] Figure 6 is a schematic diagram of determining a search base point provided by an exemplary embodiment of the present application;
[0073] Figure 7 is a schematic diagram of the process of contour search provided by an exemplary embodiment of the present application;
[0074] Figure 8 is a schematic diagram of the structure of an image processing device provided by an exemplary embodiment of the present application;
[0075] Figure 9 is a schematic diagram of the structure of another image processing device provided by an exemplary embodiment of the present application;
[0076] Figure 10 is a schematic diagram of the structure of yet another image processing device provided by an exemplary embodiment of the present application;
[0077] Figure 11 is a schematic diagram of the structure of a chip provided by an exemplary embodiment of the present application. Detailed implementation manners
[0078] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present application without creative efforts shall fall within the protection scope of the present application.
[0079] The embodiments of the present application relate to the field of Artificial Intelligence (AI). Artificial Intelligence is to use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, and is a theory, method, technology, and application system that can perceive the environment, acquire knowledge, and use knowledge to obtain the best results. Artificial Intelligence technology is a comprehensive discipline, involving a wide range of fields, including both hardware-level technologies and software-level technologies. The basic technologies of Artificial Intelligence generally include technologies such as sensors, dedicated Artificial Intelligence chips, cloud computing, distributed storage, big data processing technologies, operation / interaction systems, and mechatronics. The software technologies of Artificial Intelligence mainly include several major directions such as computer vision technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0080] The image processing solution provided by the embodiments of the present application mainly relates to computer vision technology (CV) in the field of Artificial Intelligence. Computer vision is a science that studies how to make machines "see". Further, it refers to using cameras and computers to replace human eyes to perform machine vision such as object recognition, detection, and measurement on targets, and further perform graphic processing to make the computer process into images that are more suitable for human eyes to observe or be transmitted to instruments for detection. As a scientific discipline, computer vision studies related theories and technologies and attempts to establish an Artificial Intelligence system that can obtain information from images or multi-dimensional data. Computer vision technology usually includes technologies such as image processing, image recognition, image semantic understanding, image retrieval, OCR (Optical Character Recognition), video processing, video semantic understanding, video content / behavior recognition, three-dimensional object reconstruction, 3D technology, virtual reality, augmented reality, simultaneous localization and mapping, and also includes common biometric recognition technologies such as face recognition and fingerprint recognition.
[0081] Furthermore, the embodiments of the present application mainly relate to technologies such as image processing, image recognition, and OCR under computer vision technology, specifically relating to the contour search technology for objects in images; this contour search technology is a commonly used technology in computer vision technology, which is mainly used to identify the contours (or referred to as boundaries, edges) of objects in images in order to achieve the recognition and processing of objects (such as detection and positioning, etc.). The basic principle of the contour search technology is based on features such as color, shape, and texture in the image, and by analyzing the edges or boundaries of the object, the contour of the object is obtained; the key step in this process is to search for the pixel points of the object's edge from the image, so as to form the contour curve of the object based on the edge pixel points. A schematic diagram of the contour of an object in an exemplary image can be seen in Figure 1 ; in Figure 1It is drawn by taking an example in which the object "puppy" is included and the searched contour is the overall shape contour of the puppy; it should be understood that in addition to the overall shape having a contour, the components or a certain part included in the object also have a contour. For example, Figure 1 the ear part of the shown puppy can also present the contour of the ear, etc. In the embodiments of the present application, it is not limited whether the contour in the image is the contour of the overall shape of the object or the contour of the shape of a partial part, and this is specifically stated here.
[0082] Based on the foregoing relevant introductions to technologies such as computer vision and contour search, the embodiments of the present application provide an image processing solution. During the contour search process of this image processing solution, it supports setting the pixel points that are scanned (or searched) and meet the starting conditions of the contour search to the scanned state for caching; in this way, if a certain pixel point is scanned to be in the scanned state during the subsequent contour search, then it is determined that the pixel point has been scanned, and the current contour search is stopped. Thereby, multiple contour searches for the same pixel point are avoided, the contour search error caused by repeated contour searches is avoided, the accuracy of the contour search is improved, and each pixel point that meets the starting conditions in the image is scanned, which can ensure the integrity and consistency of the contour search in the image.
[0083] Taking the search process of single - contour search as an example, the general idea of the image - processing solution involved in the embodiments of this application is introduced. In specific implementation: First, during the process of contour search for the image to be processed, a starting point in the image to be processed will be searched, and then this starting point can be compared with the set of scanned points; the set of scanned points is used to store the pixel points that are searched during the historical contour search process and meet the starting conditions of the contour search. Then, if the starting point obtained from this contour search belongs to the set of scanned points, that is, the scanning state of the starting point obtained from this contour search is the scanned state, it indicates that this starting point has been searched as a starting point or a boundary point in the historical contour search. Then, continuing the search based on this starting point will result in duplicate search for the same contour; on the contrary, if the starting point obtained from this contour search does not belong to the set of scanned points, that is, the scanning state of the starting point obtained from this contour search is the unscanned state, it indicates that it has not been searched as a boundary point or a starting point in the historical contour search. At this time, the contour search in the image to be processed is continued based on this starting point to obtain the boundary points in the image to be processed. Finally, based on the starting point and the searched points obtained from this contour search, the target contour connected by the starting point and the boundary points is marked in the image to be processed. It can be seen that compared with directly performing contour search after scanning the starting point, the embodiments of this application can avoid duplicate search for the same contour in the image to be processed, and can also ensure that each contour in the image to be processed is searched, ensuring the integrity (that is, all contours are searched) and consistency (that is, the searched contour is the actual contour in the image to be processed) of the contour search in the image to be processed.
[0084] The image - processing solution provided by the embodiments of this application can be deployed in the image - processing device in the form of software, and the image - processing device calls the software to implement contour search for the image. Among them, the image - processing device can run on (or be set in) a computer device, specifically, it can be a chip, a hardware system, or a central - processing - system firmware (such as a Central Processing Unit (CPU) or a graphics processing unit (GPU)) running in the computer device, etc. Among them, the computer device is a terminal or a server with image - processing capabilities. Taking the computer device with image - processing capabilities as a server as an example, the schematic diagram of the architecture of an exemplary image - processing scenario can be seen Figure 2 ; as Figure 2 shown, the schematic diagram of the architecture includes a terminal 201 and a server 202. The embodiments of this application do not limit the type and quantity of the terminal 201 and the server 202; among them:
[0085] The terminal 201 can be a terminal device used by users with image processing requirements. The terminal device can include but is not limited to: smart phones (such as smart phones deployed with the Android system or smart phones deployed with the Internetworking Operating System (IOS)), tablet computers, portable personal computers, Mobile Internet Devices (MID), in-vehicle devices, head-mounted devices, and smart homes, etc. The embodiments of the present application do not limit the type of the terminal device, which is hereby explained. The server 202 can be the server corresponding to the terminal, and is used to perform data interaction with the terminal to provide computing and application service support for the terminal. The server 203 can be deployed with the image processing device provided by the embodiments of the present application, and the image processing device deployed in the server 203 provides the image processing solution proposed by the embodiments of the present application. Among them, the server (such as the server 102 or the server 203) can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, Content Delivery Network (CDN), and big data and artificial intelligence platforms.
[0086] In a specific implementation, first, when the user has an image processing requirement, the image to be processed can be sent to the server 202 through the terminal 201. Then, after receiving the image to be processed, the server 202 performs a contour search on the image (specifically, the binary image of the image), and obtains the searched image (if the image includes contours, the searched image is marked with the identified contours; if the image does not include contours (such as a blank image), the searched image is not marked with contours). Finally, the server 202 returns the image marked with contours to the terminal 201 side for display. Among them, during the process of the server 202 performing a contour search on the image, the starting point in the image is searched; then, the server 202 obtains the set of scanned points, which is used to store the pixel points that are searched and meet the starting conditions of the contour search during the historical contour search process, and the scanning status of these pixel points is set to the scanned status. In this way, the server 202 can detect whether the searched starting point belongs to the set of scanned points; if the searched starting point does not belong to the set of scanned points, it indicates that the starting point searched in this contour search has not been scanned during the historical contour search process, that is, the starting point searched in this contour search has not been used as the starting point or boundary point of the historical contour search, then the contour search can be performed in the image based on this starting point to obtain the boundary points in the image; furthermore, based on the searched starting point and all boundary points, the template contour formed by the starting point and the boundary points can be identified from the image. On the contrary, if the searched starting point belongs to the set of scanned points, it indicates that the starting point searched in this contour search has been scanned during the historical contour search process, that is, the contour with the starting point searched in this contour search as the starting point or boundary point has been searched in the historical time, then this contour search is stopped.
[0087] It should be noted that: ① During the process of the server 201 performing a contour search on the image, in addition to judging whether the scanning status of the starting point is the scanned status, the boundary points searched in each round of loop search will also be used as the loop end condition (that is, judging whether to return to the starting point of this contour search) to stop this contour search when it is judged that the starting point of this contour search is returned, and further judge whether to start the next contour search.
[0088] ② The above introduces the contour search process by taking a single contour search as an example; in practical applications, considering that the set of scanned points will be updated in each contour search process in the embodiments of the present application, the embodiments of the present application support performing multiple contour searches on the image simultaneously without repeated searches. For example, performing two contour searches or three contour searches in the image at the same time.
[0089] ③ Figure 2The schematic architecture diagram and process shown do not limit the image processing scenarios applicable to the embodiments of this application; in specific image processing scenarios, Figure 2 the schematic architecture diagram and process shown may undergo adaptive changes. The image processing solution provided by the embodiments of this application can be applied to any application scenario that requires contour search for images; including but not limited to: character segmentation and extraction in OCR recognition (such as license plate recognition, text recognition, or subtitle recognition, etc.) scenarios, moving foreground object segmentation and extraction in visual detection (such as pedestrian intrusion detection, left-behind object detection, or vision-based vehicle detection, etc.) scenarios, medical image processing (such as extraction of regions of interest in CT images) scenarios, vehicle recognition scenarios in the transportation field, actor positioning scenarios in film and television works, and so on.
[0090] ④ In the embodiments of this application, the collection and processing of relevant data should strictly comply with the requirements of relevant national laws and regulations. To obtain personal information, the informed consent of the individual subject (or having a legal basis for information acquisition) is required, and subsequent data use and processing behaviors should be carried out within the scope authorized by laws, regulations, and the individual information subject. For example, when the embodiments of this application are applied to specific products or technologies, such as when obtaining an image to be processed, the permission or consent of the owner of the image needs to be obtained, and the collection, use, and processing of relevant data (such as the collection and release of bullet screens posted by the object, etc.) need to comply with the relevant laws, regulations, and standards of relevant countries and regions.
[0091] Figure 3 The flowchart shows a process of an image processing method provided by an exemplary embodiment of this application; this image processing method can be executed by the aforementioned computer device. If the computer device is a server, specifically, it can be executed by the hardware (such as a chip) in the server; this image processing method may include but is not limited to steps S301 - S304:
[0092] S301: During the process of performing contour search on the image to be processed, find the starting point in the image.
[0093] As described above, contour search mainly finds the boundary points of objects in the image in sequence, so as to connect the boundary points into the contour of the object; and the first step in finding the boundary points in sequence is to find the first starting point, so that the contour of the object can be found by performing sequential search in the image based on this first starting point. That is to say, the starting point can refer to the first boundary point of the contour found during the contour search process.
[0094] The search types for contour search provided by the embodiments of this application may include: forward contour search and reverse contour search; the forward contour search refers to continuing the contour search in the clockwise direction with the starting point as the reference; the reverse contour search refers to performing the contour search in the counterclockwise direction with the starting point as the reference. When this two-way search technology (i.e., forward contour search and reverse contour search) acts on an image simultaneously, it can achieve two-way search for the image, which can effectively improve the speed and efficiency of contour search compared to performing serial contour search on the image in a certain direction.
[0095] Furthermore, the judgment conditions for the starting points of the forward contour search and the reverse contour search are not the same; taking the image to be processed as a binary image (the pixel values of each pixel point in this binary image are 0 or 1), any pixel point in the binary image (specifically the coordinates of this any pixel point) is represented as (i, j), and the pixel value of the pixel point (i, j) is represented as f(i, j) as an example, then: ① The judgment conditions for the starting point of the forward contour search include: using the raster scan method, scanning the binary image in the scanning order from bottom to top and from right to left; if it is scanned that f(i, j) = 1 and f(i, j + 1) = 0, then the pixel point (i, j) is used as the starting point of the target contour (i.e., the contour to be searched in the image). ② The judgment conditions for the starting point of the reverse contour search include: using the raster scan method, scanning the binary image in the scanning order from left to right and from top to bottom; if it is scanned that f(i, j) = 1 and f(i, j - 1) = 0, then the pixel point (i, j) is used as the starting point of the target contour. Among them, the above-mentioned raster scan is an image scanning method, and its main scanning principle is: scanning row by row in the order from top to bottom or from bottom to top.
[0096] For easy understanding, the following combines the attached Figure 4 An exemplary introduction to the judgment process of the starting points of the forward contour search and the reverse contour search is given. As Figure 4As shown in the figure, it is assumed that a square in a binary image represents a pixel point in the image, the value inside the square is the pixel value of the corresponding pixel point, and the pixel value 0 is omitted. Then, when performing a reverse contour search on the binary image, the process of determining the starting point of the reverse contour search includes: scanning the 0th row of the binary image in the scanning order from left to right and from top to bottom. If the pixel value of each pixel point in the 0th row obtained is 0, it is determined that there is no starting point for the reverse contour search in this 0th row; further, scanning the 1st row in the binary image in the scanning order from left to right and from top to bottom. The pixel values of the pixel points (1, 0) and (1, 1) obtained are both 0, which are not the starting points, but the pixel value of the scanned pixel point (1, 2) is 1, so it is ensured that this pixel point (1, 2) is used as the starting point for the reverse contour search. Similarly, when performing a forward contour search on the binary image, the process of determining the starting point of the forward contour search includes: scanning the 5th row of the binary image in the scanning order from right to left and from bottom to top. If the pixel value of each pixel point in the 5th row obtained is 0, it is determined that there is no starting point for the forward contour search in this 5th row; further, scanning the 4th row in the binary image in the scanning order from right to left and from bottom to top. The pixel values of the pixel points (4, 11) and (4, 10) obtained are both 0, which are not the starting points, but the pixel value of the scanned pixel point (4, 9) is 1, so it is ensured that this pixel point (4, 9) is used as the starting point for the forward contour search.
[0097] For the convenience of description, in the following embodiments of the present application, the contour search is taken as an example of the reverse contour search to introduce the contour search process for the image, and it is specifically stated here.
[0098] S302: Obtain the set of scanned points.
[0099] S303: If the starting point of the search does not belong to the set of scanned points, perform a contour search in the image based on the starting point to obtain the boundary points in the image.
[0100] In steps S302 - S303, the scanned point set is used to store the pixel points that are searched during the historical contour search and meet the starting conditions of the contour search. That is, the pixel points stored in the scanned point set are all the points that have been searched during the historical contour search and meet the starting conditions; the scanning status of these pixel points is the scanned status. For example, during a certain historical contour search before the current contour search, the pixel point (i, j) is searched as a boundary point, and the pixel point (i, j) meets the starting conditions of the contour search (such as meeting the starting conditions of the reverse contour search f(i, j)1 and f(i, j + 1) = 0), then it is determined that the scanning status of the pixel point (i, j) is the scanned status, and the pixel point (i, j) is added to the scanned point set. From the above example, it can be seen that the pixel points stored in the scanned point set may be the starting points searched during the historical contour search, or may be the boundary points searched during the historical contour search and the boundary point meets the starting conditions of the contour search. Among them, the historical contour search is relative to the current contour search; the start time of the historical contour search is earlier than the start time of the current contour search; or, the start time of the historical contour search is the same as the start time of the current contour search (or the start time of the historical contour search is later than the start time of the current contour search), but the search time of the historical contour search for a certain pixel point is earlier than the search time of the current contour search for the same pixel point.
[0101] In specific implementation, after the starting point in the image is searched in the current contour search, it is determined whether the starting point belongs to the scanned point set, that is, it is determined whether the scanning status of the starting point is the scanned status. If the starting point belongs to the scanned point set, that is, the scanning status of the starting point is the scanned status, it indicates that the starting point has been scanned as a starting point or a boundary point in the historical contour search, then the current contour search is stopped, and the next starting point is scanned for the next contour search. On the contrary, if the starting point does not belong to the scanned point set, that is, the scanning status of the starting point is the unscanned status, it indicates that the starting point has not been used as a starting point or a boundary point in the historical contour search, then the current contour search is continued based on the starting point to obtain the boundary points of the current contour search.
[0102] To facilitate the understanding of the specific process of the contour search, the following first gives the coordinate meanings involved in the contour search through Table 1:
[0103] Table 1
[0104] Coordinates (i, j) Starting point Coordinates (i1, j1) Starting search base point Coordinates (i2, j2) Starting boundary point for contour search Coordinates (i3, j3) Central point for each neighborhood search Coordinates (i4, j4) Result of each neighborhood search Coordinates (i5, j5) Scanned point Coordinates (i2_jext, j2_jext) Starting point for each neighborhood search
[0105] Combined with Table 1 and taking the search type of this contour search as the reverse contour search as an example, the specific implementation process of obtaining the boundary points of the target contour based on the starting point of this contour search may include but is not limited to:
[0106] (1) The establishment stage or initialization stage of the contour search.
[0107] Based on the judgment condition of the starting point of the reverse contour search mentioned above, the starting point of the target contour is identified from the image and represented as (i, j), where i is the column and j is the row. Then, the starting point (i, j) can be added to the set of scanned points, that is, the scanning state of this starting point is set to the scanned state. In this way, when other contours search to this starting point later, the same contour search will not be performed based on this starting point, avoiding duplicate search of the contour. In the embodiments of the present application, the pixel points that need to be added to the set of scanned points are supported to be represented as (i5, j5). That is, the process of adding the starting point (i, j) to the set of scanned points can be considered as an update of this set of scanned points. Specifically, it is to make the scanned point (i5, j5) = (i, j). Then, according to the search rule of the reverse contour search and based on this starting point (i, j), the starting boundary point (i2, j2) of the reverse contour search is determined. Specifically, the pixel point (i, j - 1) in the image is used as the starting boundary point (i2, j2), that is, the adjacent left pixel point in the same row as the starting point is used as the starting boundary point. Finally, based on the starting point (i, j) and the starting boundary point (i2, j2), the search base point (i1, j1) is searched from the image. This search base point (i1, j1) is the reference point for subsequent cyclic search to find the boundary point. Among them, the specific process of determining the search base point includes: starting from the starting boundary point (i2, j2), searching clockwise for the search base point (i1, j1) in the neighborhood of the starting point (i, j). Specifically, taking the starting point (i, j) as the center, starting from the starting boundary point (i2, j2) and rotating clockwise, the first non-zero point in the neighborhood of the starting point (i, j) is found, and this first non-zero point is used as the search base point (i1, j1).
[0108] Among them, the neighborhood mentioned above is a basic structure of the topological space, specifically a special interval centered on a certain pixel point. The neighborhood of a pixel point can be used to reflect the adjacency property between the pixel point and the surrounding pixel points. According to different adjacency properties, it is usually divided into 4-neighborhood, 8-neighborhood, D-neighborhood, etc. A schematic diagram of the structure of a 4-neighborhood can be seen Figure 5a , taking the pixel point P as the center position, and taking the four pixel points above (such as label 1), below (such as label 3), left (such as label 2), and right (such as label 0) that have an adjacency relationship with this center position as the 4-neighborhood of the pixel point P. A schematic diagram of the structure of an 8-neighborhood can be seen Figure 5b, taking the pixel point P as the central position, and taking the eight pixel points above (such as label 2), below (such as label 6), left (such as label 4), right (such as label 0), upper left (such as label 3), upper right (such as label 1), lower left (such as label 5), and lower right (such as label 7) that have an adjacency relationship with this central position as the 8-neighborhood of the pixel point P. A schematic structural diagram of a D-neighborhood can be seen in Figure 5c , taking the pixel point P as the central position, and taking the four diagonal pixel points of upper left (such as label 3), upper right (such as label 1), lower left (such as label 5), and lower right (such as label 7) that have an adjacency relationship with the pixel point P as the D-neighborhood of the pixel point P. It should be noted that the image processing method provided by the embodiments of the present application has relatively wide generality and can be applied to contour searches in any neighborhood including but not limited to 4-neighborhood, 8-neighborhood, and D-neighborhood, etc.; the embodiments of the present application do not limit the specific neighborhood involved.
[0109] For example, the exemplary process of determining the search base point (i1, j1) above can be seen in Figure 6 ; as Figure 6 shown, according to the judgment condition of the starting point of the reverse contour search, the starting point (1, 2) is searched from the binary image and the scanning state of the starting point (1, 2) is the unscanned state. Then, take the left adjacent pixel point (1, 1) in the same row as this starting point as the starting boundary point (i2, j2), that is, the starting boundary point (i2, j2) = (1, 1). Then, with the starting point (1, 2) as the center, starting from the starting boundary point (i2, j2), find the first non-zero point (1, 3) in the neighborhood of the starting point (1, 2) in the clockwise direction. Then, take this first non-zero point (1, 3) as the search base point (i1, j1), that is, the search base point (i1, j1) = (1, 3).
[0110] (2) The loop search stage of contour search.
[0111] After identifying the search base point (i1, j1) from the image based on the above step (1), a reverse contour search can be performed based on this search base point (i1, j1) and the starting point (i, j) to obtain the boundary points of the target contour; this reverse contour search can include one or more rounds of loop searches until the search result meets the loop end condition and stops this contour search.
[0112] Specifically, the search base point (i1, j1) in the initialization stage is used as the starting boundary point (i2, j2) for the first round of loop search, and the starting point (i, j) is used as the neighborhood search center point (i3, j3) for the first round of loop search. Then, based on the starting boundary point (i2, j2) and the neighborhood search center point (i3, j3) of the first round of loop search, the image is subjected to the first round of loop search to obtain the first round of search result (i4, j4). Secondly, it is judged whether the first round of search result (i4, j4) meets the loop end condition. If it meets, the current reverse contour search is ended, and at this time, the only pixel point included in the target contour is the starting point (i, j) of the first round of loop search. On the contrary, if it does not meet, it indicates that the first round of search result (i4, j4) can be used as a boundary point constituting the target contour, and the loop search continues based on the first round of search result (i4, j4); specifically, the neighborhood search center point (i3, j3) of the first round of loop search is used as the starting boundary point (i2, j2) for the second round of loop search, and the first round of search result (i4, j4) of the first round of loop search is used as the neighborhood search center point (i3, j3) for the second round of loop search. Then, based on the starting boundary point (i2, j2) and the neighborhood search center point (i3, j3) of the second round of loop search, the image is subjected to the second round of loop search to obtain the second round of search result (i4, j4). Secondly, it continues to be judged whether the second round of search result (i4, j4) meets the loop end condition; the above steps are repeated until the k-th round of search result (i4, j4) of the k-th round of loop search meets the loop end condition, where k is an integer greater than 2; at this time, the pixel points constituting the target contour include: the starting point (i, j) of the first round of loop search and the search results (i4, j4) of other loop searches except the first round of loop search in the k rounds of loop search.
[0113] It should be noted that in the above process:
[0114] ① The specific process of any loop search in the multi-loop search is the same. Taking the second-loop search as an example, the process of the loop search will be introduced. The process of the loop search may include: starting from the starting boundary point (i2, j2) of the second-loop search, searching counterclockwise for the first non-zero point within the neighborhood of the neighborhood search center point (i3, j3) of the second-loop search; specifically, taking the neighborhood search center point (i3, j3) of the second-loop search as the center point of the 8-neighborhood, taking the next pixel point in the counterclockwise direction of the starting boundary point (i2, j2) of the second-loop search as the starting point, denoted as the coordinate (i2_jext, j2_jext), and starting from the pixel point (i2_jext, j2_jext) to search counterclockwise for the 8-neighborhood of the neighborhood search center point (i3, j3) of the second-loop search until the first non-zero value is found. Then, take this first non-zero point as the second-round search result (i4, j4) of the second-loop search.
[0115] ② The search result (i4, j4) obtained from any loop search meets the loop end condition, including: the neighborhood search center point (i3, j3) of any loop search is the same as the search base point (i1, j1); that is to say, this any loop search returns to the starting point of this contour search, that is, the starting point and boundary point found in this contour search have formed a closed contour.
[0116] ③ During the process of the multi-loop search of this contour search, the scanned point set will also be updated in real time according to the search result of each loop search, so that any contour search can make a loop end judgment based on the real-time updated scanned point set, that is, to judge whether the starting point or boundary point found in this any contour search is a scanned point; in the embodiment of the present application, when the search result of the loop search meets the starting condition, set this search result to the scanned state, that is, add it to the scanned point set. The process of avoiding redundant search for subsequent contour search is called boundary conversion. By introducing boundary conversion in the contour search technology, multiple synchronous or asynchronous unidirectional (such as forward contour search or reverse contour search) or bidirectional (such as forward contour search and reverse contour search) of the image can be accurately executed, ensuring the accuracy of the search result and the search performance.
[0117] In a specific implementation, during multiple rounds of loop for contour search, if the search result (i4, j4) obtained in any round of loop search is a boundary point that meets the starting condition of contour search, the set of scanned points is updated based on the search result (i4, j4) obtained in that round of loop search. The updated set of scanned points includes the search result (i4, j4) obtained in that round of loop search. As described above, the search types of the contour search provided in the embodiments of the present application may include forward contour search and reverse contour search, and the judgment conditions for the starting points of the two search types are different; therefore, if the search result (i4, j4) obtained in any round of loop search meets the judgment condition for the starting point of any search type, the search result (i4, j4) will be added to the set of scanned points, so that whether the subsequent contour search type is forward contour search or reverse contour search, duplicate contour search will not be performed based on the search result (i4, j4), avoiding errors in contour search.
[0118] Among them, when i4 in the search result (i4, j4) obtained in the same round of loop search is greater than i3 in the neighborhood search center point (i3, j3) of the same round of loop search, it indicates that the search result (i4, j4) meets the judgment condition for the starting point of reverse contour search, and then it is determined that the search result (i4, j4) obtained in the same round of loop search is a boundary point that meets the starting condition of contour search. Or, when i4 in the search result (i4, j4) obtained in the same round of loop search is equal to i3 in the neighborhood search center point (i3, j3) of the same round of loop search, and j4 in the search result (i4, j4) obtained in the same round of loop search is greater than j3 in the neighborhood search center point (i3, j3) of the same round of loop search, it indicates that the search result (i4, j4) meets the judgment condition for the starting point of forward contour search, and then it is determined that the search result (i4, j4) obtained in the same round of loop search is a boundary point that meets the starting condition of contour search. The update rule for the set of scanned points described above can be exemplarily expressed as:
[0119] if(i4>i3)
[0120] (i5,j5)=(i4,j4) / / If i4 in the search result (i4, j4) is greater than i3 in the neighborhood search center point (i3, j3), the scanned point (i5, j5) is updated with the search result (i4, j4)
[0121] else if((i4==i3)&&(j4>j3))
[0122] (i5, j5) = (i4, j4) / / If i4 in the search result (i4, j4) is equal to i3 in the neighborhood search center point (i3, j3), and j4 in the search result (i4, j4) is greater than j3 in the neighborhood search center point (i3, j3), then use the search result (i4, j4) to update the scanned point (i5, j5).
[0123] For ease of understanding, the following combines Figure 7 and takes the contour search as the reverse contour search as an example to introduce in detail the process of the reverse contour search shown in the foregoing steps (1) and (2). As Figure 7 shown, including but not limited to:
[0124] Step 1 (i.e., the process of the foregoing step (1)): Scan the image in the raster scanning manner in the order from top to bottom and from left to right to obtain the starting point (i, j) = (1, 2); and when it is determined that the starting point (1, 2) is not in the scanned state, determine the starting boundary point (i2, j2) = (i, j - 1) = (1, 1) based on the starting point (i, j).
[0125] Step 2: Starting from the starting boundary point (i2, j2), rotate clockwise to find the first non - zero point (1, 3) in the neighborhood of the starting point (i, j), and use this first non - zero point (1, 3) as the search base point (i1, j1).
[0126] Step 3: Update the coordinate values of the starting boundary point (i2, j2) and the neighborhood search center point (i3, j3) according to the search rules of the reverse contour search; specifically, use the starting point (i, j) as the neighborhood search center point (i3, j3) for the first - round loop search. And use the search base point (i1, j1) as the starting boundary point (i2, j2) for the first - round loop search.
[0127] Step 4: During the first - round loop search, with the neighborhood search center point (1, 2) of the first - round loop search as the center of the 8 - neighborhood, find the next pixel point (i2_jext, j2_jext) = (0, 3) in the counter - clockwise direction of the starting boundary point (1, 3) of the first - round loop search.
[0128] Step 5: Starting from this pixel point (i2_jext, j2_jext), with the neighborhood search center point (1, 2) of the first - round loop search as the 8 - neighborhood center, find the first non - zero point (2, 2), and this first non - zero point (2, 2) is the first search result (i4, j4) = (2, 2) of the first - round loop search.
[0129] Step 6: After the end of the first round of loop search, it is determined whether the first search result (i4, j4) meets the loop end condition (such as whether it returns to the starting point of this contour search); if not, it jumps back to Step 4 to continue the loop search (such as the second round of loop search, the third round of loop search, the fourth round of loop search, etc.); conversely, if it meets, this contour search ends and jumps to Step 1 to perform the next contour search. In addition, when the first search result (i4, j4) does not meet the loop end condition, it is also determined whether the first search result (i4, j4) meets the starting point determination condition according to the update rule given above; if it meets, the first search result (i4, j4) is used to update the scanned point (i5, j5); if not, the first search result (i4, j4) is only used as a boundary point scanned by this contour search, and no boundary conversion is performed on the first search result (i4, j4).
[0130] S304: Based on the starting point and the boundary point, the target contour connected by the starting point and the boundary point is marked in the image.
[0131] Based on the foregoing steps, the starting point and the boundary point can be searched from the image. Then, the curve obtained by connecting the starting point and the boundary point in the image is the target contour. To facilitate the user to intuitively perceive the shape and position of the identified target contour from the image, the embodiments of the present application support marking the target contour connected by the starting point and the boundary point in the image; the marking here may include: deepening the color of the curve of the target contour, or reducing the color depth of other lines in the image except the target contour, etc.
[0132] In addition, it should be noted that the above steps S301 - S304 introduce the process of contour search by taking one contour search in the image as an example. It should be understood that the number of contours included in the image is often relatively large. For example, an object in the image is often composed of multiple contours; taking the case where the image also includes a reference contour and the reference contour is different from the target contour as an example, the execution order of the contour search for the target contour and the reference contour in the image is synchronous or asynchronous. That is, it supports performing multiple contour searches simultaneously in the image, or performing multiple contour searches at different times in the image to identify multiple contours that need to be searched out from the image, or performing multiple contour searches at different times and simultaneously in the image. The embodiments of the present application do not limit the order of multiple contour searches. Here, the simultaneous (or synchronous) or time-sharing (or asynchronous) refers to the start time of the contour search; for example, simultaneous means that the start times of two or more contour searches are the same, and for another example, time-sharing means that the start times of two or more contour searches are different.
[0133] Taking the example of performing multiple contour searches in the image at different times, after the contour search for the target contour in the image is completed, first, it can be determined whether there are still contours to be searched in the image. The determination methods include: based on the coordinates of each pixel point in the scanned point set that is in the scanned state, re-scanning the starting point of the contour in the image; if it is scanned that the coordinates of the starting point in the image do not belong to the scanned point set, it is determined that there are contours to be searched in the image. Second, if it is detected that there are no contours to be searched in the image, step S304 is triggered, that is, based on the starting point and the boundary point, the target contour connected by the starting point and the boundary point is marked in the image. On the contrary, if it is detected that there are contours to be searched in the image, the contour search can continue to be performed using the search rule. Here, the search rule can be the search rule of forward contour search or the search rule of reverse contour search, which is not limited here, until all the specified contours in the image are searched; the specified contours here can default to all the contours in the image, or can also be part of the contours in the image, which is specifically determined according to the contour search service for the image. For example, if the contour search service indicates to perform contour search on a certain object (such as an animal, a vehicle, a moving object, or a tree, etc.) in the image, then the specified contour here refers to the contour of that certain object. Finally, after the specified contours in the image are searched, the searched specified contours can be marked in the image together. The specified contours here at least include the aforementioned target contour, that is, it supports marking all the contours in the image in batches only after all the contours to be recognized are searched; of course, it is also possible to mark one or more contours in the image immediately after each one or more contours are recognized, which is not limited here.
[0134] In summary, the embodiment of the present application supports caching the pixel points scanned (or searched) in each contour search and meeting the starting conditions of the contour search; in this way, during any contour search process, only when the starting point or the search result found is not the pixel point that has been stored, the contour search continues; compared with directly performing the contour search after scanning the starting point or the search result, it can avoid repeated searches for the same contour in the image to be processed, and can also ensure that each contour in the image to be processed is searched, ensuring the integrity (that is, all contours are searched) and consistency (that is, the searched contours are the actual contours in the image to be processed) of the contour search in the image to be processed. In addition, since the embodiment of the present application supports caching the pixel points that meet the starting conditions in the contour search. It makes the embodiment of the present application not have the situation of repeated searches when performing multi-contour searches on the image to be processed simultaneously or at different times. On the basis of ensuring the accuracy of the contour search, it effectively improves the rapidity of the contour search and improves the contour search efficiency.
[0135] The above Figure 3The embodiments mainly introduce the overall method flow of the image processing method provided by the embodiments of the present application. As described above, the image processing method provided by the embodiments of the present application can be deployed in an image processing device, and the computer device runs the image processing device to implement the image processing method. Next, an exemplary introduction to the structure of the image processing device involved in the embodiments of the present application is given. As Figure 8 shown, the image processing device at least includes the following units: a contour search rule unit, a contour boundary conversion unit corresponding to the contour search rule unit, and a scan state query unit. Among them, the contour search rule unit is used to implement contour search for an image, and during the contour search process, it judges the starting conditions for the starting point or search result obtained from the contour search to determine whether the starting point or search result is in a scanned state. The contour boundary conversion unit is used to judge whether the starting point or search result obtained from the contour search needs to be added to the set of scanned points. The scan state query unit is mainly used to store the set of scanned points, or to store the pixel points that are set to the scanned state during the historical contour search process, specifically, it stores the coordinates of the pixel points.
[0136] An exemplary process in which three units in an image processing device jointly implement single - pass contour search can be described as follows: First, after the image processing device obtains the image to be processed, it can input the image into the contour search rule unit. Then, the contour search rule unit performs contour search on the image according to the search rules of contour search (such as forward contour search or reverse contour search). Among them, during the contour search process: ① The contour search rule unit is used to search for the starting point in the image during the contour search of the image; at this time, the contour search rule unit is used to obtain the set of scanned points from the scan status query unit, and the scan status query unit is used to output the set of scanned points to the contour search rule unit; in this way, the contour search rule unit is also used to perform contour search in the image based on the starting point when the found starting point does not belong to the set of scanned points, and obtain the boundary points in the image. ② Every time the contour search rule unit searches for a pixel point (such as the first starting point found, or each boundary point found), it will send the coordinates of the pixel point to the contour boundary conversion unit; in this way, the contour boundary conversion unit is used to, during the multi - pass loop search of the contour search, if the search result (i4, j4) obtained in any pass of the loop search is a boundary point that meets the starting condition of the contour search, send the search result (i4, j4) obtained in any pass of the loop search to the scan status query unit. At this time, the scan status query unit is used to update the set of scanned points based on the search result (i4, j4) obtained in any pass of the loop search, and the updated set of scanned points includes the search result (i4, j4) obtained in any pass of the loop search, so as to ensure that there will be no repeated search for the scanned pixel points during subsequent contour search, and improve the search performance.
[0137] In addition, in the above - mentioned process, the scan status query unit is also used to store the coordinates of each pixel point searched in all completed contour searches for the image. In this way, after a certain contour search by the contour search rule unit ends, it can be determined whether there are still pixel points in the image that have not been scanned based on the coordinates of the pixel points stored in the scan status query unit. If there are, the contour search rule unit is called to continue scanning the pixel points in the image that have not been scanned, and a new contour search is started when it is determined that the scanned pixel point is a new starting point. On the contrary, if not, it indicates that every pixel point in the image has been scanned and there is no new contour to be searched, and then all contours can be output. Specifically, the image can be output, and all the searched contours are marked in the image.
[0138] Furthermore, as described above, the search types of the contour search involved in the embodiments of the present application can include: forward contour search or reverse contour search. Therefore, the above - mentioned Figure 8The contour search rule unit shown may include: a forward contour search rule subunit and / or a reverse contour search rule subunit, and each contour search rule subunit corresponds to a contour boundary conversion subunit. For example, the forward contour search rule subunit corresponds to a forward contour boundary conversion subunit, and the reverse contour search rule subunit corresponds to a reverse contour boundary conversion subunit. It should be noted that the number of contour search rule subunits and contour boundary conversion subunits included in the contour search rule unit may be one or more, and the search types of the contour searches performed by multiple contour search rule subunits may be the same or different. That is to say, the contour search rule unit in the image processing device may include one or more contour search rule subunits, and when the contour search rule unit includes multiple contour search rule subunits, the search types of the contour searches performed by multiple contour search rule subunits may be the same or different. For example, the contour search rule unit includes a forward contour search rule subunit and a reverse contour search rule subunit; another example is that the contour search rule unit includes N1 forward contour search rule subunits and N2 reverse contour search rule subunits, where N1 and N2 are both integers greater than 1.
[0139] Furthermore, when the number of contour search rule subunits included in the contour search rule unit is multiple, it supports performing multiple contour searches on the image using multiple contour search rule subunits and contour boundary conversion subunits; among them, the search start times of the multiple contour searches may be synchronous or asynchronous (i.e., simultaneous or time-division). Taking the number of contour search rule subunits included in the contour search rule unit being 2, which are a forward contour search rule subunit and a reverse contour search rule subunit respectively, and the forward contour search rule subunit corresponding to a forward contour boundary conversion subunit, and the reverse contour search rule subunit corresponding to a reverse contour boundary conversion subunit as an example, the structural schematic diagram of the image processing device can be seen Figure 9 . Such as Figure 9 shown, the image processing device includes: a forward contour search rule subunit, the forward contour boundary conversion device corresponding to the forward contour search rule subunit, a reverse contour search rule subunit, the reverse contour search boundary conversion device corresponding to the reverse contour search rule subunit, and a scan state query unit. Among them, the search rules of the forward contour search are deployed in the forward contour search rule subunit, and the forward contour search rule subunit is used to perform a forward contour search on the image. Similarly, the search rules of the reverse contour search are deployed in the reverse contour search rule subunit, and the reverse contour search rule subunit is used to perform a reverse contour search on the image.
[0140] It should be noted that for either side of the forward contour search and the reverse contour search, the search process of performing a single contour search is the same as the aforementioned Figure 8The search processes shown are similar and will not be elaborated here. Specifically, after the image processing device obtains the image to be processed, it can input the image into the forward contour search rule subunit and the reverse contour search rule subunit respectively. In this way, the forward contour search rule subunit can combine the forward contour boundary conversion subunit and the scan status query unit to perform the forward contour search process for the image; similarly, the reverse contour search rule subunit can combine the reverse contour boundary conversion subunit and the scan status query unit to perform the reverse contour search process for the image. Among them, during the process of performing the forward contour search and the reverse contour search for the image, it is particularly worth noting that the set of scanned points obtained by the forward contour search rule subunit from the scan status query unit includes not only the pixel points searched by the historical contour search (such as forward or reverse) whose search start time (i.e., the start moment of a contour search) is different from the search start time of the current forward contour search, but also the pixel points that have been set to the scanned status during the reverse contour search process whose search start time is the same as the search start time of the current forward contour search. Similarly, the set of scanned points obtained by the reverse contour search rule subunit from the scan status query unit includes not only the pixel points searched by the historical contour search (such as forward or reverse) whose search start time is different from the search start time of the current reverse contour search, but also the pixel points that have been set to the scanned status during the forward contour search process whose search start time is the same as the search start time of the current reverse contour search.
[0141] It can be seen that the contour boundary conversion unit and the scan status query unit provided in the embodiments of the present application are a new type of technology, which can cache (or set to the scanned status) the pixel points that meet the starting conditions of the contour search for each contour search, so that subsequent contour searches will not be based on the scanned pixel points, avoiding repeated searches of the contour and ensuring the integrity of the contour search in the image. In addition, in the case where the image processing device includes multiple contour boundary conversion units and contour search rule subunits, these multiple contour boundary conversion units and contour search rule subunits can perform contour searches on the image simultaneously, greatly improving the contour search speed and efficiency for the image and enhancing the contour search performance on the basis of ensuring the correctness of the contour search.
[0142] The method of the embodiments of the present application is elaborated in detail above. To facilitate better implementation of the above solutions of the embodiments of the present application, correspondingly, the device of the embodiments of the present application is provided below.
[0143] Figure 10The figure shows a schematic structural diagram of an image processing device provided by an exemplary embodiment of the present application; the image processing device may be a computer program (including program code) running on a computer device. For example, the image processing device may be an application program of the computer device or a computer program in a chip; the image processing device may be used to execute Figure 3 , Figure 8 and Figure 9 part or all of the steps in the method embodiments shown. Please refer to Figure 10 . The image processing device includes: a contour search rule unit 1001, a contour boundary conversion unit 1002, and a scan status query unit 1003; where:
[0144] The contour search rule unit 1001 is configured to search for a starting point in the image during the process of contour search for the image to be processed.
[0145] The scan status query unit 1003 is configured to output a set of scanned points to the contour search rule unit 1001. The set of scanned points is used to store pixel points that are searched during the historical contour search process and meet the starting conditions of the contour search.
[0146] The contour search rule unit 1001 is further configured to obtain the set of scanned points from the scan status query unit 1003.
[0147] The contour search rule unit 1001 is further configured to, if the searched starting point does not belong to the set of scanned points, perform a contour search in the image based on the starting point to obtain boundary points in the image.
[0148] The contour search rule unit 1001 is further configured to identify a target contour formed by connecting the starting point and the boundary points in the image based on the starting point and the boundary points.
[0149] In one implementation, the contour search for the target contour is a reverse contour search. The reverse contour search refers to performing a contour search in the counterclockwise direction with the starting point as the reference; the reverse contour search includes one or more rounds of loop searches; the starting point of the target contour is represented as (i, j). When the contour search rule unit 1001 is configured to perform a contour search in the image based on the starting point to obtain boundary points in the image, it is specifically configured to:
[0150] Determine the starting boundary point (i2, j2) of the reverse contour search according to the search rule of the reverse contour search and based on the starting point (i, j), and add the starting point (i, j) to the set of scanned points.
[0151] Starting from the starting boundary point (i2, j2), search clockwise for the search base point (i1, j1) within the neighborhood of the starting point (i, j), and use the search base point (i1, j1) as the starting boundary point (i2, j2) for the first round of cyclic search, and use the starting point (i, j) as the neighborhood search center point (i3, j3) for the first round of cyclic search;
[0152] Based on the starting boundary point (i2, j2) and the neighborhood search center point (i3, j3) of the first round of cyclic search, perform the first round of cyclic search on the image to obtain the first round of search result (i4, j4);
[0153] Determine whether the first round of search result (i4, j4) meets the loop end condition;
[0154] If it meets the condition, end the reverse contour search for this time; the only pixel point included in the target contour is the starting point (i, j) of the first round of cyclic search.
[0155] In one implementation, the contour search rule unit 1001 is further configured to:
[0156] If it does not meet the condition, use the neighborhood search center point (i3, j3) of the first round of cyclic search as the starting boundary point (i2, j2) for the second round of cyclic search, and use the first round of search result (i4, j4) of the first round of cyclic search as the neighborhood search center point (i3, j3) for the second round of cyclic search;
[0157] Based on the starting boundary point (i2, j2) and the neighborhood search center point (i3, j3) of the second round of cyclic search, perform the second round of cyclic search on the image to obtain the second round of search result (i4, j4);
[0158] Determine whether the second round of search result (i4, j4) meets the loop end condition;
[0159] Repeat the above steps until the k-th round of search result (i4, j4) of the k-th round of cyclic search meets the loop end condition, where k is an integer greater than or equal to 2; the pixel points forming the target contour include: the starting point (i, j) of the first round of cyclic search and the search results (i4, j4) of other cyclic searches except the first round of cyclic search in the k rounds of cyclic search.
[0160] In one implementation, when the contour search rule unit 1001 is configured to perform the second round of cyclic search on the image based on the starting boundary point (i2, j2) and the neighborhood search center point (i3, j3) of the second round of cyclic search to obtain the second round of search result (i4, j4), it is specifically configured to:
[0161] Starting from the starting boundary point (i2, j2) of the second-round loop search, search counterclockwise for the first non-zero point within the neighborhood of the neighborhood search center point (i3, j3) of the second-round loop search.
[0162] Take the first non-zero point as the second-round search result (i4, j4) of the second-round loop search.
[0163] In one implementation, the search result (i4, j4) obtained from any round of loop search meets the loop end condition, including:
[0164] The search result (i4, j4) obtained from any round of loop search is located in the set of scanned points; or,
[0165] The search result (i4, j4) obtained from any round of loop search is the same as the starting point (i, j) of the first-round loop search, and the neighborhood search center point (i3, j3) of any round of loop search is the same as the search base point (i1, j1).
[0166] In one implementation, the image processing device further includes a contour boundary conversion unit 1002 corresponding to the contour search rule unit 1001; wherein,
[0167] The contour boundary conversion unit 1002 is configured to, during the multi-round loop search of the contour search, if the search result (i4, j4) obtained from any round of loop search is a boundary point that meets the starting condition of the contour search, send the search result (i4, j4) obtained from any round of loop search to the scan status query unit 1003;
[0168] The scan status query unit 1003 is configured to update the set of scanned points based on the search result (i4, j4) obtained from any round of loop search, and the updated set of scanned points includes the search result (i4, j4) obtained from any round of loop search;
[0169] Wherein, when i4 in the search result (i4, j4) obtained from the same round of loop search is greater than i3 in the neighborhood search center point (i3, j3) of the same round of loop search, determine that the search result (i4, j4) obtained from the same round of loop search is a boundary point that meets the starting condition of the contour search; or,
[0170] When i4 in the search result (i4, j4) obtained from the same round of loop search is equal to i3 in the neighborhood search center point (i3, j3) of the same round of loop search, and j4 in the search result (i4, j4) obtained from the same round of loop search is greater than j3 in the neighborhood search center point (i3, j3) of the same round of loop search, determine that the search result (i4, j4) of the same round of loop search is a boundary point that meets the starting condition of the contour search.
[0171] In one implementation, the contour search rule unit 1001 is further configured to obtain each pixel point of the historical contour search from the scan status query unit 1003;
[0172] After the contour search for the target contour ends, the contour search rule unit 1001 is further configured to determine whether there is a contour to be searched in the image based on each pixel point of the historical contour search;
[0173] If there is, the contour search rule unit 1001 continues to perform contour search using the search rule until all contours in the image are searched; and marks the searched contours in the image; the searched contours at least include the target contour;
[0174] If not, the contour search rule unit 1001 triggers the execution of the step of marking the target contour formed by connecting the starting point and the boundary point in the image based on the starting point and the boundary point.
[0175] In one implementation, when the contour search rule unit 1001 is configured to determine whether there is a contour to be searched in the image, it is specifically configured to:
[0176] Based on the coordinates of each scanned point in the scanned point set that is in the scanned state, re-scan the starting point of the contour in the image;
[0177] If it is scanned that the coordinates of the starting point in the image do not belong to the scanned point set, it is determined that there is a contour to be searched in the image.
[0178] In one implementation, the image further includes a reference contour, and the reference contour is different from the target contour;
[0179] Among them, the execution order of the contour search for the target contour and the reference contour in the image is synchronous.
[0180] In one implementation, the image is a binary image, any pixel point in the binary image is represented as (i, j), and the pixel value of the pixel point (i, j) is represented as f(i, j); the search types of the contour search include: forward contour search and reverse contour search; the forward contour search means performing contour search in the clockwise direction with the starting point as the reference; the reverse contour search means performing contour search in the counterclockwise direction with the starting point as the reference;
[0181] The judgment conditions for the starting point of the forward contour search include:
[0182] Scan the binary image in the scanning order from bottom to top and from right to left;
[0183] If f(i, j) = 1 is scanned and f(i, j + 1) = 0, then the pixel point (i, j) is used as the starting point of the target contour;
[0184] The judgment conditions for the starting point of the reverse contour search include:
[0185] Scan the binary image in the scanning order from left to right and from top to bottom;
[0186] If f(i, j) = 1 is scanned and f(i, j - 1) = 0, then the pixel point (i, j) is used as the starting point of the target contour.
[0187] In one implementation, the contour search rule unit 1001 includes: a forward contour search rule subunit 10011 and / or a reverse contour search rule subunit 10012; each contour search rule subunit corresponds to a contour boundary conversion sub-device;
[0188] The forward contour search rule subunit 10011 deploys the search rules for forward contour search; the forward contour search rule subunit 10011 is used to perform forward contour search on the image; forward contour search means performing contour search in the clockwise direction with the starting point as the reference;
[0189] The reverse contour search rule subunit 10012 deploys the search rules for reverse contour search; the reverse contour search rule subunit 10012 is used to perform reverse contour search on the image; reverse contour search means performing contour search in the clockwise direction with the starting point as the reference; forward contour search means performing contour search in the counterclockwise direction with the starting point as the reference.
[0190] In one implementation, the number of the contour search rule unit 1001 and the contour boundary conversion unit 1002 is the same, and the number of the contour search rule unit 1001 and the contour boundary conversion unit 1002 can be one or more;
[0191] When the number of the contour search rule subunits included in the contour search rule unit 1001 is multiple, multiple contour search rule subunits and contour boundary conversion subunits are used to perform multiple contour searches on the image;
[0192] Among them, the search types of the contour searches performed by the multiple contour search rule subunits are the same or different.
[0193] According to an embodiment of the present application, Figure 10Each unit in the image processing apparatus shown can be separately or all combined into one or several other units to form, or a certain one (or some) of the units can be further split into multiple smaller units with more specific functions to form. This can achieve the same operations without affecting the realization of the technical effects of the embodiments of this application. The above units are divided based on logical functions. In practical applications, the function of one unit can also be realized by multiple units, or the functions of multiple units can be realized by one unit. In other embodiments of this application, the image processing apparatus can also include other units. In practical applications, these functions can also be assisted by other units and can be realized through the cooperation of multiple units. According to another embodiment of this application, it can be achieved by running a computer program (including program code) capable of executing the respective steps involved in the corresponding methods shown in Figure 3 , Figure 8 and Figure 9 on a general computing device such as a computer including processing elements and storage elements such as a central processing unit (CPU), a random access storage medium (RAM), and a read-only storage medium (ROM), to construct an image processing apparatus as shown in Figure 10 and to implement the image processing method of the embodiments of this application. The computer program can be recorded on, for example, a computer-readable recording medium, loaded into the above computing device through the computer-readable recording medium, and run therein.
[0194] In an embodiment of the present application, during the process of contour search for an image to be processed, when the starting point in the image to be processed is found, a status query is first performed on the starting point. Specifically, it is determined whether the starting point falls into the set of scanned points, and the set of scanned points is used to store the pixel points that are found during the historical contour search and meet the starting conditions of the contour search. That is to say, after the starting point is found, it is first detected whether the starting point has been scanned during the historical contour search. If not, it indicates that the contour with the starting point as the boundary point has not been searched yet, and then the contour search can continue in the image to be processed based on the starting point to obtain the target contour formed by the starting point and other boundary points. On the contrary, if so, it indicates that the contour with the starting point as the boundary point has been searched in the historical time, and the current contour search with the starting point as the boundary point is cancelled. As can be seen from the above solution, the embodiment of the present application provides a new method for contour search. This method supports caching the pixel points that are scanned (or found) during each contour search and meet the starting conditions of the contour search. In this way, during any contour search, the contour search only continues when the found starting point is not the pixel point that has been stored. Compared with directly performing the contour search after the starting point is scanned, it can avoid repeated searches for the same contour in the image to be processed, and can also ensure that each contour in the image to be processed is searched, ensuring the integrity (i.e., all contours are searched) and consistency (i.e., the searched contour is the actual contour in the image to be processed) of the contour search in the image to be processed. In addition, considering that each contour search will cache the scanned pixel points that meet the starting conditions, this makes the embodiment of the present application not have the situation of repeated searches when performing multiple contour searches on the image to be processed at the same time. On the basis of ensuring the accuracy of the contour search, it effectively improves the rapidity of the contour search and improves the contour search efficiency.
[0195] Figure 11 FIG. shows a schematic structural diagram of a computer device provided by an exemplary embodiment of the present application. Please refer to Figure 11, the computer device includes a processor 1101, a communication interface 1102, and a computer-readable storage medium 1103. Among them, the processor 1101, the communication interface 1102, and the computer-readable storage medium 1103 can be connected through a bus or other means. Among them, the communication interface 1102 is used to receive and send data. The computer-readable storage medium 1103 can be stored in the memory of the computer device. The computer-readable storage medium 1103 is used to store a computer program, and the computer program includes program instructions. The processor 1101 is used to execute the program instructions stored in the computer-readable storage medium 1103. The processor 1101 (or CPU (Central Processing Unit, central processor)) is the computing core and control core of the computer device, and is suitable for implementing one or more instructions, specifically suitable for loading and executing one or more instructions to implement the corresponding method flow or corresponding function.
[0196] The embodiment of the present application also provides a computer-readable storage medium (Memory). The computer-readable storage medium is a memory device in the computer device and is used to store programs and data. It can be understood that the computer-readable storage medium here can include both the built-in storage medium in the computer device and, of course, the extended storage medium supported by the computer device. The computer-readable storage medium provides a storage space, and this storage space stores the processing system of the computer device. And, one or more instructions suitable for being loaded and executed by the processor 1101 are also stored in this storage space. These instructions can be one or more computer programs (including program codes). It should be noted that the computer-readable storage medium here can be a high-speed RAM memory or a non-volatile memory, such as at least one disk memory; optionally, it can also be at least one computer-readable storage medium located far from the aforementioned processor.
[0197] In one embodiment, one or more instructions are stored in the computer-readable storage medium; the processor 1101 loads and executes one or more instructions stored in the computer-readable storage medium to implement the corresponding steps in the above-mentioned embodiment of the image processing method; one or more instructions in the computer-readable storage medium are loaded and executed by the processor 1101 as follows:
[0198] During the process of contour search for the image to be processed, a starting point in the image is searched for;
[0199] Obtain a set of scanned points, and the set of scanned points is used to store the pixel points that are searched during the historical contour search process and meet the starting conditions of the contour search;
[0200] If the starting point found does not belong to the set of scanned points, perform contour search in the image based on the starting point to obtain the boundary points in the image.
[0201] Based on the starting point and the boundary points, identify the target contour formed by connecting the starting point and the boundary points in the image.
[0202] In one implementation, the contour search for the target contour is a reverse contour search. The reverse contour search means performing contour search in the counterclockwise direction with the starting point as the reference. The reverse contour search includes one or more rounds of cyclic search. The starting point of the target contour is represented as (i, j). When one or more instructions in the computer-readable storage medium are loaded by the processor 1101 and executed to perform contour search in the image based on the starting point to obtain the boundary points in the image, the following steps are specifically executed:
[0203] According to the search rules of the reverse contour search and based on the starting point (i, j), determine the starting boundary point (i2, j2) of the reverse contour search, and add the starting point (i, j) to the set of scanned points.
[0204] Starting from the starting boundary point (i2, j2), search clockwise for the search base point (i1, j1) in the neighborhood of the starting point (i, j), and use the search base point (i1, j1) as the starting boundary point (i2, j2) of the first round of cyclic search, and use the starting point (i, j) as the neighborhood search center point (i3, j3) of the first round of cyclic search.
[0205] Based on the starting boundary point (i2, j2) and the neighborhood search center point (i3, j3) of the first round of cyclic search, perform the first round of cyclic search on the image to obtain the first round of search result (i4, j4).
[0206] Judge whether the first round of search result (i4, j4) meets the loop end condition.
[0207] If it meets, end the reverse contour search for this time. The only pixel point included in the target contour is the starting point (i, j) of the first round of cyclic search.
[0208] In one implementation, one or more instructions in the computer-readable storage medium are loaded by the processor 1101 and further execute the following steps:
[0209] If it does not meet, use the neighborhood search center point (i3, j3) of the first round of cyclic search as the starting boundary point (i2, j2) of the second round of cyclic search, and use the first round of search result (i4, j4) of the first round of cyclic search as the neighborhood search center point (i3, j3) of the second round of cyclic search.
[0210] Based on the starting boundary point (i2, j2) of the second-round loop search and the neighborhood search center point (i3, j3), perform a second-round loop search on the image to obtain the second-round search result (i4, j4).
[0211] Determine whether the second-round search result (i4, j4) meets the loop end condition.
[0212] Repeat the above steps until the k-th round search result (i4, j4) of the k-th round loop search meets the loop end condition, where k is an integer greater than or equal to 2; the pixel points forming the target contour include: the starting point (i, j) of the first-round loop search and the search results (i4, j4) of other loop searches except the first-round loop search in the k rounds of loop searches.
[0213] In one implementation, when one or more instructions in the computer-readable storage medium are loaded by the processor 1101 and execute a second-round loop search on the image based on the starting boundary point (i2, j2) of the second-round loop search and the neighborhood search center point (i3, j3) to obtain the second-round search result (i4, j4), the following steps are specifically executed:
[0214] Starting from the starting boundary point (i2, j2) of the second-round loop search, find the first non-zero point in the neighborhood of the neighborhood search center point (i3, j3) of the second-round loop search counterclockwise.
[0215] Take the first non-zero point as the second-round search result (i4, j4) of the second-round loop search.
[0216] In one implementation, the search result (i4, j4) obtained in any round of loop search meeting the loop end condition includes:
[0217] The search result (i4, j4) obtained in any round of loop search is located in the set of scanned points; or,
[0218] The search result (i4, j4) obtained in any round of loop search is the same as the starting point (i, j) of the first-round loop search, and the neighborhood search center point (i3, j3) of any round of loop search is the same as the search base point (i1, j1).
[0219] In one implementation, one or more instructions in the computer-readable storage medium are loaded by the processor 1101 and further execute the following steps:
[0220] During the multi-round cyclic search of contour search, if the search result (i4, j4) obtained in any round of cyclic search is a boundary point that meets the starting condition of contour search, the scanned point set is updated based on the search result (i4, j4) obtained in any round of cyclic search, and the updated scanned point set includes the search result (i4, j4) obtained in any round of cyclic search;
[0221] Among them, when i4 in the search result (i4, j4) obtained in the same round of cyclic search is greater than i3 in the neighborhood search center point (i3, j3) of the same round of cyclic search, it is determined that the search result (i4, j4) obtained in the same round of cyclic search is a boundary point that meets the starting condition of contour search; or,
[0222] When i4 in the search result (i4, j4) obtained in the same round of cyclic search is equal to i3 in the neighborhood search center point (i3, j3) of the same round of cyclic search, and j4 in the search result (i4, j4) obtained in the same round of cyclic search is greater than j3 in the neighborhood search center point (i3, j3) of the same round of cyclic search, it is determined that the search result (i4, j4) of the same round of cyclic search is a boundary point that meets the starting condition of contour search.
[0223] In one implementation, one or more instructions in the computer-readable storage medium are loaded and executed by the processor 1101, and the following steps are further performed:
[0224] Obtain each pixel point of the historical contour search;
[0225] After the contour search for the target contour ends, determine whether there is a contour to be searched in the image based on each pixel point of the historical contour search;
[0226] If there is, continue to perform contour search using the search rule until all contours in the image are searched; and mark the searched contours in the image; the searched contours include at least the target contour;
[0227] If not, trigger the step of marking the target contour formed by the starting point and the boundary point in the image based on the starting point and the boundary point.
[0228] In one implementation, one or more instructions in the computer-readable storage medium are loaded and executed by the processor 1101, and when determining whether there is a contour to be searched in the image, the following steps are specifically performed:
[0229] Based on the coordinates of each scanned point in the scanned state included in the scanned point set, re-scan the starting point of the contour in the image;
[0230] If it is scanned that the coordinates of the starting point in the image do not belong to the set of scanned points, it is determined that there is a contour to be searched in the image.
[0231] In one implementation, the image further includes a reference contour, which is different from the target contour;
[0232] Among them, the execution order of the contour search for the target contour and the reference contour in the image is synchronous.
[0233] In one implementation, the image is a binary image. Any pixel point in the binary image is represented as (i, j), and the pixel value of the pixel point (i, j) is represented as f(i, j); the search types of the contour search include: forward contour search and reverse contour search; the forward contour search means performing a contour search in the clockwise direction with the starting point as the reference; the reverse contour search means performing a contour search in the counterclockwise direction with the starting point as the reference.
[0234] The judgment conditions for the starting point of the forward contour search include:
[0235] Scan the binary image in the scanning order from bottom to top and from right to left;
[0236] If it is scanned that f(i, j) = 1 and f(i, j + 1) = 0, then the pixel point (i, j) is used as the starting point of the target contour.
[0237] The judgment conditions for the starting point of the reverse contour search include:
[0238] Scan the binary image in the scanning order from left to right and from top to bottom;
[0239] If it is scanned that f(i, j) = 1 and f(i, j - 1) = 0, then the pixel point (i, j) is used as the starting point of the target contour.
[0240] In the embodiments of the present application, during the process of contour search for the image to be processed, when the starting point in the image to be processed is searched, the status of the starting point is first queried. Specifically, it is determined whether the starting point falls into the set of scanned points, and the set of scanned points is used to store the pixel points that are searched during the historical contour search and meet the starting conditions of the contour search; that is to say, after the starting point is searched, it is first detected whether the starting point has been scanned during the historical contour search. If not, it indicates that the contour with the starting point as the boundary point has not been searched yet, and then the contour search can continue in the image to be processed based on the starting point to obtain the target contour connected by the starting point and other boundary points. On the contrary, if so, it indicates that the contour with the starting point as the boundary point has been searched in the historical time, and then the current contour search with the starting point as the boundary point is cancelled. It can be seen from the above solution that the embodiments of the present application provide a new contour search method, which supports caching the pixel points that are scanned (or searched) during each contour search and meet the starting conditions of the contour search; in this way, during any contour search, only when the searched starting point is not the stored pixel point, the contour search continues; compared with directly performing the contour search after scanning the starting point, it can avoid repeated searches for the same contour in the image to be processed, and can also ensure that each contour in the image to be processed is searched, ensuring the integrity (i.e., all contours are searched) and consistency (i.e., the searched contour is the actual contour in the image to be processed) of the contour search in the image to be processed. In addition, considering that each contour search will cache the scanned pixel points that meet the starting conditions, this makes the embodiments of the present application not have repeated searches when performing multiple contour searches on the image to be processed at the same time. On the basis of ensuring the accuracy of the contour search, it effectively improves the rapidity of the contour search and improves the contour search efficiency.
[0241] The embodiments of the present application also provide a computer program product, which includes a computer program. When the computer program is executed by a processor, the above image processing method is implemented.
[0242] Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed in the present application can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but this implementation should not be considered to exceed the scope of the present application.
[0243] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions according to the embodiments of the present application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transmitted through a computer-readable storage medium. The computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center in a wired manner (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or a wireless manner (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data processing device such as a server or a data center that includes one or more integrated available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)), etc.
[0244] As described above, the above is only the specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any technical person familiar with the technical field of the present application can easily think of changes or substitutions within the technical scope disclosed in the present application, and all should be covered by the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. An image processing method, characterized in that, Including: During the process of performing multiple contour searches synchronously on the image to be processed, according to the judgment condition of the starting point corresponding to the search type to which each contour search belongs, the starting point in the image corresponding to each contour search is searched; the search type to which any one of the contour searches belongs is a forward contour search or a reverse contour search; the image is a binary image, and any pixel point in the binary image is represented as (i, j); the judgment condition of the starting point of the forward contour search includes: scanning the binary image in the scanning order from bottom to top and from right to left, if f(i, j)=1 and f(i, j + 1)=0 are scanned, then the pixel point (i, j) is used as the starting point of the target contour; the judgment condition of the starting point of the reverse contour search includes: scanning the binary image in the scanning order from left to right and from top to bottom, if f(i, j)=1 and f(i, j - 1)=0 are scanned, then the pixel point (i, j) is used as the starting point of the target contour; Obtain a set of scanned points, where the set of scanned points is used to store pixel points that are searched during the historical contour search process and meet the starting conditions of the contour search; If the starting point searched by any one of the contour searches does not belong to the set of scanned points, then based on the starting point searched by any one of the contour searches, perform a contour search in the image to obtain the boundary points in the image corresponding to any one of the contour searches; Based on the starting point searched by any one of the contour searches and the corresponding boundary points, mark the target contour formed by connecting the starting point searched by any one of the contour searches and the corresponding boundary points in the image.
2. The method according to claim 1, wherein The contour search for the target contour is a reverse contour search, where the reverse contour search means performing a contour search in the counterclockwise direction with the starting point as the reference; the reverse contour search includes one or more rounds of cyclic searches; the starting point of the target contour is represented as (i, j); the performing a contour search in the image based on the starting point searched by any one of the contour searches to obtain the boundary points in the image corresponding to any one of the contour searches includes: According to the search rule of the reverse contour search and based on the starting point (i, j), determine the starting boundary point (i2, j2) of the reverse contour search, and add the starting point (i, j) to the set of scanned points; Starting from the starting boundary point (i2, j2), clockwise search for the search base point (i1, j1) in the neighborhood of the starting point (i, j), and use the search base point (i1, j1) as the starting boundary point (i2, j2) of the first round of cyclic search, and use the starting point (i, j) as the neighborhood search center point (i3, j3) of the first round of cyclic search; Based on the starting boundary point (i2, j2) and the neighborhood search center point (i3, j3) of the first round of cyclic search, perform the first round of cyclic search on the image to obtain the first round of search result (i4, j4); Determine whether the first-round search result (i4, j4) meets the loop end condition; If it meets the condition, end the reverse contour search for this time; the only pixel point included in the target contour is the starting point (i, j) of the first-round loop search.
3. The method according to claim 2, wherein The method further includes: If it does not meet the condition, use the neighborhood search center point (i3, j3) of the first-round loop search as the starting boundary point (i2, j2) of the second-round loop search, and use the first-round search result (i4, j4) of the first-round loop search as the neighborhood search center point (i3, j3) of the second-round loop search; Based on the starting boundary point (i2, j2) and the neighborhood search center point (i3, j3) of the second-round loop search, perform a second-round loop search on the image to obtain a second-round search result (i4, j4); Determine whether the second-round search result (i4, j4) meets the loop end condition; Repeat the above steps until the k-th round search result (i4, j4) of the k-th round loop search meets the loop end condition, where k is an integer greater than or equal to 2; the pixel points forming the target contour include: the starting point (i, j) of the first-round loop search and the search results (i4, j4) of other loop searches except the first-round loop search in the k rounds of loop searches.
4. The method according to claim 3, wherein The performing a second-round loop search on the image based on the starting boundary point (i2, j2) and the neighborhood search center point (i3, j3) of the second-round loop search to obtain a second-round search result (i4, j4) includes: Starting from the starting boundary point (i2, j2) of the second-round loop search, counterclockwise find the first non-zero point in the neighborhood of the neighborhood search center point (i3, j3) of the second-round loop search; Use the first non-zero point as the second-round search result (i4, j4) of the second-round loop search.
5. The method according to any one of claims 2 to 4, characterized in that That the search result (i4, j4) obtained in any round of loop search meets the loop end condition includes: The search result (i4, j4) obtained in any round of loop search is the same as the starting point (i, j) of the first-round loop search, and the neighborhood search center point (i3, j3) of any round of loop search is the same as the search base point (i1, j1).
6. The method according to any one of claims 1 or 2 to 4, characterized in that, The method further includes: During the multi-round loop search of any of the contour searches, if the search result (i4, j4) obtained in any round of loop search is a boundary point that meets the starting condition of the contour search, update the scanned point set based on the search result (i4, j4) obtained in any round of loop search, and the updated scanned point set includes the search result (i4, j4) obtained in any round of loop search; Wherein, when i4 in the search result (i4, j4) obtained in the same round of loop search is greater than i3 in the neighborhood search center point (i3, j3) of the same round of loop search, determine that the search result (i4, j4) obtained in the same round of loop search is a boundary point that meets the starting condition of the contour search; or, When i4 in the search result (i4, j4) obtained from the same round of cyclic search is equal to i3 in the neighborhood search center point (i3, j3) of the same round of cyclic search, and j4 in the search result (i4, j4) obtained from the same round of cyclic search is greater than j3 in the neighborhood search center point (i3, j3) of the same round of cyclic search, determine the search result (i4, j4) of the same round of cyclic search as the boundary point that meets the starting condition of the contour search.
7. The method according to claim 1, wherein The method further includes: After the contour search for the target contour ends, determine whether there is a contour to be searched in the image; If there is, continue to perform contour search using the search rule until all the specified contours in the image are searched; and mark the searched specified contours in the image; the specified contours at least include the target contour; If not, trigger the step of marking the target contour formed by the starting point and the boundary point in the image based on the starting point and the boundary point.
8. The method according to claim 7, wherein The determining whether there is a contour to be searched in the image includes: Based on the coordinates of the pixel points in the scanned point set that are in the scanned state, rescan the image for the contour starting point; If it is scanned that there is a starting point coordinate in the image that does not belong to the scanned point set, determine that there is a contour to be searched in the image.
9. The method according to claim 1, wherein The image further includes a reference contour, and the reference contour is different from the target contour.
10. The method according to claim 1, characterized in that, The pixel value of the pixel point (i, j) is represented as (i, j); the forward contour search means to perform contour search in the clockwise direction with the starting point as the reference.
11. An image processing apparatus, characterized in that, The image processing device includes: a contour search rule unit, a contour boundary conversion unit, and a scan state query unit; where The contour search rule unit is used to search for the starting point in the image corresponding to each contour search according to the judgment condition of the starting point corresponding to the search type to which each contour search belongs during the process of performing multiple contour searches on the image synchronously; any search type to which a contour search belongs is a forward contour search or a reverse contour search; the image is a binary image, and any pixel point in the binary image is represented as (i, j); the judgment condition of the starting point for the forward contour search includes: scanning the binary image in the scanning order from bottom to top and from right to left, if it is scanned that f(i, j) = 1 and f(i, j + 1) = 0, then use the pixel point (i, j) as the starting point of the target contour; the judgment condition of the starting point for the reverse contour search includes: scanning the binary image in the scanning order from left to right and from top to bottom, if it is scanned that f(i, j) = 1 and f(i, j - 1) = 0, then use the pixel point (i, j) as the starting point of the target contour; The scan state query unit is used to output the scanned point set to the contour search rule unit, and the scanned point set is used to store the pixel points that are searched during the historical contour search process and meet the starting condition of the contour search. The contour search rule unit is further configured to obtain the scanned point set from the scan status query unit; The contour search rule unit is further configured to, if the starting point searched by any one of the contour searches does not belong to the scanned point set, perform a contour search in the image based on the starting point searched by any one of the contour searches to obtain the boundary points in the image corresponding to any one of the contour searches; The contour search rule unit is further configured to, based on the starting point searched by any one of the contour searches and the corresponding boundary points, identify in the image the target contour formed by connecting the starting point searched by any one of the contour searches and the corresponding boundary points.
12. The device according to claim 11, characterized in that The image processing device further includes a contour boundary conversion unit corresponding to the contour search rule unit; wherein, The contour boundary conversion unit is configured to, during the multi-round cyclic search of the contour search, if the search result (i4, j4) obtained in any round of cyclic search is a boundary point that meets the starting condition of the contour search, send the search result (i4, j4) obtained in any round of cyclic search to the scan status query unit; The scan status query unit is configured to update the scanned point set based on the search result (i4, j4) obtained in any round of cyclic search, and the updated scanned point set includes the search result (i4, j4) obtained in any round of cyclic search; Wherein, when i4 in the search result (i4, j4) obtained in the same round of cyclic search is greater than i3 in the neighborhood search center point (i3, j3) of the same round of cyclic search, it is determined that the search result (i4, j4) obtained in the same round of cyclic search is a boundary point that meets the starting condition of the contour search; or, When i4 in the search result (i4, j4) obtained in the same round of cyclic search is equal to i3 in the neighborhood search center point (i3, j3) of the same round of cyclic search, and j4 in the search result (i4, j4) obtained in the same round of cyclic search is greater than j3 in the neighborhood search center point (i3, j3) of the same round of cyclic search, it is determined that the search result (i4, j4) of the same round of cyclic search is a boundary point that meets the starting condition of the contour search.
13. The device according to claim 11, characterized in that, The contour search rule unit includes: a forward contour search rule subunit and / or a reverse contour search rule subunit; each contour search rule subunit corresponds to a contour boundary conversion sub-device; The forward contour search rule subunit is deployed with the search rules for forward contour search; the forward contour search rule subunit is configured to perform a forward contour search on the image; the forward contour search refers to performing a contour search in the clockwise direction with the starting point as the reference; The reverse contour search rule subunit is deployed with the search rules for reverse contour search; the reverse contour search rule subunit is configured to perform a reverse contour search on the image; the reverse contour search refers to performing a contour search in the clockwise direction with the starting point as the reference.
14. The device according to claim 13, characterized in that, The number of contour search rule subunits is the same as that of contour boundary conversion subunits, and the number of contour search rule subunits included in the contour search rule unit is one or more; When the number of contour search rule subunits included in the contour search rule unit is multiple, multiple contour search rule subunits and contour boundary conversion subunits are used to perform multiple contour searches on the image; Among them, the search types of the contour searches performed by the multiple contour search rule subunits are the same or different.
15. A computer device, characterized in that, A chip is provided in the computer device, and an image processing device as described in any one of claims 11-14 is provided in the chip, and the image processing device is used to implement the image processing method as described in any one of claims 1-10.
16. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, and the computer program is adapted to be loaded and executed by a processor to perform the image processing method as described in any one of claims 1-10.
17. A computer program product, characterized in that, The computer program product includes a computer program, and when the computer program is executed by a processor, it implements the image processing method as described in any one of claims 1-10.
Citation Information
Patent Citations
Table tennis ball identification method based on contour detection technology
CN115049689A
Outline detecting method
JP1995065179A