Image processing method and related device

By calling kernel functions on the graphics processor GPU and using thread grids for parallel processing, the CPU is solved inefficient in massive high-concurrent picture cropping, and efficient picture cropping is achieved.

CN112037114BActive Publication Date: 2025-05-16FOSHAN SHUNDE GUANGQI ADVANCED EQUIP CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN201910477646.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-06-03
Publication Date
2025-05-16
Estimated Expiration
2039-06-03

AI Technical Summary

Technical Problem

In the prior art, since the CPU can only process one picture at a time when the image is trimmed, the cutting efficiency is low when facing a large number of high-concurrency pictures.

Method used

The graphics processor GPU is used to perform image cutting processing, and all images in the to-process image group are trimmed in parallel by calling the kernel function, and the thread grid is used for parallel processing.

Benefits of technology

It realizes efficient tailoring of massive and high-concurrent pictures, improves tailoring efficiency, and can meet the tailoring needs of massive pictures.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112037114B_ABST
    Figure CN112037114B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for processing pictures and related devices, wherein the picture processing device includes a graphics processor (GPU); the picture processing method includes: receiving picture data; the picture data includes a to-be-processed picture group and clipping coordinates corresponding to the to-be-processed picture group; the to-be-processed picture group includes at least one picture; calling a kernel function to clip all pictures in the to-be-processed picture group according to the clipping coordinates to obtain a clipping result; wherein the kernel function is configured with at least one thread grid. The present invention uses a GPU to clip pictures, and configures a thread grid for the kernel function used to clip pictures. Compared with the method of using a CPU to clip pictures in the prior art, the present invention can realize parallel clipping of multiple pictures, can meet the clipping requirements of massive and highly concurrent pictures, and at the same time, by calling the kernel function to directly extract pixel values ​​within the clipping coordinate range, obtain a clipping result, and has higher clipping efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image processing, and in particular to an image processing method and related devices. Background Art

[0002] Image cropping refers to cutting and extracting the target area in a picture. Image cropping can extract key information from massive image information, which is an important part of the image processing process.

[0003] The existing image cropping method is to first transfer the image to be processed to the memory of the CPU of the image processing device, and then crop the image through the CPU. Since the CPU can only process one image at a time when cropping the image, the cropping efficiency is low when facing massive and highly concurrent images. Summary of the invention

[0004] The present invention provides a picture processing method and related devices, which can solve the problem in the prior art that when a CPU performs picture cropping processing, it can only process pictures one by one, resulting in low cropping efficiency.

[0005] To achieve the above object, the present invention provides the following technical solutions:

[0006] Part 1: A method for image processing, applied to an image processing device including a graphics processor (GPU), the method comprising:

[0007] Receive image data; wherein the image data includes a to-be-processed image group and clipping coordinates corresponding to the to-be-processed image group; the to-be-processed image group includes at least one image;

[0008] Calling a kernel function to perform cropping on all images in the image group to be processed according to the cropping coordinates to obtain cropping results; wherein the kernel function is used to perform cropping on the images, and the kernel function is configured with at least one grid, each of the grids includes at least one thread block, and each of the thread blocks includes at least one thread.

[0009] Optionally, the calling of the kernel function to perform image clipping on all images in the to-be-processed image group according to the clipping coordinates to obtain a clipping result includes:

[0010] Calling part or all of the pictures in the to-be-processed picture group according to the processing capabilities of all threads configured by the kernel function;

[0011] In each of the called pictures, determining a pixel area corresponding to the clipping coordinates;

[0012] The threads configured by the kernel function are used to extract the pixel values ​​of all pixels in the pixel area of ​​each picture in the group of pictures to be processed in parallel to obtain a cropping result; wherein each thread configured by the kernel function corresponds to a pixel of the picture.

[0013] Optionally, determining the pixel area corresponding to the clipping coordinates in each of the called pictures includes:

[0014] In each of the called images, the x-coordinate and the y-coordinate of the pixel area are calculated according to Formula 1 and Formula 2 respectively;

[0015] Wherein, Formula 1 is: x=threadIdx.x+blockIdx.x*blockDim.x; wherein, threadIdx.x is the x coordinate of the coordinate ID of the thread corresponding to the clipping coordinate, blockIdx.x is the x coordinate of the coordinate ID of the thread block to which the thread corresponding to the clipping coordinate belongs, and blockDim.x is the number of threads in the x direction of the thread block to which the thread corresponding to the clipping coordinate belongs;

