Image processing method and device, equipment, storage medium and program product

By selecting an appropriate sorting algorithm according to the image mask size and the memory requirements of the sorting algorithm, the adaptive adjustment of the median filter on the GPU is realized, solving the problem of low GPU memory utilization in the existing technology, improving the processing speed and filter effect.

CN118570071APending Publication Date: 2024-08-30MOORE THREADS TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410658604.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-24
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

The existing median filter algorithm cannot be adaptively adjusted in the GPU, and fails to effectively utilize the GPU memory structure, resulting in low processing speed and efficiency.

Method used

By determining the mask size of the image and the memory requirements of different sorting algorithms, an appropriate sorting algorithm is selected for median filtering to achieve adaptive adjustment of image filtering and maximize GPU memory utilization.

Benefits of technology

The processing speed and filtering effect of median filtering are improved, the memory usage during image filtering is taken into account, and the memory access delay is reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118570071A
    Figure CN118570071A
Patent Text Reader

Abstract

The embodiment of the invention discloses an image processing method and device, equipment, a storage medium and a program product, and the method comprises the steps: determining a mask corresponding to a to-be-processed first image; determining a sorting algorithm corresponding to the mask based on the size of the mask and the memory requirements of the mask under different sorting algorithms; the sorting algorithm is used for sorting arrays in the image during single median filtering; and performing median filtering on the first image based on the mask and the sorting algorithm to obtain a second image. Thus, different sorting algorithms are adopted for filtering for masks of different sizes, the filtering processing rate and the filtering effect can be improved, and self-adaptive adjustment of filtering is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to, but is not limited to, the field of computer vision technology, and in particular to an image processing method, apparatus, device, storage medium, and program product. Background Art

[0002] Digital images are often interfered by noise during sampling and transmission. Therefore, image filtering is proposed to preprocess digital images to retain image details and remove noise to the greatest extent.

[0003] Median filtering is a typical nonlinear filtering method. When the noise is shot noise, the filtering effect is very significant. Median filtering is a filtering method based on sorting statistics theory. Its basic idea is to sort the grayscale values ​​of all pixels in the domain window centered on a certain pixel and select the middle value as the grayscale value of the central pixel.

[0004] The median filtering algorithm used in the existing solution is relatively simple and cannot achieve adaptive adjustment of the median filtering algorithm. Summary of the invention

[0005] In view of this, the embodiments of the present disclosure at least provide an image processing method, apparatus, device, storage medium and program product.

[0006] The technical solution of the embodiment of the present disclosure is implemented as follows:

[0007] On the one hand, an embodiment of the present disclosure provides an image processing method, which includes: determining a mask corresponding to a first image to be processed; determining a sorting algorithm corresponding to the mask based on the size of the mask and the memory requirement of the mask under different sorting algorithms; the sorting algorithm is used to sort an array in an image during a single median filtering; and performing a median filter on the first image based on the mask and the sorting algorithm to obtain a second image.

[0008] In some embodiments, determining the sorting algorithm corresponding to the mask based on the size of the mask and the memory requirements of the mask under different sorting algorithms includes: determining a first resource possessed by a computer device used for image filtering; determining a resource difference based on the size of the mask and the first resource; the resource difference being the difference between the resources required for median filtering the first image and the resources possessed by the computer device; determining the sorting algorithm corresponding to the mask based on the resource difference, preset resource conditions, and the memory requirements of the mask under different sorting algorithms.

[0009] In some embodiments, determining the resource difference based on the size of the mask and the first resource includes: determining the second resource required for median filtering the first image based on the size of the mask; and determining the resource difference based on the first resource and the second resource.

[0010] In some embodiments, the determining of the sorting algorithm corresponding to the mask based on the resource difference, the preset resource condition and the memory requirements of the mask under different sorting algorithms includes: when the resource difference satisfies the resource condition, using the first sorting algorithm as the sorting algorithm corresponding to the mask; when the resource difference does not satisfy the resource condition and the memory requirement of the mask under the second sorting algorithm is lower than the memory requirement under the first sorting algorithm, using the second sorting algorithm as the sorting algorithm corresponding to the mask; the first sorting algorithm has fewer branches during processing than the second sorting algorithm.

[0011] In some embodiments, when the resource difference does not meet the resource condition and the memory requirement of the mask under the second sorting algorithm is lower than the memory requirement under the first sorting algorithm, the second sorting algorithm is used as the sorting algorithm corresponding to the mask, including: when the resource difference does not meet the resource condition, the memory requirement of the mask under the third sorting algorithm is lower than the memory requirement under the fourth sorting algorithm, and the size of the mask meets the preset size condition, the third sorting algorithm is used as the sorting algorithm corresponding to the mask; when the resource difference does not meet the resource condition and the size of the mask does not meet the size condition, the fourth sorting algorithm is used as the sorting algorithm corresponding to the mask; the processing efficiency of the third sorting algorithm is better than that of the fourth sorting algorithm; the second sorting algorithm includes the third sorting algorithm and the fourth sorting algorithm.

[0012] In some embodiments, the median filtering of the first image based on the mask and the sorting algorithm to obtain the second image includes: when the sorting algorithm is the first sorting algorithm, determining the first memory space required by the first sorting algorithm for a single median filtering; the first memory space includes a private space corresponding to the first sorting algorithm for a single median filtering; and, on the first memory space, median filtering of the first image based on the mask and the first sorting algorithm to obtain the second image.

[0013] In some embodiments, determining the first memory space required by the first sorting algorithm for a single median filtering includes: determining a first number of registers required by the first sorting algorithm for a single median filtering based on the size of the mask; and determining a first number of registers as the first memory space from the resources of a computer device used for image filtering.

[0014] In some embodiments, performing median filtering on the first image based on the mask and the first sorting algorithm in the first memory space to obtain the second image includes: extracting a target array for a single median filter from the first image; transferring the target array from the second memory space to the first memory space; the second memory space includes space on a memory component; and performing median filtering on the target array based on the mask and the first sorting algorithm in the first memory space to obtain the second image.

[0015] In some embodiments, the median filtering of the first image based on the mask and the sorting algorithm to obtain the second image includes: when the sorting algorithm is a third sorting algorithm, determining the third memory space required for a single median filtering of the third sorting algorithm; the third memory space includes a private space corresponding to the third sorting algorithm in a single median filtering; and, on the third memory space, median filtering of the first image based on the mask and the third sorting algorithm to obtain the second image.

[0016] In some embodiments, determining the third memory space required by the third sorting algorithm for a single median filtering includes: determining the size of the sliding window based on the size of the mask; determining the second number of registers required by the third sorting algorithm for a single filtering process based on the size of the sliding window; and determining a second number of registers as the third memory space from the resources of a computer device used for image filtering.

[0017] In some embodiments, determining the size of the sliding window based on the size of the mask includes: determining a preset first threshold and a second threshold; performing a first operation on the length and width of the size of the mask to obtain a first value; performing a second operation on the first value and the first threshold to obtain a second value; performing a third operation on the second value and the second threshold to obtain the size of the sliding window.

[0018] In some embodiments, performing median filtering on the first image based on the mask and the third sorting algorithm in the third memory space to obtain the second image includes: performing median filtering on the first image based on the mask, the third sorting algorithm and the sliding window in the third memory space to obtain the second image.

[0019] In some embodiments, the median filtering of the first image based on the mask and the sorting algorithm to obtain the second image includes: when the sorting algorithm is a fourth sorting algorithm, median filtering of the first image based on the mask and the fourth sorting algorithm on a second memory space of a computer device used for image filtering to obtain the second image; the second memory space includes space on a memory component.

[0020] In some embodiments, the target data type is used for memory access between the first memory space, the second memory space, and the third memory space of the computer device.

[0021] On the other hand, an embodiment of the present disclosure provides an image processing device, which includes: a determination module, configured to determine a mask corresponding to a first image to be processed; the determination module is also configured to determine a sorting algorithm corresponding to the mask based on the size of the mask and the memory requirement of the mask under different sorting algorithms; the sorting algorithm is used to sort an array in an image during a single median filtering; and a filtering module, configured to perform a median filter on the first image based on the mask and the sorting algorithm to obtain a second image.

