Image edge detection method and apparatus
This method, which generates edge detection by calculating the distance to each pixel in the labeled image, solves the problems of low efficiency and accuracy in edge detection of labeled images in existing technologies, and achieves pixel-level edge detection results.
Patent Information
- Application Number
- CN202210976665.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-15
- Publication Date
- 2026-01-02
- Estimated Expiration
- 2042-08-15
AI Technical Summary
The existing image edge detection annotation technology is inefficient and has low accuracy, mainly because deep learning-based image segmentation algorithms require a large amount of manually annotated data for training, resulting in manually annotated edge detection methods.
Edge pixels are generated by calculating the distance between each pixel in the labeled image and the background and target regions, thereby improving the accuracy and efficiency of edge detection.
It achieves pixel-level accuracy in edge detection through image annotation, improving the efficiency and accuracy of image edge annotation.
Smart Images

Figure CN115170597B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image processing, in particular to an image edge detection method and device. BACKGROUND
[0002] Deep learning-based image segmentation algorithms are widely used in automatic driving, high-precision maps and other applications that require fine identification of object categories and positions. Deep learning-based image segmentation algorithms require a large amount of manually annotated data for training.
[0003] In related technologies, the edges of the target region and the background region of an image are manually annotated. However, manual annotation is based on visual judgment of the target region and the background region, and the edges are manually drawn, which is time-consuming and inefficient, and the accuracy is low. SUMMARY
[0004] To solve or partially solve the problems in the related art, the present application provides an image edge detection method and device that can improve the efficiency and accuracy of image edge annotation.
[0005] The first aspect of the present application provides an image edge detection method, which comprises:
[0006] calculating a first set distance between each pixel point in a labeled image and a background region of the labeled image;
[0007] calculating a second set distance between each pixel point in the labeled image and a target region of the labeled image;
[0008] respectively according to the first set distance and the second set distance of each pixel point in the labeled image, obtaining a third set distance of each pixel point in the labeled image;
[0009] determining an edge pixel point of the background region and the target region according to the third set distance of each pixel point in the labeled image, and generating an edge of the background region and the target region from the edge pixel point.
[0010] Preferably, the calculation of the first set distance between each pixel point in the labeled image and the background region of the labeled image comprises:
[0011] setting the pixel value of the background region of the labeled image to a first set value and the pixel value of the target region to a second set value;
[0012] calculating the first set distance between each pixel point in the labeled image and the background region according to the first set value of the background region and the second set value of the target region.
[0013] Preferably, the calculating the second set distance between each pixel point in the labeled image and the target region of the labeled image comprises:
[0014] setting the pixel value of the target region as the first set value and the pixel value of the background region as the second set value;
[0015] calculating the second set distance between each pixel point in the labeled image and the target region according to the first set value of the target region and the second set value of the background region.
[0016] Preferably, the obtaining the third set distance of each pixel point in the labeled image according to the first set distance and the second set distance of each pixel point in the labeled image respectively comprises:
[0017] adding the first set distance and the second set distance of each pixel point in the labeled image respectively to obtain the third set distance of each pixel point in the labeled image.
[0018] Preferably, the determining the edge pixel point of the background region and the target region according to the third set distance of each pixel point in the labeled image and generating the edge of the background region and the target region from the edge pixel point comprises:
[0019] determining the pixel point with the third set distance less than or equal to a set distance threshold as the edge pixel point of the background region and the target region and generating the edge of the background region and the target region from the edge pixel point.
[0020] The second aspect of the present application provides an image edge detection device, the device comprising:
[0021] a first calculation module for calculating the first set distance between each pixel point in a labeled image and a background region of the labeled image;
[0022] a second calculation module for calculating the second set distance between each pixel point in the labeled image and a target region of the labeled image;
[0023] a distance processing module for obtaining the third set distance of each pixel point in the labeled image according to the first set distance of each pixel point in the labeled image calculated by the first calculation module and the second set distance of each pixel point in the labeled image calculated by the second calculation module respectively;
[0024] determining a third set distance of each pixel point in the marked image obtained by the distance processing module, determining edge pixel points of the background region and the target region, and generating edges of the background region and the target region from the edge pixel points.
[0025] Preferably, the first calculation module is further configured to set pixel values of the background region of the marked image as a first set value, and set pixel values of the target region as a second set value; and calculate a first set distance of each pixel point in the marked image from the background region according to the first set value of the background region and the second set value of the target region.
[0026] Preferably, the second calculation module is further configured to set pixel values of the target region as the first set value, and set pixel values of the background region as the second set value; and calculate a second set distance of each pixel point in the marked image from the target region according to the first set value of the target region and the second set value of the background region.
[0027] The third aspect of the present application provides an electronic device, comprising:
[0028] a processor; and
[0029] a memory having executable code stored thereon, which, when executed by the processor, causes the processor to perform the method described above.
[0030] The fourth aspect of the present application provides a computer-readable storage medium having executable code stored thereon, which, when executed by a processor of an electronic device, causes the processor to perform the method described above.
[0031] The technical solution provided by the present application can include the following beneficial effects:
[0032] The technical solution of the present application determines edge pixel points of the background region and the target region according to a third set distance of each pixel point in the marked image, and generates edges of the background region and the target region from the edge pixel points; determines edges of the marked image through the third set distance of each pixel point in the marked image, so that the accuracy of edge detection of the marked image reaches the pixel level, the edge pixel points of the marked image can be accurately detected, and the efficiency and accuracy of image edge marking can be improved.
[0033] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and cannot limit the present application. BRIEF DESCRIPTION OF DRAWINGS
[0034] The above and other objects, features and advantages of the present application will become more apparent from the following detailed description when taken in conjunction with the accompanying drawings in which like reference characters refer to like parts throughout the figures, and in which:
[0035] Figure 1 is a flowchart of an image edge detection method according to an embodiment of the present application;
[0036] Figure 2 is another flowchart of an image edge detection method according to an embodiment of the present application;
[0037] Figure 3 is a structural diagram of an image edge detection device according to an embodiment of the present application;
[0038] Figure 4 is a structural diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0039] Embodiments of the present application will be described more fully hereinafter with reference to the accompanying drawings, in which embodiments of the application are shown. This application may, however, be embodied in many different forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the application to those skilled in the art.
[0040] The terminology used in the present application is for the purpose of describing particular embodiments only and is not intended to be limiting of the present application. As used herein, the singular forms "a", "an" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be further understood that the terms "comprises" and / or "comprising," when used in this specification, specify the presence of stated features, integers, steps, operations, elements, and / or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.
[0041] It is to be understood that the singular forms "a", "an", and "the" include plural referents unless the context clearly dictates otherwise. It is to be further understood that the terms "comprise", "comprising", "comprises", "including", "includes" or "contain" or "containing" when used in this specification, specify the presence of stated features, integers, steps, operations, elements, or components but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, or groups thereof.
[0042] The embodiments of the present application provide an image edge detection method, which can improve the efficiency and accuracy of image edge labeling.
[0043] The technical solutions of the embodiments of the present application are described in detail below with reference to the drawings.
[0044] Figure 1 is a flow diagram of an image edge detection method shown in the embodiments of the present application.
[0045] Referring to Figure 1 An image edge detection method comprises the following steps.
[0046] In step 110, the first set distance of each pixel point in the labeled image to the background region of the labeled image is calculated.
[0047] In an embodiment, the images of the training set are correctly labeled to obtain the labeled image (Ground Truth) of the image. The distance of each pixel point in the labeled image to the pixel point of the nearest background region of the labeled image is calculated, which is the first set distance of each pixel point in the labeled image to the background region of the labeled image.
[0048] In step 120, the second set distance of each pixel point in the labeled image to the target region of the labeled image is calculated.
[0049] In an embodiment, the distance of each pixel point in the labeled image to the pixel point of the nearest target region of the labeled image can be calculated, which is the second set distance of each pixel point in the labeled image to the target region of the labeled image.
[0050] In step 130, the third set distance of each pixel point in the labeled image is obtained according to the first set distance and the second set distance of each pixel point in the labeled image, respectively.
[0051] In an embodiment, the third set distance of the same pixel point in the labeled image can be obtained according to the first set distance and the second set distance of the same pixel point in the labeled image by using a set algorithm; the third set distance of each pixel point in the labeled image can be obtained according to the first set distance and the second set distance of each pixel point in the labeled image by using a set algorithm, respectively.
[0052] In step 140, the edge pixel points of the background region and the target region are determined according to the third set distance of each pixel point in the labeled image, and the edge of the background region and the target region is generated from the edge pixel points.
[0053] In an embodiment, according to the third set distance of each pixel point in the labeled image, the pixel points whose third set distance reaches a set distance threshold value can be determined as non-edge pixel points, and other pixel points can be determined as edge pixel points, and the edge of the background region and the target region is generated from the edge pixel points.
[0054] The image edge detection method shown in the embodiments of the present application determines the edge pixel points of the background region and the target region according to the third set distance of each pixel point in the labeled image, and generates the edges of the background region and the target region from the edge pixel points; the edges of the labeled image are determined through the third set distance of each pixel point in the labeled image, so that the accuracy of the edge detection of the labeled image reaches the pixel level, the edge pixel points of the labeled image can be accurately detected, and the efficiency and accuracy of the image edge labeling can be improved.
[0055] Figure 2 FIG. 2 is another flowchart of the image edge detection method shown in the embodiments of the present application. Figure 2 Compared with the prior art Figure 1 The scheme of the present application is described in more detail.
[0056] Referring to Figure 2 An image edge detection method comprises the following steps:
[0057] In step 210, the pixel value of the background region of the labeled image is set to a first set value, and the pixel value of the target region is set to a second set value.
[0058] In an embodiment, the images in the training set are correctly labeled by using an image labeling tool to obtain a labeled image (Ground Truth) of correct labeling data. The pixel value of the background region of the labeled image is set to a first set value, and the pixel value of the target region is set to a second set value.
[0059] In step 220, the first set distance of each pixel point in the labeled image from the background region is calculated according to the first set value of the background region and the second set value of the target region.
[0060] In an embodiment, according to the different pixel values of the background region and the target region of the labeled image, a calculation tool is used to calculate the shortest distance of each pixel point in the labeled image from the nearest pixel point with the first set value, and the shortest distance of each pixel point is the first set distance of each pixel point in the labeled image from the background region.
[0061] In a specific embodiment, according to the labeled image of the image, the background region and the target region of the labeled image are determined. The pixel value of each pixel point in the background region is set to 1, and the pixel value of each pixel point in the target region is set to 0; a calculation tool is used to calculate the shortest distance of each pixel point in the labeled image from the nearest pixel point with the pixel value of 1, and the shortest distance of each pixel point is the first set distance of each pixel point in the labeled image from the background region, and the first set distance of each pixel point in the labeled image forms a first distance matrix A.
[0062] In step 230, the pixel value of the target region is set to a first set value, and the pixel value of the background region is set to a second set value.
[0063] In step 240, according to the first set value of the target region and the second set value of the background region, the second set distance of each pixel point in the marked image to the target region is calculated.
[0064] In an embodiment, according to the different pixel values of the background region and the target region of the marked image, a calculation tool is used to calculate the shortest distance of each pixel point in the marked image to the nearest pixel point with the first set value, and the shortest distance of each pixel point is the second set distance of each pixel point in the marked image to the target region.
[0065] In a specific embodiment, the pixel value of each pixel point of the target region is set to 1, and the pixel value of each pixel point of the background region is set to 0; a calculation tool is used to calculate the shortest distance of each pixel point in the marked image to the nearest pixel point with the first set value, and the shortest distance of each pixel point is the second set distance of each pixel point in the marked image to the target region, and the second set distance of each pixel point in the marked image forms a second distance matrix B.
[0066] In step 250, the first set distance and the second set distance of each pixel point in the marked image are added respectively to obtain the third set distance of each pixel point in the marked image.
[0067] In an embodiment, the first set distance of each pixel point in the first distance matrix A and the second set distance of each pixel point in the second distance matrix B are added respectively to obtain the third set distance of each pixel point, and the third set distance of each pixel point forms a third distance matrix C.
[0068] In step 260, the pixel point with a third set distance less than or equal to a set distance threshold value is determined as an edge pixel point of the background region and the target region, and the edge of the background region and the target region is generated from the edge pixel point.
[0069] In a specific embodiment, the corresponding pixel point with a third set distance less than or equal to 2 in the third distance matrix C is taken as an edge pixel point of the background region and the target region, and the edge of the marked image is obtained according to the edge pixel point.
[0070] For example, the image has pixels M1, M2, M3, M4 and M5, the pixels M1, M2 and M3 are pixels of the background region, and the pixels M4 and M5 are pixels of the target region. The pixel values of the pixels M1, M2 and M3 of the background region are set to 1, and the pixel values of the pixels M4 and M5 of the target region are set to 0. The first set distance of the pixels M1, M2, M3, M4 and M5 from the nearest pixel with a pixel value of 1 is calculated by distance_transform_edt, the first set distance of the pixel M1 from the nearest pixel with a pixel value of 1 is a1, the first set distance of the pixel M2 from the nearest pixel with a pixel value of 1 is a2, the first set distance of the pixel M3 from the nearest pixel with a pixel value of 1 is a3, the first set distance of the pixel M4 from the nearest pixel with a pixel value of 1 is a4, and the first set distance of the pixel M5 from the nearest pixel with a pixel value of 1 is a5. The first distance matrix A is composed of a1, a2, a3, a4 and a5, for example, [a1, a2, a3, a4, a5]. The pixel values of the pixels M1, M2 and M3 of the background region are set to 0, and the pixel values of the pixels M4 and M5 of the target region are set to 1. The second set distance of the pixels M1, M2, M3, M4 and M5 from the nearest pixel with a pixel value of 1 is calculated by distance_transform_edt, the second set distance of the pixel M1 from the nearest pixel with a pixel value of 1 is b1, the second set distance of the pixel M2 from the nearest pixel with a pixel value of 1 is b2, the second set distance of the pixel M3 from the nearest pixel with a pixel value of 1 is b3, the second set distance of the pixel M4 from the nearest pixel with a pixel value of 1 is b4, and the second set distance of the pixel M5 from the nearest pixel with a pixel value of 1 is b5. The second distance matrix B is composed of b1, b2, b3, b4 and b5, for example, [b1, b2, b3, b4, b5]. The third set distance c1 of the pixel M1 is obtained by adding a1 and b1, the third set distance c2 of the pixel M2 is obtained by adding a2 and b2, the third set distance c3 of the pixel M3 is obtained by adding a3 and b3, the third set distance c4 of the pixel M4 is obtained by adding a4 and b4, and the third set distance c5 of the pixel M5 is obtained by adding a5 and b5. The third distance matrix C is composed of the third set distances c1, c2, c3, c4 and c5, for example, [c1, c2, c3, c4, c5]. The pixel value of the pixel with a third set distance less than or equal to 2 in the third distance matrix C [c1, c2, c3, c4, c5] is set to 1, and the pixel with a pixel value of 1 is the edge pixel point of the background region and the target region. The edge of the image is obtained according to the edge pixel point.
[0071] It should be noted that the units of the first set distance, the second set distance, the third set distance, and the set distance threshold are the same.
[0072] Corresponding to the foregoing application function implementation method embodiments, the application further provides an image edge detection device, an electronic device, and corresponding embodiments.
[0073] Figure 3 is a structural schematic diagram of an image edge detection device according to an embodiment of the application.
[0074] Referring to Figure 3 An image edge detection device includes a first calculation module 301, a second calculation module 302, a distance processing module 303, and a determination module 304.
[0075] The first calculation module 301 is configured to calculate a first set distance between each pixel point in a labeled image and a background region of the labeled image.
[0076] The second calculation module 302 is configured to calculate a second set distance between each pixel point in the labeled image and a target region of the labeled image.
[0077] The distance processing module 303 is configured to obtain a third set distance of each pixel point in the labeled image according to the first set distance of each pixel point in the labeled image calculated by the first calculation module 301 and the second set distance of each pixel point in the labeled image calculated by the second calculation module 302.
[0078] The determination module 304 is configured to determine an edge pixel point of the background region and the target region according to the third set distance of each pixel point in the labeled image obtained by the distance processing module 303, and generate an edge of the background region and the target region from the edge pixel point.
[0079] In an embodiment, the first calculation module 301 is further configured to set a pixel value of the background region of the labeled image to a first set value, set a pixel value of the target region to a second set value, and calculate the first set distance between each pixel point in the labeled image and the background region according to the first set value of the background region and the second set value of the target region.
[0080] In an embodiment, the second calculation module 302 is further configured to set the pixel value of the target region to the first set value, set the pixel value of the background region to the second set value, and calculate the second set distance between each pixel point in the labeled image and the target region according to the first set value of the target region and the second set value of the background region.
[0081] In an embodiment, the distance processing module 303 is further configured to add the first set distance of each pixel point in the labeled image calculated by the first calculation module 301 and the second set distance calculated by the second calculation module, to obtain a third set distance of each pixel point in the labeled image.
[0082] In an embodiment, the determination module 304 is further configured to determine, according to the third set distance of each pixel point in the labeled image obtained by the distance processing module 303, a pixel point with a third set distance less than or equal to a set distance threshold as an edge pixel point of the background region and the target region, and generate an edge of the background region and the target region from the edge pixel point.
[0083] The technical solution of the present application determines the edge pixel point of the background region and the target region according to the third set distance of each pixel point in the labeled image, and generates the edge of the background region and the target region from the edge pixel point. The edge of the labeled image is determined through the third set distance of each pixel point in the labeled image, so that the accuracy of edge detection of the labeled image reaches the pixel level, the edge pixel point of the labeled image can be accurately detected, and the efficiency and accuracy of image edge labeling can be improved.
[0084] As to the apparatus in the above-mentioned embodiments, the specific manners in which various modules perform operations have been described in detail in the embodiments of the method, and thus will not be described in detail here.
[0085] Figure 4 FIG. 1 is a structural schematic diagram of an electronic device according to an embodiment of the present application.
[0086] Referring to FIG. 1, Figure 4 The electronic device 400 includes a memory 401 and a processor 402.
[0087] The processor 402 can be a central processing unit (CPU), and can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor.
[0088] The memory 401 can include various types of storage units, such as a system memory, a read-only memory (ROM), and a permanent storage device. Among them, the ROM can store static data or instructions required by the processor 402 or other modules of the computer. The permanent storage device can be a read-write storage device. The permanent storage device can be a non-volatile storage device that does not lose stored instructions and data even after the computer is powered off. In some embodiments, the permanent storage device uses a mass storage device (such as a magnetic or optical disk, a flash memory) as a permanent storage device. In some other embodiments, the permanent storage device can be a removable storage device (such as a floppy disk, an optical drive). The system memory can be a read-write storage device or a volatile read-write storage device, such as a dynamic random access memory. The system memory can store some or all of the instructions and data required by the processor during runtime. In addition, the memory 401 can include a combination of any computer readable storage media, including various types of semiconductor storage chips (such as DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), magnetic disks and / or optical disks. In some embodiments, the memory 401 can include a read and / or write removable storage device, such as a compact disc (CD), a read-only digital versatile disc (such as DVD-ROM, double-layer DVD-ROM), a read-only Blu-ray disc, an ultra-density optical disc, a flash memory card (such as an SD card, a min SD card, a Micro-SD card, etc.), a magnetic floppy disk, etc. The computer readable storage medium does not include a carrier wave and an instantaneous electronic signal transmitted by wireless or wired transmission.
[0089] The memory 401 stores executable code, which, when processed by the processor 402, can cause the processor 402 to perform part or all of the above-mentioned methods.
[0090] In addition, the method according to the present application can also be implemented as a computer program or computer program product, which includes computer program code instructions for executing part or all of the steps of the above-mentioned methods of the present application.
[0091] Alternatively, the present application can also be implemented as a computer readable storage medium (or non-transitory machine readable storage medium or machine readable storage medium) having executable code (or computer program or computer instruction code) stored thereon, which, when executed by a processor of an electronic device (or server, etc.), causes the processor to execute part or all of the steps of the above-mentioned methods according to the present application.
[0092] Having described various embodiments of the application, it is to be understood that the above description is meant not to limit and not to encompass all of the possible embodiments. Many modifications and variations of this application can be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. It is intended that the scope of the application be defined by the scope of the patent and equivalents thereof.
Claims
1. An image edge detection method, characterized in that, include: Calculate a first predetermined distance between each pixel in the labeled image and the background region of the labeled image, and construct a first predetermined distance matrix of the labeled image based on the first predetermined distance; Calculate a second predetermined distance between each pixel in the labeled image and the target region of the labeled image, and construct a second predetermined distance matrix of the labeled image based on the second predetermined distance; The method involves obtaining a third predetermined distance for each pixel in the labeled image based on the first predetermined distance and the second predetermined distance, respectively, including: adding the first predetermined distance and the second predetermined distance for each pixel in the labeled image to obtain the third predetermined distance for each pixel in the labeled image; A third set distance matrix of the labeled image is constructed based on the third set distance of each pixel in the labeled image, and the pixels in the third set distance matrix whose third set distance is less than or equal to a set distance threshold are determined as edge pixels of the background region and the target region, and the edge of the background region and the target region is generated by the edge pixels.
2. The method according to claim 1, characterized in that, The calculation of the first predetermined distance between each pixel in the labeled image and the background region of the labeled image includes: Set the pixel values of the background region of the labeled image to a first preset value and the pixel values of the target region to a second preset value; Based on the first set value of the background region and the second set value of the target region, the first set distance between each pixel in the labeled image and the background region is calculated.
3. The method according to claim 2, characterized in that, The calculation of the second predetermined distance between each pixel in the labeled image and the target region of the labeled image includes: Set the pixel value of the target area to the first preset value and the pixel value of the background area to the second preset value; Based on the first set value of the target region and the second set value of the background region, the second set distance between each pixel in the labeled image and the target region is calculated.
4. An image edge detection device, characterized in that, include: The first calculation module is used to calculate a first predetermined distance between each pixel in the labeled image and the background region of the labeled image, and to construct a first predetermined distance matrix of the labeled image based on the first predetermined distance; The second calculation module is used to calculate a second predetermined distance between each pixel in the labeled image and the target region of the labeled image, and to construct a second predetermined distance matrix of the labeled image based on the second predetermined distance; A distance processing module is used to obtain a third set distance for each pixel in the labeled image based on a first set distance calculated by the first calculation module and a second set distance calculated by the second calculation module. The third set distance for each pixel in the labeled image is obtained by adding the first set distance and the second set distance for each pixel in the labeled image. The determination module is used to construct a third set distance matrix of the labeled image based on the third set distance of each pixel in the labeled image obtained by the distance processing module, and to determine the pixels in the third set distance matrix whose third set distance is less than or equal to a set distance threshold as edge pixels of the background region and the target region, and to generate the edge of the background region and the target region from the edge pixels.
5. The apparatus according to claim 4, characterized in that: The first calculation module is further configured to set the pixel value of the background region of the labeled image to a first set value and the pixel value of the target region to a second set value; and to calculate the first set distance between each pixel in the labeled image and the background region based on the first set value of the background region and the second set value of the target region.
6. The apparatus according to claim 5, characterized in that: The second calculation module is further configured to set the pixel value of the target region to the first preset value and the pixel value of the background region to the second preset value; and to calculate the second preset distance between each pixel in the labeled image and the target region based on the first preset value of the target region and the second preset value of the background region.
7. An electronic device, characterized in that, include: processor; as well as A memory having executable code stored thereon, which, when executed by the processor, causes the processor to perform the method as described in any one of claims 1-3.
8. A computer-readable storage medium, characterized in that, It stores executable code that, when executed by a processor of an electronic device, causes the processor to perform the method as described in any one of claims 1-3.