[0016] Formula 2 is: y=threadIdx.y+blockIdx.y*blockDim.y; wherein threadIdx.y is the y coordinate of the coordinate ID of the thread corresponding to the clipping coordinate, blockIdx.y is the y coordinate of the coordinate ID of the thread block to which the thread corresponding to the clipping coordinate belongs, and blockDim.y is the number of threads in the y direction of the thread block to which the thread corresponding to the clipping coordinate belongs.

[0017] Optionally, the image processing method further includes:

[0018] Sending the trimming result to the CPU memory;

[0019] Release the memory space of the GPU.

[0020] Part 2: A graphics processor, comprising:

[0021] A receiving unit, configured to receive picture data; wherein the picture data includes a picture group to be processed and clipping coordinates corresponding to the picture group to be processed; the picture group to be processed includes at least one picture;

[0022] A cropping unit is used to call a kernel function to crop all images in the image group to be processed according to the cropping coordinates to obtain a cropping result; wherein the kernel function is used to crop the images, and the kernel function is configured with at least one grid, each of the grids includes at least one thread block, and each of the thread blocks includes at least one thread.

[0023] Optionally, the cutting unit includes:

[0024] A calling unit, configured to call part or all of the pictures in the to-be-processed picture group according to the processing capabilities of all threads configured by the kernel function;

[0025] A determination unit, configured to determine, in each of the called pictures, a pixel area corresponding to the clipping coordinates;

[0026] The extraction unit is used to use the threads configured by the kernel function to extract in parallel the pixel values ​​of all pixel points in the pixel area of ​​each picture in the group of pictures to be processed to obtain a cropping result; wherein each thread configured by the kernel function corresponds to a pixel point of the picture.

[0027] Optionally, the determining unit includes:

[0028] A calculation unit, used for calculating the x-coordinate and the y-coordinate of the pixel area in each of the called pictures according to Formula 1 and Formula 2 respectively;

[0029] Wherein, Formula 1 is: x=threadIdx.x+blockIdx.x*blockDim.x; wherein, threadIdx.x is the x coordinate of the coordinate ID of the thread corresponding to the clipping coordinate, blockIdx.x is the x coordinate of the coordinate ID of the thread block to which the thread corresponding to the clipping coordinate belongs, and blockDim.x is the number of threads in the x direction of the thread block to which the thread corresponding to the clipping coordinate belongs;

[0030] Formula 2 is: y=threadIdx.y+blockIdx.y*blockDim.y; wherein threadIdx.y is the y coordinate of the coordinate ID of the thread corresponding to the clipping coordinate, blockIdx.y is the y coordinate of the coordinate ID of the thread block to which the thread corresponding to the clipping coordinate belongs, and blockDim.y is the number of threads in the y direction of the thread block to which the thread corresponding to the clipping coordinate belongs.

[0031] Optionally, the graphics processor further includes:

[0032] A sending unit, used for sending the trimming result to a central processing unit (CPU) memory;

[0033] A release unit is used to release the memory space of the graphics processor.

[0034] Part III: An image processing device, comprising: a graphics processor and a central processing unit; wherein:

[0035] The graphics processor is used to execute the image processing method as described in the first part above;

[0036] The central processing unit is used to send the image data to the graphics processing unit.

[0037] Optionally, the central processing unit is further used to receive and save the clipping result.

[0038] Through the above technical scheme, it can be known that the present invention discloses a picture processing method and related devices, wherein the picture processing method is applied to a picture processing device including a graphics processor GPU, and when the picture processing device executes the picture processing method, it is used to receive picture data; wherein the picture data includes a to-be-processed picture group and the clipping coordinates corresponding to the to-be-processed picture group; the to-be-processed picture group includes at least one picture; the kernel function is called to clip all pictures in the to-be-processed picture group according to the clipping coordinates to obtain the clipping result; wherein the kernel function is used to clip the picture, and the kernel function is configured with at least one thread grid. The present invention uses GPU to clip pictures, and configures a thread grid for the kernel function used to clip pictures. Compared with the method of using CPU to clip pictures in the prior art, it can realize parallel clipping of multiple pictures, and can meet the clipping requirements of massive and highly concurrent pictures. At the same time, by calling the kernel function, the pixel values ​​within the clipping coordinate range can be directly extracted to obtain the clipping result, which has higher clipping efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0040] Figure 1 A schematic diagram of the structure of a picture processing device disclosed in an embodiment of the present invention;