[0022] On the other hand, an embodiment of the present disclosure provides a computer device, including a memory and a processor, wherein the memory stores a computer program executable on the processor, and the processor implements some or all of the steps in the above method when executing the program.

[0023] On the other hand, an embodiment of the present disclosure provides a computer-readable storage medium having a computer program stored thereon, which implements part or all of the steps in the above method when executed by a processor.

[0024] On the other hand, an embodiment of the present disclosure provides a computer program, including computer-readable codes. When the computer-readable codes are executed in a computer device, a processor in the computer device executes some or all of the steps for implementing the above method.

[0025] On the other hand, an embodiment of the present disclosure provides a computer program product, including a computer program or instructions, which implement the steps in the above method when executed by a processor.

[0026] In the disclosed embodiment, the corresponding sorting algorithm is determined by the size of the mask of the first image and the memory requirements of the mask under different sorting algorithms, and the mask of the first image and its corresponding sorting algorithm are used to perform median filtering on the first image; in this way, different sorting algorithms are used for filtering for masks of different sizes, so that adaptive adjustment of image filtering can be achieved, and the processing rate and filtering effect of filtering can be improved. In addition, when determining the sorting algorithm for image filtering of the first image, the mask size and its memory requirements under different sorting algorithms are comprehensively considered; in this way, the memory during image filtering is taken into account to maximize the utilization of GPU memory.

[0027] It should be understood that the above general description and the following detailed description are merely exemplary and explanatory, and are not intended to limit the technical solutions of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and are used to illustrate the technical solutions of the present disclosure together with the specification.

[0029] Figure 1 A schematic diagram of an implementation flow of a median filtering method provided in an embodiment of the present disclosure;

[0030] Figure 2 A schematic diagram of an implementation process of an image processing method provided in an embodiment of the present disclosure Figure 1 ;

[0031] Figure 3 A schematic diagram of an implementation process of an image processing method provided in an embodiment of the present disclosure Figure 2 ;

[0032] Figure 4 A schematic diagram of the implementation flow of bitonal sorting in an image processing method provided in an embodiment of the present disclosure;

[0033] Figure 5 Schematic diagram of the implementation process of sliding window + forgetful sorting in an image processing method provided in an embodiment of the present disclosure Figure 1 ;

[0034] Figure 6 Schematic diagram of the implementation process of sliding window + forgetful sorting in an image processing method provided in an embodiment of the present disclosure Figure 2 ;

[0035] Figure 7 A schematic diagram of an implementation process of an image processing method provided in an embodiment of the present disclosure Figure 3 ;

[0036] Figure 8A schematic diagram of the structure of an image processing device provided by an embodiment of the present disclosure;

[0037] Fig. 9 A hardware entity schematic diagram of a computer device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0038] In order to make the purpose, technical solutions and advantages of the present disclosure clearer, the technical solutions of the present disclosure are further elaborated in detail below in conjunction with the drawings and embodiments. The described embodiments should not be regarded as limiting the present disclosure. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present disclosure.

[0039] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.

[0040] The terms "first / second / third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It is understandable that "first / second / third" can be interchanged with a specific order or sequence where permitted so that the embodiments of the present disclosure described herein can be implemented in an order other than that illustrated or described herein.

[0041] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which the present disclosure belongs. The terms used herein are only for the purpose of describing the present disclosure and are not intended to limit the present disclosure.

[0042] In order to better understand the image processing method provided by the embodiment of the present disclosure, the solution in the related art is first described below.

[0043] Median filtering is a nonlinear signal processing technology based on sorting statistics theory that can effectively suppress noise. It replaces the value of a point in a digital image or digital sequence with the median of all points in a neighborhood of that point, making the surrounding pixel values ​​close to the true value, thereby eliminating isolated noise points.

[0044] like Figure 1 As shown in the figure, the domain window is 3*3, and the grayscale values ​​of all pixels in the neighborhood window where the pixel A with a grayscale value of 15 is located are taken out to obtain a sequence 10: {15,6,7,8,9,16,13,14,5}; then, the sequence 10 is sorted to obtain a sequence 11: {5,6,7,8,9,13,14,15,16}, and then the median 9 is determined; the median 9 is used as the grayscale value of the pixel A to implement a median filtering.

[0045] There are many fast median filtering algorithms based on different sorting, such as the fast median filtering algorithm using sliding windows. This algorithm uses sliding windows to reduce data access and uses odd median sorting to sort the 5x5 sliding window to get the median. However, in GPUs, the use of sliding windows is more limited due to the characteristics of single instruction multiple threads (SIMT), and sorting in GPUs needs to consider the use of different levels of memory, reduce branches, bank contention, etc., resulting in many sorting algorithms being unable to adapt to use in GPUs.

[0046] The odd median sort of the above algorithm assumes a size of 7x7 in the GPU, which requires the use of more than 49 registers, which will reduce the number of activated warps and thus fail to cover up latency. In addition, the above algorithm does not consider how to reduce branching to improve instruction parallelism. A warp is a collection of multiple threads, for example, a warp can be a collection of 32 threads. Activating a warp means activating threads in one or more warps to process tasks.

[0047] In the GPU, the best situation is that all threads in a warp enter the same branch and execute an instruction, but the above algorithm is not optimized for this aspect. If each thread in the warp executes a different branch and the branches are of different lengths, the branch with a faster processing rate will always wait for the branch with a slower processing rate, causing a lot of latency. In short, the existing median filtering solutions for images are not optimized for GPUs and are only applicable to CPUs.

[0048] The above algorithm has the following problems: 1) It is impossible to achieve adaptive adjustment of the median filter algorithm; 2) The algorithm is not optimized for the GPU memory structure to ensure maximum utilization of registers and shared memory, and less use of global memory, thereby reducing memory access latency; 3) Branch optimization is not performed to ensure that the same branch is taken within the warp. If it is not possible to ensure that each thread in the warp is on the same branch, then try to ensure that the branch length is consistent.

[0049] To this end, the present disclosure provides an image processing method, which can be executed by a processor of a computer device. The computer device may refer to a server, a laptop, a tablet computer, a desktop computer, a smart TV, a set-top box, a mobile device (such as a mobile phone, a portable video player, a personal digital assistant, a dedicated messaging device, a portable gaming device), or other device with data processing capabilities. Figure 2As shown, the image processing method includes the following steps 201 to 203:

[0050] Step 201: Determine a mask corresponding to a first image to be processed.

[0051] The first image is an image to be processed currently. In a feasible implementation, the first image may refer to one or more digital images; the image types of the digital images may include but are not limited to: dynamic images, color images, vector images, and bitmap images.

[0052] In some embodiments, if the first images are images of the same type, such as the first images are multiple frames of images in a video, a mask for uniformly filtering the multiple frames of images can be pre-set, that is, a uniform mask is set for first images of the same type.

[0053] In some embodiments, if the first image is an image of a different type, such as the first image is photos of multiple different sizes, different masks can be set for different photos, that is, different masks are set for different types of first images, which can improve the filtering effect of each image.

[0054] Step 202: Determine a sorting algorithm corresponding to the mask based on the size of the mask and the memory requirements of the mask under different sorting algorithms.

[0055] The sorting algorithm is used to sort the array in the image during single median filtering.

[0056] The size of the mask can reflect the size of the neighborhood window during filtering, the computational complexity of filtering, the hardware resources required for filtering, and the final filtering effect. The memory requirements of the mask under different sorting algorithms are different. For example, a mask of size 7*7 requires 49 registers under the median sorting algorithm, but only 25 registers under the forgetful sorting algorithm.

[0057] In some implementations, a comprehensive analysis may be performed on the size of the mask and the memory requirements of the mask under different sorting algorithms to determine the sorting algorithm with the best implementation effect corresponding to the mask.

