Corrosion operator acceleration method, system and electronic equipment
Composite operators are composed of dynamic range compression and convolution to perform image corrosion operations, which solves the problem of CPU resources occupied by image corrosion operations, improves calculation speed and applicability, and reduces equipment complexity and cost.
Patent Information
- Application Number
- CN202410976911.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-22
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2044-07-22
AI Technical Summary
Image corrosion operations occupy more CPU resources, resulting in reduced CPU usage and increased device complexity. Devices without hardware circuits or processors need to rely on the CPU for image corrosion, which affects the user experience.
A mapping table based on dynamic range compression is used to convert the original image into a preprocessed image, and perform a convolution operation with the structural elements. A composite operator is formed through dynamic range compression and convolution to perform the image erosion operation, reducing CPU resource usage and improving operation speed.
The calculation speed of image corrosion operations is improved, CPU resource usage is reduced, equipment complexity and cost are reduced, and the applicability and user experience of corrosion operations are increased.
Smart Images

Figure CN118505519B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to an acceleration method, system and electronic device for a corrosion operator. Background Art
[0002] Image erosion is a morphological operation in digital image processing, which is used to remove small objects in an image, eliminate pixels at boundary points, disconnect weakly connected objects, etc. Image erosion can be applied to many fields of image processing and computer vision, such as object detection, feature extraction, edge detection, etc.
[0003] When performing image erosion, the image data can be loaded into memory, and then the CPU (Central Processing Unit) computing power is used to execute the erosion algorithm. The erosion algorithm may involve performing neighborhood operations on each pixel in the image data, checking the specific conditions of its neighboring pixels, and updating the value of the pixel accordingly. However, the erosion operation involves a large amount of pixel-level calculations, which takes up more CPU resources and affects CPU usage.
[0004] Therefore, in order to improve the above-mentioned problem of occupying more CPU resources, a specific hardware circuit or processor can also be designed to perform the image corrosion operation, such as based on FPGA (Field Programmable Gate Array), ASIC (Application-Specific Integrated Circuit) or other types of hardware accelerators. However, designing hardware circuits or processors will increase the complexity and cost of electronic devices, such as increasing the area of the chip, and electronic devices that are not equipped with the above-mentioned hardware circuits or processors still need to use more CPU resources to perform image corrosion, resulting in increased limitations of image corrosion. Summary of the invention
[0005] The present application provides a method, system and electronic device for accelerating an erosion operator to solve the problem of high limitations of hardware in executing image erosion operations.
[0006] In a first aspect, some embodiments of the present application provide a method for accelerating a corrosion operator, comprising the following steps:
[0007] Acquire an original image, wherein the pixel value of the original image is a first value or a second value, the first value is equal to the background pixel value, and the second value is greater than the background pixel value;
[0008] The original image is converted based on a mapping table for dynamic range compression to output a preprocessed image; the mapping table includes an input value and a mapping value corresponding to the input value, the mapping value is the second value when the input value is the first value, and the mapping value is the first value when the input value is the second value;
[0009] Calculating a convolution result of the preprocessed image and a structure element, where the structure element is a matrix including at least two elements, and element values of the elements are the first value or the second value;
[0010] The convolution result is converted according to the mapping table to output a target image.
[0011] In some embodiments of the present application, converting the original image based on the mapping table for dynamic range compression includes: setting the mapping table for dynamic range compression; setting the mapping value of the first value to the second value in the mapping table, and setting the mapping value of the second value to the first value; detecting the first pixel value of the original image; marking the first pixel value as the input value; and querying the mapping value corresponding to the input value according to the mapping table to output the preprocessed image.
[0012] In some embodiments of the present application, the background pixel value is 0, and querying the mapping value corresponding to the input value according to the mapping table includes: traversing the first pixel value of the original image; if the first pixel value is the first value, setting the second pixel value of the preprocessed image to the second value, and the pixel point coordinates of the first pixel value and the second pixel value are associated; if the first pixel value is the second value, setting the second pixel value of the preprocessed image to the first value.
[0013] In some embodiments of the present application, calculating the convolution result of the preprocessed image and the structural element includes: detecting the origin of the structural element; traversing the second pixel value of the preprocessed image with the origin as the starting point; calculating the product of the structural element and the target pixel value, the target pixel value being the second pixel value of the pixel point covered by the structural element; calculating the sum of the products to generate the convolution result of the preprocessed image and the structural element.
[0014] In some embodiments of the present application, the structure element is a matrix including at least 3 rows and 3 columns of elements, and the structure element includes at least an element whose element value is equal to the second value.
[0015] In some embodiments of the present application, the structural elements include elements whose element values are equal to the first value and elements whose element values are equal to the second value, and the elements whose element values are equal to the second value include elements in the 2nd row, elements in the 1st row and 2nd column, and elements in the 3rd row and 2nd column in the element matrix; the elements whose element values are equal to the first value include elements in the 1st row and 1st column, elements in the 1st row and 3rd column, elements in the 3rd row and 1st column, and elements in the 3rd row and 3rd column in the element matrix.
[0016] In some embodiments of the present application, converting the convolution result according to the mapping table includes: obtaining the mapping table for the dynamic range compression; if the convolution result is the first value, setting the third pixel value of the target image to the second value, and the third pixel value is associated with the pixel point coordinates of the second pixel value in the preprocessed image; if the convolution result is the second value, setting the third pixel value of the target image to the first value.
[0017] In a second aspect, some embodiments of the present application further provide an acceleration system for a corrosion operator, which can be used to execute the acceleration method for the corrosion operator provided in the first aspect, wherein the acceleration system includes an input module, a dynamic range compression module, a convolution module, and an output module, wherein:
[0018] An input module is configured to obtain an original image, wherein a pixel value of the original image is a first value or a second value, wherein the first value is equal to a background pixel value, and the second value is greater than the background pixel value;
[0019] a dynamic range compression module, configured to convert the original image based on a mapping table for dynamic range compression to output a preprocessed image; the mapping table includes an input value and a mapping value corresponding to the input value, the mapping value being the second value when the input value is the first value, and the mapping value being the first value when the input value is the second value;
[0020] a convolution module configured to calculate a convolution result of the preprocessed image and a structure element, wherein the structure element is a matrix including at least two elements, and an element value of the element is the first value or the second value;
[0021] An output module is configured to convert the convolution result according to the mapping table to output a target image.
[0022] In some embodiments of the present application, the dynamic range compression module performs conversion of the original image based on a mapping table for dynamic range compression, and is configured to: set the mapping table for dynamic range compression; set the mapping value of the first value to the second value in the mapping table, and set the mapping value of the second value to the first value; detect the pixel value of the original image; mark the pixel value as the input value; and query the mapping value corresponding to the input value according to the mapping table to output the preprocessed image.
[0023] In a third aspect, some embodiments of the present application further provide an electronic device, comprising a processor, a memory and a bus. The processor and the memory are communicatively connected via the bus; the memory stores computer program instructions executable by the processor, and the processor is configured to execute the following program steps:
[0024] Acquire an original image, wherein the pixel value of the original image is a first value or a second value, the first value is equal to the background pixel value, and the second value is greater than the background pixel value;
[0025] The original image is converted based on a mapping table for dynamic range compression to output a preprocessed image; the mapping table includes an input value and a mapping value corresponding to the input value, the mapping value is the second value when the input value is the first value, and the mapping value is the first value when the input value is the second value;
[0026] Calculating a convolution result of the preprocessed image and a structure element, where the structure element is a matrix including at least two elements, and element values of the elements are the first value or the second value;
[0027] The convolution result is converted according to the mapping table to output a target image.
[0028] It can be seen from the above technical solutions that some embodiments of the present application provide an acceleration method, system and electronic device for the corrosion operator. The method can convert the original image into a preprocessed image based on a mapping table of dynamic range compression, wherein the mapping table includes an input value and a mapping value corresponding to the input value, and when the input value is a first value, the mapping value is a second value, and when the input value is a second value, the mapping value is a first value, the first value is a background pixel value, and the second value is a non-background pixel value. Then, the convolution result of the preprocessed image and the preset structural element is calculated, and the convolution result is converted into a target image according to the mapping table of dynamic range compression to complete the corrosion operation on the original image. The method performs the corrosion operation of image corrosion by a composite operator composed of dynamic range compression and convolution, which can improve the calculation speed of the corrosion operation. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0030] Figure 1 A schematic diagram of an NPU architecture provided for some embodiments of the present application;
[0031] Figure 2 A schematic diagram of a process flow of a corrosion operator acceleration method provided in some embodiments of the present application;
[0032] Figure 3 A schematic diagram of the principle of DRC conversion provided in some embodiments of the present application;
[0033] Figure 4 A schematic diagram of a structural element provided for some embodiments of the present application;
[0034] Figure 5 A schematic diagram of another structural element provided for some embodiments of the present application;
[0035] Figure 6 A schematic diagram of the principle of calculating convolution results provided in some embodiments of the present application;
[0036] Figure 7 A schematic diagram of a convolution result calculation process provided in some embodiments of the present application;
[0037] Figure 8 A schematic diagram of another convolution result calculation process provided in some embodiments of the present application;
[0038] Fig. 9 An example diagram of a corrosion operator acceleration method provided in some embodiments of the present application;
[0039] Fig.10 A schematic diagram of the structure of a corrosion operator acceleration system provided in some embodiments of the present application;
[0040] Fig.11 A schematic diagram of the structure of an electronic device provided for some embodiments of the present application. DETAILED DESCRIPTION
[0041] In order to make the purpose, technical solutions and advantages of the exemplary embodiments of the present application clearer, the technical solutions in the exemplary embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the exemplary embodiments of the present application. Obviously, the described exemplary embodiments are only part of the embodiments of the present application, not all of the embodiments.
[0042] Based on the exemplary embodiments shown in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application. In addition, although the disclosure in this application is introduced according to one or several exemplary examples, it should be understood that each aspect of these disclosures can also constitute a complete technical solution separately.
[0043] It should be understood that the terms "first", "second", "third", etc. in the specification and the above-mentioned drawings of this application are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, for example, they can be implemented according to an order other than those given in the diagrams or descriptions of the embodiments of this application.
[0044] In addition, the terms "include" and "have" and any variations thereof are intended to cover but not exclude inclusion, for example, a product or device comprising a list of components is not necessarily limited to those components expressly listed but may include other components not expressly listed or inherent to such products or devices.
[0045] Image erosion is a morphological operation in digital image processing, which is used to remove small objects in images, eliminate pixels at boundary points, disconnect objects with weak connections, etc. It can be applied to many fields of image processing and computer vision, such as object detection, feature extraction, edge detection, etc.
[0046] As for software, in some embodiments, the image data of the original image can be loaded into the memory, and then the erosion algorithm can be executed through the computing power of the CPU. Among them, the erosion algorithm can include performing neighborhood operations on each pixel in the image data, checking the specific conditions of its neighboring pixels, and updating the value of the pixel accordingly. However, since the erosion operation of the erosion algorithm involves a large amount of pixel-level calculations, it will occupy more CPU resources, affecting the CPU usage and computing speed.
[0047] In order to improve the CPU resource usage problem in software, in some embodiments, a specific hardware circuit or processor can also be designed to perform the image corrosion operation, such as based on FPGA (Field Programmable Gate Array), ASIC (Application-Specific Integrated Circuit) or other types of hardware accelerators.
[0048] However, designing hardware circuits or processors will increase the complexity and cost of electronic devices, such as increasing the area of the chip, and electronic devices that are not equipped with the above-mentioned hardware circuits or processors still need to use the computing power of the CPU to perform image corrosion, which increases the limitations of image corrosion and affects the user experience.
[0049] To this end, some embodiments of the present application provide an acceleration method for a corrosion operator, which can implement the corrosion operation of image corrosion based on NPU hardware (Neural Processing Unit) without occupying more CPU resources to perform the corrosion operation and without the need to additionally design specific hardware circuits or processors. It can be applied to a variety of scenarios while improving the calculation speed of the corrosion operation, thereby increasing the applicability of the corrosion operation and improving the user experience.
[0050] like Figure 1 As shown, in some embodiments, the NPU may include multiple EU working units, each EU is responsible for different calculations, and each EU can perform calculations in parallel. Figure 1 In the DMA, DMA (Direct Memory Access) is responsible for data movement between the main memory such as RAM, and can read or write data directly from the main memory without CPU intervention, such as DMA-EU, DMA-EU is a specific version and identifier of DMA. DMA can be used to perform DMA read and write, indicating that DMA supports the function of reading and writing data from external storage; CCM (Color Correction Module) is used to adjust or optimize the color of the image; YUV format is a color encoding method, where Y represents the brightness component, and U and V represent the chrominance components; affine (affine transformation) is a two-dimensional coordinate transformation that can maintain the flatness of the image and is used for operations such as scaling, rotation, and translation.
[0051] Tesseract engine-EU is a module used to perform computing tasks. It can be used to perform DMA reading and writing, which means that DMA supports the functions of reading and writing data from external storage; tensor addition / subtraction / multiplication / division, which means basic mathematical operations on tensors such as multidimensional arrays; tensor transport, which is a mechanism for transmitting tensor data within the NPU or between other devices.
[0052] CV (Computer Vision) is used to handle computer vision-related tasks, such as image recognition, object detection, etc. CV-EU is a specific version and logo of CV. CV can be used to perform blend (color mixing); wrap is a boundary processing or data packaging technology used to handle edge cases of images or data; remap is used to rearrange or transform images or data.
[0053] Com (Communication) is responsible for the communication and data exchange between NPU and external devices or systems. Com-EU is a specific version and identifier of Com. Com can be used to perform conv1×1 and convN×M. Convolution operations are different forms of convolution operations. 1×1 convolution can be used to adjust the number of channels or the depth of feature maps, and N×M convolution can be used to extract features in space. Affine is a two-dimensional coordinate transformation that maintains the flatness of the image and is used for operations such as scaling, rotation, and translation.
[0054] The sync manager is a component used to ensure data synchronization and coordination between various modules within the NPU.
[0055] based on Figure 1 In the NPU architecture shown, in some embodiments, multiple EU working units can be configured inside the NPU, and each EU is responsible for different calculations, and each EU can calculate in parallel. In addition, each EU has the ability to independently read and write DDR and OCM (On-Chip Memory). For complex combinatorial operator calculations, multiple EU units need to be used in combination, and OCM can be used as a cache for intermediate data, where OCM has high bandwidth and low latency characteristics. When EUs calculate in parallel, there will be calculation timing and data dependencies, so a sync manager is needed to control the calculation timing of the EU.
[0056] It should be noted that Figure 1 The NPU architecture diagram shown exemplarily shows the various modules and functions inside the NPU, as well as the data flow and communication paths between the modules, but is not intended to limit them. The NPU may include more or fewer other modules or components.
[0057] In some embodiments, the acceleration method can form a composite operator through Conv (convolution) and DRC (Dynamic Range Compression) provided by the NPU hardware, and use the combined operator as a hardware implementation of the corrosion operation to improve the computing speed of the corrosion operation.
[0058] like Figure 2 As shown, the acceleration method of the corrosion operator provided in some embodiments of the present application may include the following steps:
[0059] S201: Acquire an original image.
[0060] When performing image corrosion, it is necessary to first obtain the original image used for the corrosion operation, that is, to obtain the image data of the original image. The original image is composed of a plurality of pixels, and each pixel is set with a corresponding pixel value. For the convenience of distinction, in some embodiments of the present application, the pixel value of each pixel in the original image is represented as a first pixel value. The first pixel value can be a first value or a second value, the first value is equal to the background pixel value, such as 0; the second value is greater than the background pixel value, such as 1, etc. That is, the pixel value of the original image is the above-mentioned first value or second value.
[0061] To facilitate image erosion, in some embodiments, the original image is a binary image, that is, an image that only includes the first value and the second value, the first value and the second value are both fixed values, the first value is 0, and the second value is 1, that is, the pixel value of the binary image is 0 or 1. Alternatively, in some implementations, when the original image is not a binary image, a binarization process can be performed on the original image first to convert it into a binary image.
[0062] For ease of explanation, the following embodiments of the present application are described by taking the original image as a binary image, the first value as 0, and the second value as a non-zero value as an example, but this is not intended to be limiting. In the specific implementation process, the above-mentioned image and pixel values may also be other values.
[0063] S202: Convert the original image based on a mapping table for dynamic range compression to output a preprocessed image.
[0064] After the original image is acquired, the original image can be converted based on the DRC, wherein the DRC is provided with a mapping table, the mapping table includes an input value and a mapping value corresponding to the input value, when the input value is a first value, the mapping value is a second value, and when the input value is a second value, the mapping value is a first value.
[0065] In some embodiments, when converting the original image based on the DRC mapping table, a mapping table for dynamic range compression is set. In the mapping table, the mapping value of the first value is set to the second value, and the mapping value of the second value is set to the first value. Then, the first pixel value of the original image is detected and marked as the input value. Then, the mapping value corresponding to the input value is queried according to the mapping table to output the preprocessed image.
[0066] For example, if the mapping value is G(x), the relationship between the input value and the mapping value recorded in the mapping table is as follows:
[0067]
[0068] In some embodiments, when querying the mapping value corresponding to the input value, the first pixel value of the original image is also traversed. If the first pixel value is the first value, the second pixel value of the preprocessed image is set to the second value; and if the first pixel value is the second value, the second pixel value of the preprocessed image is set to the first value. The pixel point coordinates of the first pixel value and the second pixel value are associated.
[0069] That is, if the pixel value of the current pixel point in the original image is 0, DRC converts the pixel value of the current pixel point to 1; if the pixel value of the current speed limit point in the original image is not 0, DRC converts the pixel value of the current pixel point to 0 to generate a converted pre-processed image. At this time, the relationship between the pixels in the pre-processed image and the original image is the opposite. For example, Figure 3 As shown, after the original image X is converted through the DRC mapping table, the output Figure 3 The preprocessed image X1 is shown.
[0070] S203: Calculate the convolution result of the preprocessed image and the structural element.
[0071] After the original image is converted into the inverse preprocessed image through the DRC mapping table, the convolution result of the preprocessed image and the preset structure element can be calculated. The structure element is a matrix including at least two elements, the element value of the element is the first value or the second value, and the structure element is used to consider the neighborhood of the current pixel.
[0072] In some embodiments, the convolution kernel of the structure element may use an S kernel. That is, the structure element is a matrix including at least 3 rows and 3 columns of elements, and the structure element includes at least an element whose element value is equal to the second value. For example, the structure element may be Figure 4 The 3×3 matrix shown in Figure 2 is a 3×3 matrix; alternatively, the structural element can be Figure 5 The 3×3 matrix shown. Figure 4 The matrix shown has the advantage of simplicity. Figure 5 The cross-shaped kernel matrix shown has the advantage of high accuracy.
[0073] To improve the accuracy of the corrosion operation, in some embodiments, the structural elements may include elements whose element values are equal to the first value and elements whose element values are equal to the second value, and the elements whose element values are equal to the second value include elements in the 2nd row, the 1st row and the 2nd column, and the 3rd row and the 2nd column in the element matrix; the elements whose element values are equal to the first value include elements in the 1st row and the 1st column, the 1st row and the 3rd column, the 3rd row and the 1st column, and the 3rd row and the 3rd column in the element matrix. For example, Figure 5 The 3×3 matrix of the cross-shaped kernel is shown.
[0074] It should be noted that the rows and columns, number of elements and element values of the above-mentioned structural elements are only some exemplary schemes and are not intended to be limiting. In the embodiments of the present application, the structural elements may also use matrices in other forms.
[0075] like Figure 6 As shown, in some embodiments, when calculating the convolution result of the preprocessed image and the structural element, the origin of the structural element is detected, or it can be represented as a center point element, such as the element located at the 2nd row and the 2nd column in a 3×3 matrix. Taking the origin as the starting point, traverse the second pixel value of the preprocessed image, that is, the pixel value corresponding to each pixel in the preprocessed image. Then calculate the product of the structural element and the target pixel value. Among them, the target pixel value is the second pixel value of the pixel covered by the structural element. Then, calculate the sum of the products to generate the convolution result of the preprocessed image and the structural element.
[0076] The following two examples illustrate the process of calculating the convolution structure.
[0077] See also Figure 7-Figure 8 , first use DRC to convert the original image X. Among them, DRC sets the mapping table, 0 mapping output 1, other mapping output 0. The pre-processed image X1 is output through the conversion of the DRC mapping table. Then the convolution of the pre-processed image X1 and the structure element S is calculated by the CONV hardware. That is, the structure element is multiplied by its covered pixels and then summed, and the sum result is 0 or a value greater than 0.
[0078] like Figure 7 As shown in the figure, the pixel values of the corresponding pixel points are multiplied, and each product is equal to 0. The convolution result obtained by summing is also 0, which means that the structural element S is multiplied by the pixels covered by X1, and the value is 0. Since X1 and X are inversely related, it can be determined that the structural element S is multiplied by the pixels covered by X, and all pixel values are non-zero.
[0079] like Figure 8 As shown, the pixel values of the corresponding pixels are multiplied, and there are two product results of 1, and the convolution result of the sum is 2. If the convolution result is greater than 0, it means that the pixel value of at least one pixel point is not 0 when the structure element S is multiplied by the pixels covered by X1. Since X1 and X are inversely related, it can be determined that at least one of the pixels covered by X is 0 when the structure element S is multiplied by the pixels covered by X.
[0080] According to the above-mentioned situation where the convolution result is 0 or non-0, according to the reciprocal relationship between the original image and the preprocessed image, and the image corrosion principle, when the convolution result is 0, the pixel value of the current pixel should be set to 1; if the convolution result is non-0, the pixel value of the current pixel is set to 0.
[0081] S204: Convert the convolution result according to the mapping table to output a target image.
[0082] In order to accurately output the target image obtained after the corrosion operation on the original image, after the convolution result is calculated, based on the reciprocal relationship between the original image and the preprocessed image and the corrosion principle of image corrosion, the convolution result is converted through the DRC mapping table to output the corresponding target image.
[0083] That is, Figure 7-Figure 8 In the convolution result calculation process shown in the figure, after the CONV hardware calculates the convolution of the image X1 and the structure element S, a DRC is connected. Through the mapping relationship set by the DRC, input 0 corresponds to output 1, and other values correspond to output 0, thus realizing the corrosion operation of the original image.
[0084] In some embodiments, when converting the convolution result according to the mapping table, a mapping table for dynamic range compression is obtained. If the convolution result is the first value, the third pixel value of the target image is set to the second value; and if the convolution result is the second value, the third pixel value of the target image is set to the first value. The third pixel value is associated with the pixel point coordinates of the second pixel value in the preprocessed image, that is, the pixel value after the corrosion operation is performed on the corresponding pixel point position according to the mapping table output.
[0085] For example, Fig. 9 This is an example diagram of a corrosion operator acceleration method. Fig. 9 The mapping table for DRC settings in is:
[0086]
[0087] The original image is the binary image X, the preprocessed image is X1, the calculated convolution result is conv, and the target image is Y.
[0088] Based on the above-mentioned acceleration method of the corrosion operator, some embodiments of the present application also provide an acceleration system of the corrosion operator, which can be used to execute the acceleration method of the corrosion operator provided in the above-mentioned embodiment. Fig.10 As shown, the acceleration system may include an input module 100, a dynamic compression module 200, a convolution module 300 and an output module 400, wherein:
[0089] An input module 100 is configured to obtain an original image, wherein a pixel value of the original image is a first value or a second value, wherein the first value is equal to a background pixel value, and the second value is greater than the background pixel value;
[0090] A dynamic range compression module 200 is configured to convert the original image based on a mapping table for dynamic range compression to output a preprocessed image; the mapping table includes an input value and a mapping value corresponding to the input value, when the input value is the first value, the mapping value is the second value, and when the input value is the second value, the mapping value is the first value;
[0091] A convolution module 300 is configured to calculate a convolution result of the preprocessed image and a structure element, wherein the structure element is a matrix including at least two elements, and an element value of the element is the first value or the second value;
[0092] The output module 400 is configured to convert the convolution result according to the mapping table to output a target image.
[0093] Based on the acceleration method of the erosion operator described above, some embodiments of the present application further provide an electronic device 500, comprising the acceleration system of the erosion operator described in the above embodiments.
[0094] In some embodiments, Fig.11 As shown, the electronic device 500 includes: at least one processor 501, at least one communication interface 502, at least one memory 503 and at least one bus 504. Among them, the bus 504 is used to realize the direct connection and communication of these components, the communication interface 502 is used to communicate signaling or data with other node devices, and the memory 503 stores computer program instructions that can be executed by the processor 501. When the electronic device 500 is running, the processor 501 communicates with the memory 503 through the bus 504, the processor 501 can call the computer program stored in the memory 503, and the execution of the computer program can realize the acceleration method of the corrosion operator provided in the embodiment of the present application.
[0095] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
[0096] For the convenience of explanation, the above description has been made in conjunction with specific embodiments. However, the above exemplary discussion is not intended to be exhaustive or limit the embodiments to the specific forms disclosed above. Based on the above teachings, various modifications and variations can be obtained. The selection and description of the above embodiments are to better explain the principles and practical applications, so that those skilled in the art can better use the embodiments and various different variations of the embodiments suitable for specific use considerations.
Claims
1. A method for accelerating a corrosion operator, characterized in that: include: Acquire an original image, wherein the pixel value of the original image is a first value or a second value, the first value is equal to the background pixel value, and the second value is greater than the background pixel value; Detecting a first pixel value of the original image; marking the first pixel value as an input value; Querying a mapping value corresponding to the input value according to a mapping table of a dynamic compression range to output a preprocessed image; The mapping table includes an input value and a mapping value corresponding to the input value, wherein when the input value is the first value, the mapping value is the second value, and when the input value is the second value, the mapping value is the first value; Calculate, based on the NPU, a convolution result of the preprocessed image and a structure element, where the structure element is a matrix including at least two elements, and an element value of the element is the first value or the second value; The convolution result is converted according to the mapping table to output a target image.
2. The acceleration method of the corrosion operator according to claim 1, characterized in that: Also includes: Setting a mapping table for the dynamic range compression; In the mapping table, a mapping value of the first value is set to the second value, and a mapping value of the second value is set to the first value.
3. The acceleration method of the corrosion operator according to claim 2, characterized in that: The background pixel value is 0, and querying the mapping value corresponding to the input value according to the mapping table includes: Traversing the first pixel value of the original image; If the first pixel value is the first value, setting the second pixel value of the preprocessed image to the second value, the pixel point coordinates of the first pixel value and the second pixel value are associated; If the first pixel value is the second value, the second pixel value of the preprocessed image is set to the first value.
4. The acceleration method of the corrosion operator according to claim 1, characterized in that: The calculating the convolution result of the preprocessed image and the structural element comprises: detecting an origin of the structural element; Taking the origin as a starting point, traversing the second pixel value of the preprocessed image; Calculate the product of the structure element and a target pixel value, where the target pixel value is a second pixel value of a pixel point covered by the structure element; A sum of the products is calculated to generate a convolution result of the preprocessed image and the structure element.
5. The acceleration method of the corrosion operator according to claim 1, characterized in that: The structure element is a matrix including at least 3 rows and 3 columns of elements, and the structure element includes at least an element whose element value is equal to the second value.
6. The acceleration method of the erosion operator according to claim 5, characterized in that: The structural elements include elements whose element values are equal to the first value and elements whose element values are equal to the second value, and the elements whose element values are equal to the second value include elements in the 2nd row, elements in the 1st row and 2nd column, and elements in the 3rd row and 2nd column in the element matrix; the elements whose element values are equal to the first value include elements in the 1st row and 1st column, elements in the 1st row and 3rd column, elements in the 3rd row and 1st column, and elements in the 3rd row and 3rd column in the element matrix.
7. The acceleration method of the erosion operator according to claim 1, characterized in that: The converting the convolution result according to the mapping table comprises: Obtaining a mapping table for the dynamic range compression; If the convolution result is the first value, setting the third pixel value of the target image to the second value, and associating the third pixel value with the pixel point coordinates of the second pixel value in the preprocessed image; If the convolution result is the second value, the third pixel value of the target image is set to the first value.
8. An acceleration system for a corrosion operator, characterized in that: include: An input module is configured to obtain an original image, wherein a pixel value of the original image is a first value or a second value, wherein the first value is equal to a background pixel value, and the second value is greater than the background pixel value; A dynamic range compression module, configured to detect a first pixel value of the original image; marking the first pixel value as an input value; Querying a mapping value corresponding to the input value according to a mapping table of a dynamic compression range to output a preprocessed image; The mapping table includes an input value and a mapping value corresponding to the input value, wherein when the input value is the first value, the mapping value is the second value, and when the input value is the second value, the mapping value is the first value; a convolution module, configured to calculate a convolution result of the preprocessed image and a structure element based on the NPU, wherein the structure element is a matrix including at least two elements, and an element value of the element is the first value or the second value; An output module is configured to convert the convolution result according to the mapping table to output a target image.
9. The acceleration system of the corrosion operator according to claim 8, characterized in that: The dynamic range compression module is further configured to: Setting a mapping table for the dynamic range compression; In the mapping table, a mapping value of the first value is set to the second value, and a mapping value of the second value is set to the first value.
10. An electronic device, characterized in that: Includes processor, memory and bus; The processor and the memory are communicatively connected via the bus; The memory stores computer program instructions executable by the processor, the processor being configured to: Acquire an original image, wherein the pixel value of the original image is a first value or a second value, the first value is equal to the background pixel value, and the second value is greater than the background pixel value; Detecting a first pixel value of the original image; marking the first pixel value as an input value; Querying a mapping value corresponding to the input value according to a mapping table of a dynamic compression range to output a preprocessed image; The mapping table includes an input value and a mapping value corresponding to the input value, wherein when the input value is the first value, the mapping value is the second value, and when the input value is the second value, the mapping value is the first value; Calculate, based on the NPU, a convolution result of the preprocessed image and a structure element, where the structure element is a matrix including at least two elements, and an element value of the element is the first value or the second value; The convolution result is converted according to the mapping table to output a target image.
Citation Information
Patent Citations
Microalgae automatic counting method based on digital image processing
CN103955937A
Distortionless black edge drawing method based on expansion corrosion algorithm
CN115601472A
Water conservancy target identification method and system, electronic equipment and medium
CN115965861A
Image detection method and device and electronic equipment
CN116917954A
Apparatus for high speed morphological processing
US5781667A