[0041] Figure 2 A flowchart of configuring a grid and a kernel function disclosed in an embodiment of the present invention;

[0042] Figure 3 A schematic diagram of a grid of a GPU in the image processing method disclosed in an embodiment of the present invention;

[0043] Figure 4 A flowchart of a picture processing method disclosed in an embodiment of the present invention;

[0044] Figure 5A schematic diagram of a pixel area to be cropped in the image processing method disclosed in an embodiment of the present invention;

[0045] Figure 6 The present invention is a schematic diagram of the structure of a graphics processor disclosed in an embodiment of the present invention. DETAILED DESCRIPTION

[0046] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0047] The present invention provides a picture processing method and related devices, which can solve the problem in the prior art that when a CPU performs picture cropping processing, it can only process pictures one by one, resulting in low cropping efficiency.

[0048] First of all, it should be noted that an embodiment of the present invention discloses a method for processing an image, which is applied to an image processing device, such as Figure 1 As shown, the image processing device includes a graphics processor 101 (Graphics Processing Unit, GPU) and a central processing unit 102 (Central Processing Unit, CPU).

[0049] Among them, GPU101 can download massive images on the Internet, or obtain massive images from storage spaces such as local disks or external storage devices, and the massive data obtained by the GPU are all used for image cropping. In addition, in order to prevent the GPU resources from being too high during the image cropping process, it is necessary to group the massive images first to obtain multiple groups of images, and each group of images will be transmitted to the GPU at one time. After the GPU completes the image cropping, the cropping result is obtained. In addition, after a group of images is cropped, the CPU will transmit the next group of images to the GPU, and the GPU will perform image cropping until all groups of images have been cropped.

[0050] Optionally, after the GPU obtains the cropping results of a group of images, the cropping results of the images may be sent to the CPU and stored in the CPU memory, and the memory space of the GPU is released.

[0051] It should be noted that the GPU has a smaller memory space and is generally only used for temporary caching during processing. The CPU has a larger memory space and can store data stably and for a long time for the next processing. Therefore, the clipping results can be transferred to the CPU memory for data storage.

[0052] It should be noted that after sending the cropping result to the CPU memory, the GPU completes one image cropping operation. To ensure that the GPU memory has enough space for the next image cropping operation, the GPU memory space is released.

[0053] It should also be noted that before the GPU performs image cropping, the kernel function and the grid need to be configured first. Since the GPU is required to perform image cropping, the kernel function configured in the GPU is a kernel function for performing image cropping processing.

[0054] Furthermore, in the GPU, the grid of the GPU can be defined according to the pixel size of a group of pictures. The group of pictures generally selects the group with the largest data volume after the massive data is grouped. Of course, the grid of the GPU can also be determined according to past experience without referring to the pixel size of the pictures in the picture group to be cropped this time.

[0055] Specifically, take the definition of the GPU grid according to the pixel size of the image as an example, Figure 2 As shown in the figure, the process of configuring the grid and kernel function includes:

[0056] S201: Establish a GPU grid according to the pixel sizes of the pictures in the picture group to be processed.

[0057] In step S201, each grid in the grid is a thread block, each grid includes at least one thread block, each thread block includes at least one thread, and each thread is allocated a single-channel pixel point;

[0058] It should be noted that if Figure 3 , which is a schematic diagram of a grid of a GPU disclosed in this embodiment. Each single-channel pixel in the image to be processed corresponds to a thread, and all threads form a thread grid. All threads in the grid share the global memory of the GPU. A grid is composed of multiple thread blocks, and a thread block is composed of multiple threads. The threads in the thread block are also distributed in a grid form.

[0059] It should be noted that both the grid and the thread block can be one-dimensional, two-dimensional or three-dimensional structures. Figure 3 What is shown in FIG. 1 is a two-dimensional grid and a two-dimensional thread block, and all threads in the entire grid can be started by a single kernel function.