[0058] During implementation, the correspondence between masks of different sizes and sorting algorithms can be pre-set, and the correspondence can reflect the memory requirements of the masks under different sorting algorithms; thus, the sorting algorithm corresponding to the mask of the first image can be determined from the correspondence according to the mask size of the first image.

[0059] In a feasible implementation, masks of each size and their memory requirements under different sorting algorithms can be stored in correspondence to obtain the correspondence between masks of different sizes and sorting algorithms. Thus, from the correspondence, a correspondence matching the mask size of the first image is searched, and the memory requirements in the matching correspondence are analyzed to obtain the sorting algorithm corresponding to the mask of the first image.

[0060] In a feasible implementation method, the sorting algorithm with the best implementation effect corresponding to each size of the mask can be determined based on the memory requirements of each size of the mask under different sorting algorithms; the mask of each size and its corresponding sorting algorithm with the best implementation effect are stored in the form of a key-value pair to obtain the correspondence between masks of different sizes and the sorting algorithms; thus, from the correspondence, the key-value pair that matches the mask size of the first image is found, and the sorting algorithm in the key-value pair is used as the sorting algorithm corresponding to the mask of the first image.

[0061] Specifically, the mask of each size is used as the key information item, and the sorting algorithm corresponding to the mask of each size is used as the value information item to obtain multiple key-value pairs (corresponding relationships); in this way, the mask size of the first image is used as the matching basis, and the key-value pairs whose mask size in the key information item is the same as the mask size of the first image are determined from the multiple key-value pairs, and the sorting algorithm stored in the value information item in the key-value pair is used as the sorting algorithm corresponding to the mask of the first image.

[0062] Step 203: Perform median filtering on the first image based on the mask and the sorting algorithm to obtain a second image.

[0063] The second image is an image obtained by performing median filtering on the first image. Performing median filtering on the first image actually performs median filtering on each pixel in the first image.

[0064] In some embodiments, the specific implementation method of step 203 may be: taking each pixel point in the first image as the midpoint in turn, and constructing a neighborhood window of each pixel point based on the mask of the first image; taking out the grayscale value of each pixel point in the neighborhood window of each pixel point to obtain a first data sequence; using the sorting algorithm of the first image to sort the first data sequence to obtain the median of the grayscale values ​​of each pixel point in the neighborhood window of each pixel point; and using the median as the grayscale value of each pixel point.

[0065] In a feasible implementation method, the specific implementation method of "taking each pixel point in the first image as the midpoint in turn, and constructing a neighborhood window of each pixel point based on the mask of the first image" can be: for any pixel point B in the first image, take pixel point B as the midpoint, and construct a neighborhood window whose size matches the mask size of the first image as the neighborhood window of pixel point B.

[0066] For example, if the mask size of the first image is 3*3, then for pixel point B, pixel point B is taken as the midpoint, and a neighborhood window with a size of 3*3 is constructed as the neighborhood window of pixel point B.

[0067] In a feasible implementation, if the number of pixels in the neighborhood window of pixel point B is not equal to the number of pixels that the mask size of the first image should have, then the first pixel point can be used to fill the pixels in the neighborhood window of pixel point B.

[0068] The first pixel point may be a pixel point with a grayscale value of a maximum grayscale value, or a pixel point with a grayscale value of a minimum grayscale value; the minimum grayscale value may be 0, and the maximum grayscale value may be 255. The first pixel point is used to fill the pixels in the neighborhood window of the pixel point B, so that the pixels in the neighborhood window can match the mask size, so that the median of the grayscale value can be obtained by only writing a median determination logic.

[0069] In a feasible implementation, the specific implementation of "taking out the grayscale values ​​of each pixel in the neighborhood window of each pixel to obtain the first data sequence" may be: taking out the grayscale values ​​of each pixel in the neighborhood window of each pixel in a preset order to obtain the first data sequence. The preset order may be a random order, or an order of top to bottom, left to right, or Figure 1 The order shown is to take the middle first and then the edge.

[0070] It should be noted that performing median filtering on the first image can be regarded as an image processing task or a filtering task, and the filtering task can correspond to one or more wraps; performing median filtering on each pixel in the first image can be regarded as a thread.

[0071] In the disclosed embodiment, the corresponding sorting algorithm is determined by the size of the mask of the first image and the memory requirements of the mask under different sorting algorithms, and the mask of the first image and its corresponding sorting algorithm are used to perform median filtering on the first image; in this way, different sorting algorithms are used for filtering for masks of different sizes, so that adaptive adjustment of image filtering can be achieved, and the processing rate and filtering effect of filtering can be improved. In addition, when determining the sorting algorithm for image filtering of the first image, the mask size and its memory requirements under different sorting algorithms are comprehensively considered; in this way, the memory during image filtering is taken into account to maximize the utilization of GPU memory.

[0072] The present disclosure provides an image processing method, which can be executed by a processor of a computer device. Figure 3 As shown, the method includes the following steps 301 to 305:

[0073] Step 301: Determine a mask corresponding to a first image to be processed.

[0074] Here, the above step 301 corresponds to the above step 201, and the specific implementation of the above step 201 may be referred to during implementation.

[0075] Step 302: Determine a first resource of a computer device for performing image filtering.

[0076] The computer device is a device for executing the image processing method of the present disclosure. The first resource is various resources on the computer device. In a feasible implementation, the first resource may include but is not limited to: the number of registers, convolution kernels, memory space size, memory bandwidth, and the number of activated warps.

[0077] In some implementations, the first resource possessed by the computer device may be determined by third-party software such as Core Temp or AIDA64.

[0078] In some implementations, the first resource of the computer device may be determined through a command built into the computer device.

[0079] Step 303: Determine a resource difference based on the size of the mask and the first resource.

[0080] The resource difference is the difference between the resources required for median filtering the first image and the resources possessed by the computer device. The resource difference can reflect whether the computer device has sufficient resources to perform median filtering on the first image.

[0081] In some implementations, step 303 may be specifically implemented by: determining the second resource required for median filtering the first image based on the size of the mask; and determining the resource difference based on the first resource and the second resource.

[0082] The second resource is a resource required for performing median filtering on the first image.

[0083] In a feasible implementation, if the main resource of the median filter is a register, then a first register of the computer device can be used as the first resource, a second register required for median filtering the first image can be determined based on the size of the mask, the second register can be used as the second resource, and the resource difference between the first resource and the second resource can be determined. In this case, the difference between the number of the first registers and the number of the second registers can be used as the resource difference.

[0084] In a feasible implementation, if the main resources of the median filter include not only registers but also memory space, then the registers and memory space of the computer device can be used as the first resource, and the registers and memory space required for median filtering the first image can be used as the second resource to determine the resource difference between the first resource and the second resource. In this case, the resource difference includes not only the difference in the number of registers but also the difference in memory space.

[0085] It should be noted that the present disclosure only uses the resource difference as the difference in the number of registers and / or the difference in memory space as an example for explanation. Of course, the resource difference may also include other resources such as the difference in memory bandwidth and the difference in the number of activated warps. As long as these resources are the resources required for median filtering of the image, the embodiments of the present disclosure are not limited to this.

[0086] Step 304: Determine a sorting algorithm corresponding to the mask based on the resource difference, a preset resource condition, and memory requirements of the mask under different sorting algorithms.

[0087] Resource conditions are used to determine which sorting algorithm should be selected under current resources to achieve the best processing rate and filtering effect.

[0088] In some embodiments, the specific implementation method of step 304 may be: when the resource difference meets the resource condition, the first sorting algorithm is used as the sorting algorithm corresponding to the mask; when the resource difference does not meet the resource condition and the memory requirement of the mask under the second sorting algorithm is lower than the memory requirement under the first sorting algorithm, the second sorting algorithm is used as the sorting algorithm corresponding to the mask; the first sorting algorithm has fewer branches during processing than the second sorting algorithm.

[0089] The resource difference satisfies the resource condition, which means that the resources of the computer device are far greater than the resources required for median filtering the first image, indicating that the resources in the computer device are inexhaustible at this time. The resource difference does not meet the resource condition, including the following two situations: In the first situation, although the resources of the computer device are greater than the resources required for median filtering the first image, it will affect the processing of other tasks (threads), indicating that the resources in the computer device are sufficient but not enough; in the second situation, the resources of the computer device are less than the resources required for median filtering the first image, indicating that the resources in the computer device are not enough at this time.