[0060] S202, setting the coordinate ID of the first thread block in the first row of the thread grid to (0, 0), setting the coordinate ID of the second thread block in the first row of the thread grid to (0, 1), and so on, setting the coordinate IDs of all thread blocks in the thread grid.

[0061] Specifically, it can be seen Figure 3 The setting of the coordinate ID to be disclosed in .

[0062] S203: configuring the grid as a thread of a kernel function and configuring the kernel function.

[0063] After the above thread settings, the corresponding thread only needs to process the relevant pixel data of the corresponding position in the image, and then merge the data processed by all threads, which is equivalent to "reading" the image within the cropping range and re-"combining" it into a new image to complete the cropping effect. By utilizing the thread setting characteristics of the GPU itself, high-concurrency operations can be achieved.

[0064] It should be noted that, through the thread configuration of the kernel function, an association relationship between the kernel function and all threads in the grid is established, so that when the kernel function is called, it can extract the single-channel pixel points corresponding to all threads in the clipping area enclosed by the clipping coordinates in the picture, and compose the clipped picture to complete the clipping work.

[0065] After the GPU in the image processing device completes the configuration of the kernel function and the grid, the image processing method can be executed. Figure 4 As shown, the method comprises the following steps:

[0066] S401, receiving picture data.

[0067] The GPU in the image processing device receives the image data. In step S401, the image data includes a group of images to be processed and clipping coordinates corresponding to the group of images to be processed; the group of images to be processed includes at least one image. The group of images to be processed is a group after the mass images mentioned in the above content are grouped.

[0068] The clipping coordinates corresponding to the image group to be processed may include: clipping coordinates corresponding to each image in the image group to be processed, and optionally, the clipping coordinates corresponding to each image may be saved in an array format. Of course, the clipping coordinates corresponding to the image group to be processed may also be a set of coordinates, that is, the same set of coordinates is used to clip each image in the image group to be processed.

[0069] The clipping coordinates are used to describe the clipping range when clipping an image. They can be in the form of the upper left coordinate and lower right coordinate of the clipping range, or in the form of the upper left coordinate and the width and height of the clipping range.

[0070] Optionally, after the GPU receives the image data, the image data may also be stored in a pre-applied memory space.

[0071] It should be noted that the memory space is the memory space of the GPU. Since the memory space of the GPU is limited, before performing image processing, it is necessary to apply for the memory space of the GPU according to the size of the image group to be cropped to ensure the smooth progress of the image cropping work.

[0072] S402 , calling a kernel function to perform cropping on all pictures in the to-be-processed picture group according to the cropping coordinates to obtain cropping results.

[0073] The kernel function is used to perform clipping on the image. As can be seen from the above content, the kernel function is configured with at least one grid, each of which includes at least one thread block, and each of which includes at least one thread. After the kernel function is thread-configured, an association relationship is established with all threads in the grid, and the pixel values ​​within the clipping coordinate range are extracted by driving the threads within the clipping coordinate range to execute the kernel function, thereby obtaining the clipping result.

[0074] Optionally, the calling of the kernel function to perform image clipping on all images in the to-be-processed image group according to the clipping coordinates to obtain a clipping result includes:

[0075] According to the processing capabilities of all threads configured by the kernel function, some or all pictures in the to-be-processed picture group are called.

[0076] Optionally, in another embodiment of the present invention, in the process of pre-grouping all the pictures to be processed, they can be grouped according to the processing capabilities of all threads configured by the kernel function, so that each cropping directly calls all the pictures in the picture group to be processed.

[0077] In each of the called pictures, a pixel area corresponding to the clipping coordinates is determined.

[0078] It should be noted that, from the above content, it can be known that the pixel area to be cropped in each picture can be determined by the same cropping coordinates, or the pixel area to be cropped of each picture can be determined by the cropping coordinates corresponding to each picture.

[0079] Optionally, in each of the called pictures, the process of determining the pixel area corresponding to the clipping coordinates includes:

[0080] In each of the called images, the x-coordinate and the y-coordinate of the pixel area are calculated according to Formula 1 and Formula 2 respectively.

[0081] Among them, formula 1 is: x=threadIdx.x+blockIdx.x*blockDim.x; wherein threadIdx.x is the x coordinate of the coordinate ID of the thread corresponding to the clipping coordinate, blockIdx.x is the x coordinate of the coordinate ID of the thread block to which the thread corresponding to the clipping coordinate belongs, and blockDim.x is the number of threads in the x direction of the thread block to which the thread corresponding to the clipping coordinate belongs.

[0082] Formula 2 is: y=threadIdx.y+blockIdx.y*blockDim.y; wherein threadIdx.y is the y coordinate of the coordinate ID of the thread corresponding to the clipping coordinate, blockIdx.y is the y coordinate of the coordinate ID of the thread block to which the thread corresponding to the clipping coordinate belongs, and blockDim.y is the number of threads in the y direction of the thread block to which the thread corresponding to the clipping coordinate belongs.

[0083] It should be noted that the clipping coordinates are generally in the form of an array. In a two-dimensional rectangular coordinate system, the data contains two coordinate values, and the distance in the x direction and the distance in the y direction of the two coordinate values ​​enclose a pixel area to be clipped. Specifically, Figure 5 As shown in the figure, the area surrounded by the dotted line is the pixel area to be clipped. Figure 5 In the figure, a two-dimensional rectangular coordinate system is established with the upper left corner as the origin, and the array of clipping coordinates is (0, 0)(x, y). Since each thread corresponds to a pixel point, after obtaining the coordinates of the pixel area, all threads that need to execute the kernel function to clip the image can be obtained.

[0084] The threads configured by the kernel function are used to extract the pixel values ​​of all pixels in the pixel area of ​​each picture in the group of pictures to be processed in parallel to obtain a cropping result; wherein each thread configured by the kernel function corresponds to a pixel of the picture.

[0085] Specifically, the GPU drives all threads in the pixel area to be cropped to execute the kernel function, extracts the pixel values ​​of the pixels corresponding to each thread, and composes a cropped image, and uses the cropped image as the cropping result.

[0086] It should be noted that, by utilizing the functional characteristics of the GPU, each of the called images can be cropped in parallel through the above steps to improve the cropping efficiency, but if necessary, each of the called images can also be cropped one by one.

[0087] The present embodiment discloses a picture processing method applied to a picture processing device including a graphics processor (GPU). When the picture processing device executes the picture processing method, it is used to receive picture data; wherein the picture data includes a group of pictures to be processed and the clipping coordinates corresponding to the group of pictures to be processed; the group of pictures to be processed includes at least one picture; a kernel function is called to clip all pictures in the group of pictures to be processed according to the clipping coordinates to obtain a clipping result; wherein the kernel function is used to clip the pictures, and the kernel function is configured with at least one thread grid. The present invention uses a GPU to clip pictures, and configures a thread grid for the kernel function used to clip pictures. Compared with the method of using a CPU to clip pictures in the prior art, it can realize parallel clipping of multiple pictures, can meet the clipping requirements of massive and highly concurrent pictures, and at the same time, by calling the kernel function, the pixel values ​​within the clipping coordinate range can be directly extracted to obtain the clipping result, which has higher clipping efficiency.

[0088] Based on the picture processing method disclosed in the above embodiment of the present invention, Figure 6 The invention specifically discloses a graphics processor applying the method.

[0089] like Figure 6 As shown, another embodiment of the present invention discloses a graphics processor, comprising:

[0090] The receiving unit 601 is used to receive picture data; wherein the picture data includes a picture group to be processed and clipping coordinates corresponding to the picture group to be processed; and the picture group to be processed includes at least one picture.

[0091] The cropping unit 602 is used to call the kernel function to crop all the pictures in the picture group to be processed according to the cropping coordinates to obtain a cropping result; wherein the kernel function is used to crop the pictures, and the kernel function is configured with at least one grid, each of the grids includes at least one thread block, and each of the thread blocks includes at least one thread.

[0092] Optionally, in another embodiment of the present invention, in the graphics processor, the clipping unit 602 includes:

[0093] The calling unit is used to call part or all of the pictures in the to-be-processed picture group according to the processing capabilities of all threads configured by the kernel function.

[0094] The determination unit is used to determine the pixel area corresponding to the clipping coordinates in each of the called pictures.