[0090] The first sorting algorithm is a sorting algorithm with less branching logic during sorting. In a feasible implementation, the first sorting algorithm can be a bitonic sorting. The advantage of bitonic sorting is that the sorting logic of a single time is the same, which can try to ensure that each thread in the warp is on the same branch and the branch length is consistent; and bitonic sorting only branches when comparing sizes, so it is less affected by branches, and can ensure that each thread in the warp executes the same instructions as much as possible, reducing the delay caused by branches, and the time complexity of bitonic sorting is O(n(log2n)^2), so it can improve the processing rate of image filtering. Moreover, the processing logic of comparing sizes in bitonic sorting can be implemented with only one line of code, and the compilation speed is fast.

[0091] The second sorting algorithm is a sorting algorithm that is greatly affected by the number of registers, that is, the second sorting algorithm requires more hardware resources when sorting and is easily affected by the GPU memory structure. In a feasible implementation, since excessive use of registers will result in a very small number of activated warps and the delay cannot be hidden, the impact of branches is not considered at this time, and the impact of hardware resources (GPU memory structure) is mainly considered. Therefore, the second sorting algorithm can be forgetful sorting to improve the image processing speed while calling the least resources. In another feasible implementation, the second sorting algorithm can also be heap sorting.

[0092] It should be noted that since both forgetful sorting and heap sorting involve adding, deleting, and sorting data in a single sort, the branches generated by forgetful sorting and heap sorting are significantly more than those of bitonic sorting.

[0093] In a feasible implementation, the resource condition may be twice or more than twice the second resource. At this time, the resource difference satisfies the resource condition, which means that the first resource is greater than or equal to twice the second resource. In this case, the bitonic sorting (first sorting algorithm) can be used as the sorting algorithm corresponding to the mask of the first image; the resource difference does not meet the resource condition, which means that the first resource is less than twice the second resource. In this case, the forgetful sorting or heap sorting (second sorting algorithm) can be used as the sorting algorithm corresponding to the mask of the first image.

[0094] Further, in some embodiments, the specific implementation method of "when the resource difference does not meet the resource condition, and the memory requirement of the mask under the second sorting algorithm is lower than the memory requirement under the first sorting algorithm, the second sorting algorithm is used as the sorting algorithm corresponding to the mask" can be: when the resource difference does not meet the resource condition, and the memory requirement of the mask under the third sorting algorithm is lower than the memory requirement under the fourth sorting algorithm, and the size of the mask meets the preset size condition, the third sorting algorithm is used as the sorting algorithm corresponding to the mask; when the resource difference does not meet the resource condition, and the size of the mask does not meet the size condition, the fourth sorting algorithm is used as the sorting algorithm corresponding to the mask; the processing efficiency of the first sub-sorting algorithm is better than that of the second sub-sorting algorithm; the second sorting algorithm includes the third sorting algorithm and the fourth sorting algorithm.

[0095] The size condition is used to further determine which sorting algorithm should be selected under the current resources to achieve the best processing rate and filtering effect. The size condition can be preset, and the size condition can be set to a mask size less than or equal to 7*7, or the size condition can be set to a mask size where the product of the length and width is less than 50.

[0096] If the size condition is that the mask size is less than or equal to 7*7, then the resource difference does not meet the resource condition and the mask size meets the preset size condition, indicating that the resources in the computer device are insufficient and the mask size of the first image is less than or equal to 7*7. If the product of the length and width of the mask size is less than 50, then the resource difference does not meet the resource condition and the mask size meets the preset size condition, indicating that the resources in the computer device are insufficient and the product of the length and width of the mask size of the first image is less than 50.

[0097] The third sorting algorithm may be forgetful sorting, and the fourth sorting algorithm may be heap sorting. Since the number of registers required for forgetful sorting during sorting is less than the number of registers required for heap sorting during sorting, forgetful sorting can implement filtering with fewer hardware resources (registers); and since forgetful sorting does not sort all data in a single sorting, the processing efficiency of forgetful sorting is better than that of heap sorting.

[0098] In a feasible implementation, if the resource condition is twice or more than twice the second resource, and the size condition is that the product of the length and width in the mask size is less than 50, then when the resource difference is less than twice the second resource, and the memory requirement of the mask under the third sorting algorithm is lower than the memory requirement under the fourth sorting algorithm, and the product of the length and width in the mask size of the first image is less than 50, forgetful sorting is used as the sorting algorithm corresponding to the first image; when the resource difference is less than twice the second resource, and the product of the length and width in the mask size of the first image is greater than 50, heap sorting is used as the sorting algorithm corresponding to the first image.

[0099] In other embodiments, since the mask size can reflect the hardware resources required when using the mask filter, the judgment condition of the sorting algorithm can be set directly according to the mask size. In a feasible implementation, the first threshold and the second threshold can be set according to the sizes of different masks, and the first threshold is less than the second threshold, and the first threshold and the second threshold are the judgment conditions of the sorting algorithm; in this way, when the mask size of the first image is less than the first threshold, the first sorting algorithm (bitonic sorting) is used as the sorting algorithm corresponding to the mask of the first image; when the mask size of the first image is greater than the first threshold and less than the second threshold, the forgetful sorting (second sorting algorithm) is used as the sorting algorithm corresponding to the mask of the first image; when the mask size of the first image is greater than the second threshold, the heap sorting (third sorting algorithm) is used as the sorting algorithm corresponding to the mask of the first image.

[0100] For example, the first threshold may be a threshold of 16, which is a product of the length and the width, set according to the mask size, and the second threshold may be a threshold of 50, which is a product of the length and the width, set according to the mask size; in this case, when the product of the length and the width of the mask size of the first image is less than 16, bitonal sorting is used as the sorting algorithm corresponding to the mask of the first image; when the product of the length and the width of the mask size of the first image is greater than 16 and less than 50, forgetful sorting is used as the sorting algorithm corresponding to the mask of the first image; when the product of the length and the width of the mask size of the first image is greater than 50, heap sorting is used as the sorting algorithm corresponding to the mask of the first image.

[0101] As another example, the first threshold may be a size threshold of 4*4 set according to the mask size, and the second threshold may be a size threshold of 8*8 set according to the mask size; in this case, when the mask size of the first image is less than 4*4, bitonal sorting is used as the sorting algorithm corresponding to the mask of the first image; when the mask size of the first image is greater than 4*4 and less than 8*8, forgetful sorting is used as the sorting algorithm corresponding to the mask of the first image; when the mask size of the first image is greater than 8*8, heap sorting is used as the sorting algorithm corresponding to the mask of the first image.

[0102] It should be noted that the size of the mask is generally an odd number, so the product of the length and width of the mask size of the first image is less than 16, and the mask size of the first image is less than 4*4, which can all mean that the mask size of the first image is 3*3. The product of the length and width of the mask size of the first image is greater than 16 and less than 50, and the mask size of the first image is greater than 4*4 and less than 8*8, which can all mean that the mask size of the first image is 5*5 or 7*7. The product of the length and width of the mask size of the first image is greater than 50, and the mask size of the first image is greater than 8*8, which can all mean that the mask size of the first image is 9*9 or greater than 9*9.

[0103] Step 305: Perform median filtering on the first image based on the mask and the sorting algorithm to obtain a second image.

[0104] Here, the above step 305 corresponds to the above step 203, and the specific implementation of the above step 203 may be referred to during implementation.

[0105] In some embodiments, when the sorting algorithm is the first sorting algorithm, step 305 may be implemented by the following steps 3051 to 3052:

[0106] Step 3051: when the sorting algorithm is the first sorting algorithm, determine the first memory space required by the first sorting algorithm for single median filtering; the first memory space includes the private space corresponding to the first sorting algorithm for single median filtering.

[0107] Since the first sorting algorithm is aimed at the case where the size of the mask is small and the resources of the computer device are relatively sufficient, the image processing rate can be focused on without optimizing the hardware resources, so the mask of the first image can be directly used to determine the first memory space. The first memory space is the memory space required by the first sorting algorithm when performing median filtering. The first memory space can be a register and / or a shared space.

[0108] In some embodiments, the specific implementation method of step 3051 may be: based on the size of the mask, determining the first number of registers required by the first sorting algorithm for a single median filtering; and determining a first number of registers as the first memory space from the resources of a computer device used for image filtering.

[0109] It should be noted that, since the first number of registers is a separate storage space allocated to the first image, it is also referred to as the private space of the first image. In addition, the median filter is performed on the register to optimize the filter for the memory structure of the graphics processing unit (GPU), so as to maximize the use of registers and use less global memory, thereby reducing memory access latency and improving image processing rate.

[0110] In a feasible implementation, the first number may be determined based on the length and width of the mask size of the first image. For example, if the mask of the first image is 3*3, then the length 3 and the width 3 of the mask of the first image may be multiplied to obtain the first number 9. In this case, 9 registers are used to store the entire array of the first image.

[0111] In a feasible implementation, resources in space may be determined from resources of a computer device, and a first number of registers may be determined from idle resources as a first memory space.

[0112] For example, if the mask of the first image is 3*3, then the first memory space can be the registers required for the mask of 3*3. At this time, the mask size is small, and the array of the first image is saved in the register for median filtering. And the number of registers used in the thread corresponding to the number of activated warps is greater than the number of activated warps corresponding to the shared memory. Because the bitonic function can only be used for 2 n Sort the long array so that mask is larger and not equal to 2 n It will cause a lot of performance waste, so other sorting algorithms will be used when the mask is large.

[0113] Step 3052: In the first memory space, perform median filtering on the first image based on the mask and the first sorting algorithm to obtain the second image.

[0114] In some embodiments, the specific implementation method of "in the first memory space, performing median filtering on the first image based on the mask and the first sorting algorithm to obtain the second image" may be: extracting a target array of a single median filter from the first image; transferring the target array from the second memory space to the first memory space; the second memory space includes space on a memory component; in the first memory space, performing median filtering on the target array based on the mask and the first sorting algorithm to obtain the second image.

[0115] The second memory space may be a memory space on a computer device, for example, a video memory or a global memory.

[0116] The target array refers to all grayscale values ​​within the neighborhood window of any pixel in the first image.

[0117] In a feasible implementation, all grayscale values ​​within the neighborhood window of any pixel point in the first image are used as the target array and transferred from the video memory to the register for filtering. This can maximize the use of the register and minimize the use of global memory, thereby reducing memory access latency and improving image processing rate.

[0118] In a feasible implementation method, the specific implementation method of "performing median filtering on the target array based on the mask and the first sorting algorithm to obtain the second image" can be: taking each pixel in the first image as the midpoint in turn, and constructing a neighborhood window of each pixel based on the mask of the first image; taking out the grayscale values ​​of each pixel in the neighborhood window of each pixel to obtain a first data sequence; using the first sorting algorithm (bitonal sorting) to sort the first data sequence to obtain the median of the grayscale values ​​of each pixel in the neighborhood window of each pixel; and using the median as the grayscale value of each pixel.

[0119] The main idea of ​​bitonal sorting is to convert a random sequence into a bitonal sequence, that is, a sequence that is monotonically increasing or monotonically decreasing, and then sort the bitonal sequence. The bitonal sorting algorithm is mainly divided into two parts. The first part is to convert the unordered sequence into a bitonal sequence; the second part is to divide the sequence into multiple small sequences of equal multiples and compare and sort them until the entire sequence is ordered.

[0120] like Figure 4 As shown, taking an array of 16 elements as an example, the process of bitonal sorting is as follows: 1. Two adjacent elements are merged to form 8 monotonic sequences with opposite monotonicity; 2. Two sequences are merged in pairs to form 4 bitonal sequences, which are sorted by opposite monotonicity; 3. Four monotonic sequences of opposite monotonicity of length 4 are merged two adjacent ones to generate two bitonal sequences of length 8, which are sorted respectively; 4. Two adjacent monotonic sequences of opposite monotonicity of length 8 are merged to generate one bitonal sequence of length 16, which is sorted.

[0121] In some embodiments, when the sorting algorithm is the third sorting algorithm, step 305 may be implemented by the following steps 3053 to 3054:

[0122] Step 3053: When the sorting algorithm is the third sorting algorithm, determine the third memory space required by the third sorting algorithm for single median filtering; the third memory space includes the private space corresponding to the third sorting algorithm for single median filtering.

[0123] Since the third sorting algorithm is aimed at the case where the size of the mask is large and the resources of the computer device are not sufficient, the attention paid to the hardware resources is better than the attention paid to the image processing rate, so the hardware resources need to be optimized at this time, and the optimization here is reflected in the determination method of the third memory space. The third memory space is the memory space required by the third sorting algorithm for a single median filtering.

[0124] In some embodiments, the specific implementation method of step 3053 may be: determining the size of the sliding window based on the size of the mask; determining the second number of registers required for the third sorting algorithm when performing a single filtering process based on the size of the sliding window; and determining a second number of registers as the third memory space from the resources of a computer device used for image filtering.

[0125] The sliding window is used here to significantly reduce the registers required for median filtering to maximize the use of the GPU memory structure.

[0126] In a feasible implementation, the specific implementation of "determining the size of the sliding window based on the size of the mask" can be: determining a preset first threshold and a second threshold; performing a first operation on the length and width of the size of the mask to obtain a first value; performing a second operation on the first value and the first threshold to obtain a second value; performing a third operation on the second value and the second threshold to obtain the size of the sliding window.

[0127] The first threshold and the second threshold are determined according to the filtering effect to be achieved and the degree of optimization of hardware resources. For example, the first threshold can be set to 3 and the second threshold can be set to 2.

[0128] In a feasible implementation, the first operation may be a multiplication operation, the second operation may be an addition operation, and the third operation may be a division operation. In this case, the length and width of the mask size of the first image are multiplied to obtain the first value, the first value and the first threshold 3 are added to obtain the second value, and the second value and the second threshold 2 are divided to obtain the size of the sliding window. The calculation formula for the size of the sliding window may be: ((length*width)+3) / 2. For example, the mask of the first image is 5*5, and the size of the sliding window may be 14.

[0129] In a feasible implementation, the size of the sliding window may be the second number of registers required by the third sorting algorithm when performing a filtering process; that is, if the size of the sliding window may be 14, then the number of registers required at this time is 14.

[0130] In a feasible implementation, resources in space may be determined from resources of the computer device, and a second number of registers may be determined from idle resources as the third memory space.

[0131] Step 3054: In the third memory space, perform median filtering on the first image based on the mask and the third sorting algorithm to obtain the second image.

[0132] In some implementations, step 3054 may be specifically implemented by performing median filtering on the first image based on the mask, the third sorting algorithm, and the sliding window in the third memory space to obtain the second image.

[0133] In a feasible implementation method, the specific implementation method of "performing median filtering on the first image based on the mask, the third sorting algorithm and the sliding window in the third memory space to obtain the second image" can be: taking each pixel in the first image as the midpoint in turn, and constructing a neighborhood window of each pixel based on the mask of the first image; taking out the grayscale value of each pixel in the neighborhood window of each pixel to obtain a first data sequence; sorting the first data sequence using forgetful sorting and a sliding window to obtain the median of the grayscale values ​​of each pixel in the neighborhood window of each pixel; and taking the median as the grayscale value of each pixel.

[0134] In a feasible implementation, the specific implementation of "using forgetful sorting and sliding windows to sort the first data sequence to obtain the median of the grayscale values ​​of each pixel in the neighborhood window of each pixel" can be: determine the second data sequence in the sliding window from the first data sequence; sort the data in the second data sequence to obtain a third data sequence; remove the maximum value and the minimum value in the third data sequence; select a data from the unsorted data and add it to the removed third data sequence, and sort it, remove the maximum value and the minimum value after sorting, and continue to select a data from the unsorted data to sort, and repeat this cycle until all the data in the first data sequence have been sorted.