[0095] The extraction unit is used to use the threads configured by the kernel function to extract in parallel the pixel values ​​of all pixel points in the pixel area of ​​each picture in the group of pictures to be processed to obtain a cropping result; wherein each thread configured by the kernel function corresponds to a pixel point of the picture.

[0096] Optionally, in another embodiment of the present invention, the determining unit includes:

[0097] The calculation unit is used to calculate the x coordinate and the y coordinate of the pixel area in each of the called pictures according to Formula 1 and Formula 2 respectively.

[0098] Among them, formula 1 is: x=threadIdx.x+blockIdx.x*blockDim.x; wherein threadIdx.x is the x coordinate of the coordinate ID of the thread corresponding to the clipping coordinate, blockIdx.x is the x coordinate of the coordinate ID of the thread block to which the thread corresponding to the clipping coordinate belongs, and blockDim.x is the number of threads in the x direction of the thread block to which the thread corresponding to the clipping coordinate belongs.

[0099] Formula 2 is: y=threadIdx.y+blockIdx.y*blockDim.y; wherein threadIdx.y is the y coordinate of the coordinate ID of the thread corresponding to the clipping coordinate, blockIdx.y is the y coordinate of the coordinate ID of the thread block to which the thread corresponding to the clipping coordinate belongs, and blockDim.y is the number of threads in the y direction of the thread block to which the thread corresponding to the clipping coordinate belongs.

[0100] Optionally, in another embodiment of the present invention, the graphics processor further includes:

[0101] The sending unit is used to send the trimming result to the memory of the central processing unit (CPU).

[0102] A release unit is used to release the memory space of the graphics processor.

[0103] It should be noted that, after receiving the clipping result, the CPU outputs the clipping result to the user and saves the clipping result.

[0104] The specific working processes of the receiving unit 601, the cropping unit 602, the sending unit, the releasing unit, the calling unit, the determining unit and the extracting unit in the graphics processor disclosed in the above embodiment of the present invention can be referred to the corresponding content in the image processing method disclosed in the above embodiment of the present invention, and will not be repeated here.

[0105] The present embodiment discloses a graphics processor, wherein a receiving unit receives picture data; wherein the picture data includes a to-be-processed picture group and clipping coordinates corresponding to the to-be-processed picture group; the to-be-processed picture group includes at least one picture; the clipping unit calls a kernel function to clip all pictures in the to-be-processed picture group according to the clipping coordinates to obtain a clipping result; wherein the kernel function is used to clip the picture, and the kernel function is configured with at least one thread grid. The present invention uses a GPU to clip pictures, and configures a thread grid for the kernel function used to clip pictures. Compared with the method of using a CPU to clip pictures in the prior art, the present invention can realize parallel clipping of multiple pictures, can meet the clipping requirements of massive and highly concurrent pictures, and at the same time, by calling the kernel function, the pixel values ​​within the clipping coordinate range can be directly extracted to obtain the clipping result, which has higher clipping efficiency.

[0106] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity 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, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0107] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0108] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.

Claims

1. A method for image processing, applied to an image processing device including a graphics processor GPU, characterized in that: include: Receive image data; wherein the image data includes a to-be-processed image group and clipping coordinates corresponding to the to-be-processed image group; the to-be-processed image group includes at least one image; Calling a kernel function to perform image cropping on all images in the image group to be processed according to the cropping coordinates to obtain a cropping result; wherein the kernel function is used to crop images, and the kernel function is configured with at least one grid, each of which includes at least one thread block, and each of which includes at least one thread; the image group to be processed is obtained by grouping based on the processing capabilities of all threads configured by the kernel function; the cropping coordinates are used to illustrate the cropping range when cropping images, and the cropping range is in the form of upper left coordinates and lower right coordinates or in the form of upper left coordinates and width and height of the cropping range; wherein the image group to be processed is obtained by grouping based on the processing capabilities of all threads configured by the kernel function, including: determining the maximum number of images in each image group to be processed according to the parallel processing capabilities of all threads configured by the kernel function; The calling of the kernel function performs image cropping according to the cropping coordinates on all images in the image group to be processed to obtain cropping results, including: calling part or all of the images in the image group to be processed according to the processing capabilities of all threads configured by the kernel function; determining the pixel area corresponding to the cropping coordinates in each of the called images; and extracting the pixel values ​​of all pixel points in the pixel area of ​​each image in the image group to be processed in parallel using the threads configured by the kernel function to obtain cropping results; wherein each thread configured by the kernel function corresponds to a pixel point of the image; Sending the trimming result to the CPU memory; Release the memory space of the GPU.