[0135] It should be noted that the forgetfulness in forgetful sorting refers to removing the maximum and minimum values ​​after a single sort, thereby increasing the image processing rate. The use of sliding windows can reduce the number of registers required and minimize the use of hardware resources. The remaining array in the sliding window is reused after a single sort and removal of the maximum and minimum values, which can further increase the image processing rate.

[0136] like Figure 5 As shown in the figure, taking an array of 9 elements as an example, the process of forgetful sorting is: 1. Sort the 6 elements in the sliding window and remove the maximum and minimum values; 2. Select an element from the three unsorted elements and add it, sort it and remove the maximum and minimum values; 3. Select an element from the two unsorted elements and add it, sort it and remove the maximum and minimum values; 4. Add the unsorted elements, sort it and remove the maximum and minimum values ​​to get the median.

[0137] like Figure 6 As shown in FIG. 1 , when mask = (5,5), the size of the sliding window is 14. The 14 common elements can be sorted first, and then one element is selected from the remaining 6 unsorted elements for sorting, and the maximum value and the minimum value are removed to obtain the final median. Among them, the 14 common elements are shared by the neighborhood window 61 and the neighborhood window 62, and can be reused to further reduce the image processing rate.

[0138] In some embodiments, when the sorting algorithm is the fourth sorting algorithm, the specific implementation method of step 305 may be: when the sorting algorithm is the fourth sorting algorithm, in the second memory space of the computer device used for image filtering, median filtering is performed on the first image based on the mask and the fourth sorting algorithm to obtain the second image; the second memory space includes the space on the memory component.

[0139] The memory component refers to a GPU. The second memory space may be a video memory or a global memory on the GPU.

[0140] Since too many registers are required when the mask size is large, the array of the first image is not placed on the registers, but is stored in the global memory for processing.

[0141] It should be noted that the implementation method of "performing median filtering on the first image based on the mask and the fourth sorting algorithm to obtain the second image" here is similar to the specific implementation method of the above-mentioned step 203. Please refer to the description in the above-mentioned step 203 for details, and the present disclosure will not repeat it here.

[0142] In a feasible implementation, the first memory space, the second memory space, and the third memory space of the computer device use the target data type for memory access; that is, the register, the shared memory, and the global memory use the same target data type for memory access. For example, the target data type may be float4.

[0143] In a feasible implementation, for the shared memory bank (storage unit), you can use bubble insertion to reduce the memory bank (storage space), use #pragma unroll to unroll the loop, and then use performance analysis tools to analyze performance bottlenecks and optimize.

[0144] In the disclosed embodiment, when the mask size is small, bitonic sorting is used for median filtering; when the mask size is large, forgetful sorting is used for median filtering; when the mask size is still large, heap sorting is used for median filtering; in this way, different sorting algorithms are used for different masks, and filtering can be performed in a targeted manner to improve the image filtering effect. In addition, the median filtering of bitonic sorting and forgetful sorting is performed on registers, thereby maximizing the use of registers and shared space, and using less global space, thereby reducing memory access latency. Moreover, the branches of bitonic sorting are smaller, which can ensure that the threads in the warp corresponding to the median filter take the same branch as much as possible, and the length of the branch is consistent; adding a sliding window to forgetful sorting can significantly reduce the registers required for filtering, further improving the image processing rate.

[0145] The following describes the application of the image processing method provided by the embodiment of the present disclosure in a practical scenario, taking median filtering on a GPU as an example.

[0146] The technical problems existing in the related technologies include at least: 1. No optimization is performed on the GPU memory structure to ensure maximum utilization of registers and shared memory, less use of global memory, and thus reduce memory access latency. 2. No branch optimization is performed to ensure that the same branch is taken within a warp as much as possible, and when it is not possible to ensure that each thread within a warp is on the same branch, the branch length is kept consistent as much as possible.

[0147] The technical solution disclosed in the present invention is: dividing the convolution kernel into three kernels according to different mask (mask) = ((mask_width, mask_height)) sizes.

[0148] 1. When the mask is small, that is, (mask_width*mask_height<=16), it is greatly affected by branches. To ensure that the threads in the warp have as few branches as possible, use Figure 4The radix sort is shown in the figure. The advantage of radix sort is that it only generates branches due to judgment, thus ensuring that the same instructions are executed as much as possible in each thread of the warp, reducing the latency caused by branches, and the time complexity of radix sort is O(n(log2n)^2). Because the mask is small, the entire array can be saved in registers, and the number of activated warps corresponding to the number of registers used in the thread is greater than the number of activated warps corresponding to the shared memory. Because the radix function can only sort arrays of 2^n length, there will be a lot of performance waste when the mask is large but not equal to 2^n, so other sorting algorithms will be used when the mask is large.

[0149] 2. When mask = (5,5) or (7,7), the number of registers has a greater impact. For example, when mask = (7,7), the commonly used sorting algorithm requires 49 registers to store the array in the image. At this time, due to the excessive use of registers, the number of activated warps will be very small, and the latency cannot be hidden. In this case, sliding window + forgetful sorting can be used. Figure 5 The forgetful sorting shown can significantly reduce register usage. For example, mask = (5,5) or (7,7) uses 14 and 25 registers respectively. At the same time, a sliding window can be used to reuse the sorting of the middle 4x5 part of the mask, such as Figure 6 As shown, this can maximize the use of the GPU's memory structure.

[0150] 3. Because the above two optimizations already include the three most commonly used masks, mask = (3,3), (5,5) or (7,7), heap sort is used for other uncommon masks, and the array is not stored in registers, but in global memory.

[0151] like Figure 7 As shown, the selection process of the sorting algorithm may include the following steps 701 to 706:

[0152] Step 701: Input the mask size of the image.

[0153] Step 702: Determine whether the product of the length and the width in the mask size is greater than 16.

[0154] If the product of the length and the width in the mask size is less than 16, step 703 is executed; if the product of the length and the width in the mask size is greater than 16, step 704 is executed.

[0155] Step 703: Select bitonal sorting to perform median filtering on the image.

[0156] Step 704: Determine whether the mask size is equal to (5,5) or (7,7).

[0157] If the mask size is equal to (5, 5) or (7, 7), execute step 705; if the mask size is not equal to (5, 5) or (7, 7), execute step 706.

[0158] Step 705: Select forgetful sorting to perform median filtering on the image.

[0159] Step 706: Select heap sorting to perform median filtering on the image.

[0160] In addition to the above improvements to the sorting algorithm, some common convolution kernel accelerations can also be made: for example, 1. Use float4 to access memory between global memory, shared memory, and registers. 2. For the shared memory bank, use bubble insertion to reduce the memory bank, use #pragma unroll loop unrolling, and then use performance analysis tools to analyze performance bottlenecks and optimize.

[0161] Table 1 below includes two APIs: nppiFilterMedian_32fC1R and nppiFilterMedian_32Fc3R. Among them, nppiFilterMedian_32fC1R performs median filtering on a single-channel 32-bit floating-point image; nppiFilterMedian_32Fc3R performs median filtering on a three-channel 32-bit floating-point image. Table 1 includes three masks of size (3,3), (5,5), and (7,7). The image display resolution in Table 1 is 2160 (vertical pixels) × 3840 (horizontal pixels). The results in Table 1 were tested on the S4000 / V100 graphics card.

[0162] Specifically, in Table 1, when nppiFilterMedian_32fC1R and a mask of size (3,3) are used for median filtering, the solution speed on the s4000 graphics card is 183%. When nppiFilterMedian_32Fc3R and a mask of size (3,3) are used for median filtering, the solution speed on the s4000 graphics card is 183%. When nppiFilterMedian_32fC1R and a mask of size (5,5) are used for median filtering, the solution speed on the s4000 graphics card is 1357%. When nppiFilterMedian_32Fc3R and a mask of size (5,5) are used for median filtering, the solution speed on the s4000 graphics card is 1618%. When using nppiFilterMedian_32fC1R and a mask of size (7,7) for median filtering, the solution speed on the s4000 graphics card is 513%. When using nppiFilterMedian_32Fc3R and a mask of size (7,7) for median filtering, the solution speed on the s4000 graphics card is 574%.

[0163]

[0164] Table 1

[0165] Based on the foregoing embodiments, the embodiments of the present disclosure provide an image processing device, which includes the units included and the modules included in the units, which can be implemented by a processor in a computer device; of course, it can also be implemented by a specific logic circuit; in the implementation process, the processor can be a central processing unit (CPU), a microprocessor (MPU), a digital signal processor (DSP) or a field programmable gate array (FPGA), etc.

[0166] Figure 8 A schematic diagram of the structure of an image processing device provided by an embodiment of the present disclosure is shown in FIG. Figure 8 As shown, the image processing device 800 includes: a determination module 810 and a filtering module 820, wherein:

[0167] A determination module 810 is configured to determine a mask corresponding to a first image to be processed;

[0168] The determination module 810 is further configured to determine a sorting algorithm corresponding to the mask based on the size of the mask and the memory requirements of the mask under different sorting algorithms; the sorting algorithm is used to sort the array in the image during a single median filtering;

[0169] The filtering module 820 is configured to perform median filtering on the first image based on the mask and the sorting algorithm to obtain a second image.

[0170] In some embodiments, the determination module 810 is specifically configured to: determine a first resource possessed by a computer device used for image filtering; determine a resource difference based on the size of the mask and the first resource; the resource difference is the difference between the resources required for median filtering of the first image and the resources possessed by the computer device; determine a sorting algorithm corresponding to the mask based on the resource difference, preset resource conditions and memory requirements of the mask under different sorting algorithms.

[0171] In some embodiments, the determination module 810 is specifically configured to: determine the second resource required for median filtering the first image based on the size of the mask; and determine the resource difference based on the first resource and the second resource.

[0172] In some embodiments, the determination module 810 is specifically configured to: determine the sorting algorithm corresponding to the mask based on the resource difference and the preset resource condition, including: when the resource difference meets the resource condition, use the first sorting algorithm as the sorting algorithm corresponding to the mask; when the resource difference does not meet the resource condition and the memory requirement of the mask under the second sorting algorithm is lower than the memory requirement under the first sorting algorithm, use the second sorting algorithm as the sorting algorithm corresponding to the mask; the first sorting algorithm has fewer branches during processing than the second sorting algorithm.

[0173] In some embodiments, the determination module 810 is specifically configured to: when the resource difference does not meet the resource condition, and the memory requirement of the mask under the third sorting algorithm is lower than the memory requirement under the fourth sorting algorithm, and the size of the mask meets the preset size condition, use the third sorting algorithm as the sorting algorithm corresponding to the mask; when the resource difference does not meet the resource condition, and the size of the mask does not meet the size condition, use the fourth sorting algorithm as the sorting algorithm corresponding to the mask; the processing efficiency of the third sorting algorithm is better than that of the fourth sorting algorithm; the second sorting algorithm includes the third sorting algorithm and the fourth sorting algorithm.

[0174] In some embodiments, the filtering module 820 is specifically configured to: when the sorting algorithm is a first sorting algorithm, determine the first memory space required by the first sorting algorithm for a single median filtering; the first memory space includes a private space corresponding to the first sorting algorithm for a single median filtering; in the first memory space, perform median filtering on the first image based on the mask and the first sorting algorithm to obtain the second image.

[0175] In some embodiments, the filtering module 820 is specifically configured to: determine a first number of registers required by the first sorting algorithm for a single median filtering based on the size of the mask; and determine a first number of registers as the first memory space from the resources of a computer device used for image filtering.

[0176] In some embodiments, the filtering module 820 is specifically configured to: extract a target array of a single median filter from the first image; transfer the target array from the second memory space to the first memory space; the second memory space includes space on a memory component; and perform median filtering on the target array based on the mask and the first sorting algorithm in the first memory space to obtain the second image.

[0177] In some embodiments, the filtering module 820 is specifically configured to: when the sorting algorithm is a third sorting algorithm, determine the third memory space required by the third sorting algorithm for a single median filtering; the third memory space includes a private space corresponding to the third sorting algorithm for a single median filtering; on the third memory space, perform median filtering on the first image based on the mask and the third sorting algorithm to obtain the second image.

[0178] In some embodiments, the filtering module 820 is specifically configured to: determine the size of the sliding window based on the size of the mask; determine the second number of registers required by the third sorting algorithm when performing a single filtering process based on the size of the sliding window; and determine a second number of registers as the third memory space from the resources of a computer device used for image filtering.

[0179] In some embodiments, the filtering module 820 is specifically configured to: determine a preset first threshold and a second threshold; perform a first operation on the length and width of the mask size to obtain a first value; perform a second operation on the first value and the first threshold to obtain a second value; perform a third operation on the second value and the second threshold to obtain the size of the sliding window.

[0180] In some embodiments, the filtering module 820 is specifically configured to: perform median filtering on the first image based on the mask, the third sorting algorithm and the sliding window in the third memory space to obtain the second image.

[0181] In some embodiments, the filtering module 820 is specifically configured as follows: when the sorting algorithm is the fourth sorting algorithm, in the second memory space of the computer device used for image filtering, median filtering is performed on the first image based on the mask and the fourth sorting algorithm to obtain the second image; the second memory space includes the space on the memory component.

[0182] In some embodiments, the target data type is used for memory access between the first memory space, the second memory space, and the third memory space of the computer device.

[0183] The description of the above device embodiment is similar to the description of the above method embodiment, and has similar beneficial effects as the method embodiment. In some embodiments, the functions or modules included in the device provided in the embodiments of the present disclosure can be used to execute the method described in the above method embodiment. For technical details not disclosed in the device embodiment of the present disclosure, please refer to the description of the method embodiment of the present disclosure for understanding.

[0184] It should be noted that in the embodiments of the present disclosure, if the above-mentioned image processing method is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiments of the present disclosure is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, which is stored in a storage medium and includes a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in each embodiment of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM), a disk or an optical disk. In this way, the embodiments of the present disclosure are not limited to any specific hardware, software or firmware, or any combination of hardware, software, and firmware.

[0185] An embodiment of the present disclosure provides a computer device, including a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the processor executes the program, some or all of the steps in the above method are implemented.

[0186] The embodiment of the present disclosure provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, some or all of the steps in the above method are implemented. The computer-readable storage medium can be transient or non-transient.

[0187] An embodiment of the present disclosure provides a computer program, including a computer-readable code. When the computer-readable code is executed in a computer device, a processor in the computer device executes some or all of the steps for implementing the above method.

[0188] The present disclosure provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and when the computer program is read and executed by a computer, some or all of the steps in the above method are implemented. The computer program product can be implemented specifically by hardware, software or a combination thereof. In some embodiments, the computer program product is specifically embodied as a computer storage medium, and in other embodiments, the computer program product is specifically embodied as a software product, such as a software development kit (SDK), etc.

[0189] It should be noted here that the description of the various embodiments above tends to emphasize the differences between the various embodiments, and the same or similar aspects can be referenced to each other. The description of the above device, storage medium, computer program and computer program product embodiments is similar to the description of the above method embodiment, and has similar beneficial effects as the method embodiment. For technical details not disclosed in the embodiments of the device, storage medium, computer program and computer program product disclosed in the present invention, please refer to the description of the method embodiment disclosed in the present invention for understanding.

[0190] It should be noted that Fig. 9 is a schematic diagram of a hardware entity of a computer device in an embodiment of the present disclosure, such as Fig. 9 As shown, the hardware entity of the computer device 900 includes: a processor 901, a communication interface 902 and a memory 903, wherein:

[0191] Processor 901 generally controls the overall operation of computer device 900 .

[0192] The communication interface 902 enables the computer device to communicate with other terminals or servers through a network.