2. The image processing method according to claim 1, characterized in that: Determining the pixel area corresponding to the clipping coordinates in each of the called pictures includes: In each of the called images, the x-coordinate and the y-coordinate of the pixel area are calculated according to Formula 1 and Formula 2 respectively; Wherein, Formula 1 is: x=threadIdx.x+blockIdx.x*blockDim.x; wherein, threadIdx.x is the x coordinate of the coordinate ID of the thread corresponding to the clipping coordinate, blockIdx.x is the x coordinate of the coordinate ID of the thread block to which the thread corresponding to the clipping coordinate belongs, and blockDim.x is the number of threads in the x direction of the thread block to which the thread corresponding to the clipping coordinate belongs; Formula 2 is: y=threadIdx.y+blockIdx.y*blockDim.y; wherein threadIdx.y is the y coordinate of the coordinate ID of the thread corresponding to the clipping coordinate, blockIdx.y is the y coordinate of the coordinate ID of the thread block to which the thread corresponding to the clipping coordinate belongs, and blockDim.y is the number of threads in the y direction of the thread block to which the thread corresponding to the clipping coordinate belongs.

3. A graphics processor GPU, characterized in that: include: A receiving unit, configured to receive picture data; wherein the picture data includes a picture group to be processed and clipping coordinates corresponding to the picture group to be processed; the picture group to be processed includes at least one picture; A clipping unit, used for calling a kernel function to clip all the pictures in the picture group to be processed according to the clipping coordinates to obtain a clipping result; wherein the kernel function is used to clip the pictures, and the kernel function is configured with at least one grid, each of which includes at least one thread block, and each of which includes at least one thread; wherein the picture group to be processed is obtained by grouping based on the processing capabilities of all threads configured by the kernel function, including: determining the maximum number of pictures in each picture group to be processed according to the parallel processing capabilities of all threads configured by the kernel function; Wherein, the cutting unit comprises: A calling unit, configured to call part or all of the pictures in the to-be-processed picture group according to the processing capabilities of all threads configured by the kernel function; A determination unit, configured to determine, in each of the called pictures, a pixel area corresponding to the clipping coordinates; An extraction unit, configured to extract, in parallel, pixel values ​​of all pixels in a pixel area of ​​each picture in the to-be-processed picture group using the threads configured by the kernel function, to obtain a cropping result; wherein each thread configured by the kernel function corresponds to a pixel of the picture; A sending unit, used for sending the trimming result to a central processing unit (CPU) memory; A release unit is used to release the memory space of the graphics processor.

4. The graphics processor GPU according to claim 3, characterized in that: The determining unit comprises: A calculation unit, used for calculating the x-coordinate and the y-coordinate of the pixel area in each of the called pictures according to Formula 1 and Formula 2 respectively; Wherein, Formula 1 is: x=threadIdx.x+blockIdx.x*blockDim.x; wherein, threadIdx.x is the x coordinate of the coordinate ID of the thread corresponding to the clipping coordinate, blockIdx.x is the x coordinate of the coordinate ID of the thread block to which the thread corresponding to the clipping coordinate belongs, and blockDim.x is the number of threads in the x direction of the thread block to which the thread corresponding to the clipping coordinate belongs; Formula 2 is: y=threadIdx.y+blockIdx.y*blockDim.y; wherein threadIdx.y is the y coordinate of the coordinate ID of the thread corresponding to the clipping coordinate, blockIdx.y is the y coordinate of the coordinate ID of the thread block to which the thread corresponding to the clipping coordinate belongs, and blockDim.y is the number of threads in the y direction of the thread block to which the thread corresponding to the clipping coordinate belongs.

5. A picture processing device, characterized in that: include: A graphics processor and a central processing unit; wherein: The graphics processor is used to execute the image processing method according to any one of claims 1 to 2; The central processing unit is used to send the image data to the graphics processing unit.

6. The image processing device according to claim 5, characterized in that: The central processing unit is also used to receive and save the clipping result.

Citation Information

Patent Citations

  • GPU image matting method

    CN106303162A