[0193] The memory 903 is configured to store instructions and applications executable by the processor 901, and can also cache data to be processed or processed by the processor 901 and each module in the computer device 900 (for example, image data, audio data, voice communication data, and video communication data), which can be implemented by flash memory (FLASH) or random access memory (Random Access Memory, RAM). Data transmission between the processor 901, the communication interface 902 and the memory 903 can be carried out through the bus 904.

[0194] It should be understood that "one embodiment" or "an embodiment" mentioned throughout the specification means that specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present disclosure. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in the various embodiments of the present disclosure, the size of the serial numbers of the above-mentioned steps / processes does not mean the order of execution. The execution order of each step / process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present disclosure. The serial numbers of the embodiments of the present disclosure are for description only and do not represent the advantages and disadvantages of the embodiments.

[0195] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.

[0196] In the several embodiments provided in the present disclosure, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored, or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.

[0197] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units; they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0198] In addition, all functional units in the embodiments of the present disclosure may be integrated into one processing unit, or each unit may be separately configured as a unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.

[0199] A person skilled in the art can understand that all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the aforementioned storage medium includes: mobile storage devices, read-only memories (ROM), magnetic disks or optical disks, etc., various media that can store program codes.

[0200] Alternatively, if the above-mentioned integrated unit of the present disclosure is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present disclosure can essentially or in other words, the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in each embodiment of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROMs, magnetic disks, or optical disks.

[0201] The above description is only an implementation mode of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present disclosure, which should be included in the protection scope of the present disclosure.

Claims

1. An image processing method, characterized in that: The image processing method comprises: Determining a mask corresponding to a first image to be processed; Determining a sorting algorithm corresponding to the mask based on the size of the mask and the memory requirements of the mask under different sorting algorithms; the sorting algorithm is used to sort the array in the image during a single median filtering; Performing median filtering on the first image based on the mask and the sorting algorithm to obtain a second image.

2. The image processing method according to claim 1, characterized in that: The determining, based on the size of the mask and the memory requirements of the mask under different sorting algorithms, a sorting algorithm corresponding to the mask includes: Determining a first resource possessed by a computer device for performing image filtering; Determine a resource difference based on the size of the mask and the first resource; the resource difference is a difference between resources required for median filtering the first image and resources possessed by the computer device; Based on the resource difference, preset resource conditions and memory requirements of the mask under different sorting algorithms, a sorting algorithm corresponding to the mask is determined.

3. The image processing method according to claim 2, characterized in that: The determining the resource difference based on the size of the mask and the first resource includes: determining, based on the size of the mask, a second resource required for performing median filtering on the first image; The resource difference is determined based on the first resource and the second resource.

4. The image processing method according to claim 2 or 3, characterized in that: The determining, based on the resource difference, the preset resource condition and the memory requirement of the mask under different sorting algorithms, a sorting algorithm corresponding to the mask includes: When the resource difference satisfies the resource condition, using the first sorting algorithm as the sorting algorithm corresponding to the mask; When the resource difference does not meet the resource condition and the memory requirement of the mask under the second sorting algorithm is lower than the memory requirement under the first sorting algorithm, the second sorting algorithm is used as the sorting algorithm corresponding to the mask; the number of branches of the first sorting algorithm during processing is less than the number of branches of the second sorting algorithm during processing.

5. The image processing method according to claim 4, characterized in that: The method of using the second sorting algorithm as the sorting algorithm corresponding to the mask when the resource difference does not satisfy the resource condition and the memory requirement of the mask under the second sorting algorithm is lower than the memory requirement under the first sorting algorithm includes: When the resource difference does not meet the resource condition, the memory requirement of the mask under the third sorting algorithm is lower than the memory requirement under the fourth sorting algorithm, and the size of the mask meets the preset size condition, the third sorting algorithm is used as the sorting algorithm corresponding to the mask; When the resource difference does not meet the resource condition and the size of the mask does not meet the size condition, the fourth sorting algorithm is used as the sorting algorithm corresponding to the mask; the processing efficiency of the third sorting algorithm is better than that of the fourth sorting algorithm; the second sorting algorithm includes the third sorting algorithm and the fourth sorting algorithm.

6. The image processing method according to any one of claims 1 to 3 or 5, characterized in that: The step of performing median filtering on the first image based on the mask and the sorting algorithm to obtain a second image includes: In the case where the sorting algorithm is a first sorting algorithm, determining a first memory space required by the first sorting algorithm for single median filtering; the first memory space includes a private space corresponding to the first sorting algorithm for single median filtering; In the first memory space, median filtering is performed on the first image based on the mask and the first sorting algorithm to obtain the second image.

7. The image processing method according to claim 6, characterized in that: The determining of the first memory space required by the first sorting algorithm for single median filtering includes: Determining, based on the size of the mask, a first number of registers required by the first sorting algorithm for a single median filtering; A first number of registers is determined from resources of a computer device used for image filtering as the first memory space.

8. The image processing method according to claim 6, characterized in that: The step of performing median filtering on the first image based on the mask and the first sorting algorithm in the first memory space to obtain the second image includes: Extracting a single median filtered target array from the first image; Transferring the target array from a second memory space to the first memory space; the second memory space includes space on a memory component; In the first memory space, median filtering is performed on the target array based on the mask and the first sorting algorithm to obtain the second image.

9. The image processing method according to any one of claims 1 to 3 or 5, characterized in that: The step of performing median filtering on the first image based on the mask and the sorting algorithm to obtain a second image includes: In the case where the sorting algorithm is a third sorting algorithm, determining a third memory space required by the third sorting algorithm during a single median filtering; the third memory space includes a private space corresponding to the third sorting algorithm during a single median filtering; In the third memory space, median filtering is performed on the first image based on the mask and the third sorting algorithm to obtain the second image.

10. The image processing method according to claim 9, characterized in that: The determining of the third memory space required by the third sorting algorithm for single median filtering includes: Determining a size of the sliding window based on the size of the mask; Determining, based on the size of the sliding window, a second number of registers required by the third sorting algorithm when performing a single filtering process; A second number of registers is determined from resources of a computer device used for image filtering as the third memory space.

11. The image processing method according to claim 10, characterized in that: The determining the size of the sliding window based on the size of the mask includes: Determine a preset first threshold and a second threshold; Performing a first operation on the length and width of the size of the mask to obtain a first value; Performing a second operation on the first value and the first threshold to obtain a second value; A third operation is performed on the second value and the second threshold to obtain the size of the sliding window.

12. The image processing method according to claim 10 or 11, characterized in that: The step of performing median filtering on the first image based on the mask and the third sorting algorithm in the third memory space to obtain the second image includes: In the third memory space, median filtering is performed on the first image based on the mask, the third sorting algorithm and the sliding window to obtain the second image.

13. The image processing method according to any one of claims 1 to 3 or 5, characterized in that: The step of performing median filtering on the first image based on the mask and the sorting algorithm to obtain a second image includes: When the sorting algorithm is the fourth sorting algorithm, in a second memory space of a computer device used for image filtering, median filtering is performed on the first image based on the mask and the fourth sorting algorithm to obtain the second image; the second memory space includes space on a memory component.

14. The image processing method according to claim 8, characterized in that: The target data type is used to access memory between the first memory space, the second memory space and the third memory space of the computer device.

15. An image processing device, characterized in that: The image processing device comprises: A determination module, configured to determine a mask corresponding to the first image to be processed; The determination module is further configured to determine a sorting algorithm corresponding to the mask based on the size of the mask and the memory requirements of the mask under different sorting algorithms; the sorting algorithm is used to sort the array in the image during a single median filtering; A filtering module is configured to perform median filtering on the first image based on the mask and the sorting algorithm to obtain a second image.

16. A computer device comprising a memory and a processor, wherein the memory stores a computer program executable on the processor, wherein: When the processor executes the program, the steps of the method according to any one of claims 1 to 14 are implemented.

17. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 14 are implemented.

18. A computer program product comprising a computer program or instructions, characterized in that When the computer program or instruction is executed by a processor, the steps of the method according to any one of claims 1 to 14 are implemented.