Image processing method and device, electronic equipment and storage medium
By reading the ROI data of YUV420 format images on the chip and extending it to even-sized areas for processing, the problem of low processing efficiency of YUV420 format images in odd-sized ROIs is solved, and efficient image processing is achieved.
Patent Information
- Application Number
- CN202410985780.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-22
- Publication Date
- 2024-09-10
AI Technical Summary
When processing odd-sized ROIs for YUV420 format images, the existing technology requires frequent format conversion, resulting in low image processing efficiency, and does not support odd-sized ROI processing.
On a chip integrating high-bandwidth memory HBM and on-chip cache GMB, the ROI data of the YUV420 format image is read to GMB, and the odd-sized ROI is expanded into an even-sized calculation area for data processing, and only written back The Y, U and V values within the ROI avoid the problem of HBM memory access out of bounds and directly process YUV420 format images.
It improves the image processing efficiency, reduces the number of visits, avoids the problem of HBM memory access out of bounds, and achieves efficient processing of YUV420 format images.
Smart Images

Figure CN118628338A
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to an image processing method, device, electronic device and storage medium. Background Art
[0002] Since the YUV420 format image shares 1 U and 1 V for every 2×2 Y color components, the minimum unit for YUV420 format modification is 4 Ys, 1 U and 1 V. YUV420 format images generally only support ROI processing of even sizes, but not odd sizes.
[0003] In the related art, for the case of odd ROI, it is necessary to first convert the YUV420 format image into an RGB or BGR image, then update the RGB / BGR image point by point, and then convert it back to the YUV420 format. This method requires multiple reading, writing and calculations for each pixel on the chip, resulting in low image processing efficiency. Summary of the invention
[0004] In view of this, the present application provides an image processing method, device, electronic device and storage medium, which can greatly improve the image processing efficiency.
[0005] To solve the above technical problems, the technical solution of this application is implemented as follows: In one embodiment, an image processing method is provided, which is applied to a chip integrated with a high bandwidth memory HBM and an on-chip cache GMB, and the method comprises: Determine a region of interest ROI of an image to be processed; the image to be processed is an image in YUV420 format; Read the image data corresponding to the ROI from the HBM to the GMB; If it is determined that the ROI is an odd-sized region, the ROI is expanded on the GMB to an even-sized region as a calculation region; if it is determined that the ROI is an even-sized region, the ROI region is used as the calculation region; Based on the minimum unit of YUV420 format, the image data corresponding to the calculation area on the GMB is processed respectively, and the Y, U and V values of the processing results located within the ROI are written back to the GMB; In response to the completion of the image data processing on the GMB, the image data on the GMB is written back to the HBM.
[0006] If it is determined that the ROI is an odd-sized region, the ROI is expanded on the GMB to an even-sized region as a calculation region, including: If it is determined that the length and / or the width of the ROI is an odd number, then the ROI is determined to be an odd-sized region; When the length of the ROI is an odd number, the ROI is expanded to the right to an even-sized area; When the width of the ROI is an odd number, the ROI is expanded downward to an even-sized area; When the length and width of the ROI are both odd numbers, the ROI is expanded to the lower right to become an even-sized area.
[0007] Wherein, after determining the ROI of the image to be processed and before reading the image data corresponding to the ROI from the HBM to the GMB, the method further comprises: If it is determined that the starting point of the ROI in the image to be processed is an odd point, the U / V starting from the even point closest to the starting point in the ROI is determined as the U / V data that needs to be processed on the GMB, and the Y in the ROI is determined to be the Y data that needs to be processed on the GMB; If it is determined that the starting point of the ROI in the image to be processed is an even point, it is determined that all Y, U, and V in the ROI are data that need to be processed on the GMB.
[0008] Among them, if the ROI is expanded on the GMB, the image data corresponding to the calculation area is the image data of the even-sized area; if the ROI is not expanded, the image data corresponding to the calculation area is the image data of the ROI.
[0009] The step of reading the image data corresponding to the ROI from the HBM to the GMB includes: Batch read the image data corresponding to the ROI from the HBM to the GMB; Writing the image data on the GMB back to the HBM includes: The image data on the GMB is written back to the HBM in batches.
[0010] Before determining the ROI of the image to be processed, the method further comprises: If it is determined that the image to be processed is not an image to be processed locally, the image to be processed is copied from the input memory of the HBM to the output memory.
[0011] Wherein, the method further comprises: In response to an input BGRA image, batch read the BGRA image from the HBM to the GMB; Separate the BGRA image on the GMB into a BGR image and a grayscale image of an Alpha value; wherein the size of the BGRA image is the same as the size of the ROI; Convert the BGR image to a YUV444 format image; The minimum unit based on the YUV420 format performs data processing on the image data on the GMB respectively, including: Based on the minimum unit of the YUV420 format and the grayscale image of the Alpha value, data fusion is performed on the image data corresponding to the ROI on the GMB and the image data corresponding to the YUV444 format image converted from the BGR image.
[0012] In another embodiment, an image processing device is provided, which is applied on a chip, and the device includes: High bandwidth memory HBM, used to store images to be processed and image data written back from the on-chip cache GMB; GMB, used to store image data corresponding to the region of interest ROI read from the HBM, image data corresponding to the even-sized region expanded from the ROI, and processing results; A calculation unit is used to determine the ROI of an image to be processed; the image to be processed is an image in YUV420 format; the image data corresponding to the ROI is read from the HBM to the GMB; if the ROI is determined to be an odd-sized area, the ROI is expanded to an even-sized area on the GMB as a calculation area; if the ROI is determined to be an even-sized area, the ROI area is used as the calculation area; based on the minimum unit of the YUV420 format, the image data corresponding to the calculation area on the GMB are respectively processed, and the Y, U and V values of the processing results located in the ROI are written back to the GMB; in response to the end of the image data processing on the GMB, the image data on the GMB is written back to the HBM.
[0013] In another embodiment, an electronic device is provided, including: Chips that integrate high-bandwidth memory HBM and on-chip cache GMB; a memory for storing executable instructions; The executable instructions are used to configure the chip to implement the image processing method.
[0014] In another embodiment, a computer-readable storage medium is provided. When at least one instruction in the computer-readable storage medium is executed by a chip of an electronic device, the electronic device can implement the image processing method.
[0015] It can be seen from the above technical solution that in the above embodiment, the image data corresponding to the ROI of the image to be processed in the format of YUV420 is read from the HBM to the GMB; in the case where the ROI is an odd-sized area, the ROI is expanded to an even-sized area on the GMB, and then the data is processed, and only the Y, U and V values of the processing results located in the ROI are written back to the GMB, and further written back from the GMB to the HBM to realize the processing of the YUV420 format image. This solution uses GMB to isolate the memory access during processing, avoiding the possible HBM memory access out-of-bounds problem; and because the YUV420 format image is directly processed, and the minimum unit of the YUV420 format is greatly reduced compared to the number of pixel elements of the same size RGB, therefore, the access volume is further reduced under the premise of only processing the ROI, and thus the solution can greatly improve the image processing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0017] Figure 1 It is a schematic diagram of the process of image processing for YUV420 format images in the related art; Figure 2 This is a schematic diagram of an image processing flow in an embodiment of the present application; Figure 3 This is a schematic diagram of an expansion of an ROI with an odd length in an embodiment of the present application; Figure 4 Schematic diagram of the expansion of an ROI with an odd width in an embodiment of the present application; Figure 5 This is a schematic diagram of an expansion of a ROI whose length and width are both odd numbers in an embodiment of the present application; Figure 6 This is a schematic diagram of an ROI with an odd-numbered starting point in an embodiment of the present application; Figure 7 This is another schematic diagram of an image processing flow in an embodiment of the present application; Figure 8 This is a schematic diagram of batch reading image data corresponding to ROI from HBM to GMB in an embodiment of the present application; Fig. 9 A schematic diagram of a process from obtaining an image to be processed to obtaining an image processing result in an embodiment of the present application; Fig.10 This is a schematic diagram of the image fusion processing flow in the embodiment of the present application; Fig.11 This is a schematic diagram of the structure of an image processing device in an embodiment of the present application; Fig.12 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0018] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0019] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe the order or precedence of the objects. It should be understood that the data used in this way can be interchanged where appropriate, so that the implementation of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0020] Since every 2×2 Y color components of a YUV420 format image share 1 U and 1 V, the minimum unit for YUV420 format modification is 4 Ys, 1 U, and 1 V. YUV420 format images generally only support ROI modification of even sizes, but not odd sizes.
[0021] For the case of odd-sized regions of interest (ROI) in the related art, see the specific image processing implementation. Figure 1 , Figure 1 The figure is a flowchart of image processing for YUV420 format images in the related art. Figure 1 For example, the YUV420 image is stored in YUV420 sp format. Figure 1 The area shown in the dotted box is ROI; first convert the YUV420 format image to BGR image, that is, convert all YUV to BGR; then process the ROI in the BGR image point by point, that is, convert each BGR in the ROI to BGR_n, and finally convert the processed BGR format image data back to YUV420 format image data, and each YUV_n corresponds to BGR_n.
[0022] In the specific implementation, the YUV420 format image can also be converted into an RGB image for related processing. Figure 1 Just take BGR as an example.
[0023] When converting RGB / BGR format images to YUV420 format images, the U and V values calculated by only the first pixel in the upper left corner of each 2×2 RGB / BGR are used as the U and V values shared by the 2×2 pixels in the YUV420 image. That is, for the YUV420 image, it can be regarded that the first pixel in the upper left corner of each 2×2 pixel determines the U / V value in its minimum unit. Therefore, only when the first pixel in the upper left corner of the 2×2 pixels is within the ROI area, the corresponding U / V value needs to be updated. Therefore, the YUV420 format image can be regarded as each 2×2 pixel only with the first pixel in the upper left corner with Y / U / V value, and the other three pixels only with Y value need to share the U / V value of the first pixel, so that the modification of ROI of odd size can be supported.
[0024] This implementation method requires multiple image format conversions on the AI chip, and each time all the data in the image needs to be converted in format. That is to say, although only the ROI needs to be processed, each pixel in the entire image needs to be read, written and calculated multiple times, resulting in low image processing efficiency and relatively poor operator performance.
[0025] Based on the above technical problems, an image processing method is provided in an embodiment of the present application, which is applied to a chip integrated with a high bandwidth memory (HBM) and an on-chip cache (GMB), and the image data corresponding to the ROI of the image to be processed in the format of YUV420 is read from the HBM to the GMB; in the case where the ROI is an odd-sized area, the ROI is expanded to an even-sized area on the GMB, and then the data is processed, and only the Y, U and V values of the processing result located in the ROI are written back to the GMB, and further written back from the GMB to the HBM to realize the processing of the YUV420 format image. This scheme uses GMB to isolate the memory access during processing, avoiding the possible HBM memory access out-of-bounds problem; and because the YUV420 format image is directly processed, and the minimum unit of the YUV420 format is greatly reduced compared to the number of pixel elements of the same size RGB, therefore, the access volume is further reduced under the premise of only processing the ROI, and thus the scheme can greatly improve the image processing efficiency.
[0026] Among them, the minimum unit of the YUV420 format includes 6 pixel elements (4 Y, 1 U and 1 V), and the same size RGB includes 12 pixel elements (4 R, 4 G and 4 B).
[0027] The following is a detailed description of the image processing process in the embodiment of the present application in conjunction with the accompanying drawings.
[0028] See also Figure 2 , Figure 2 This is a schematic diagram of an image processing flow in an embodiment of the present application. The specific steps are: Step 201, determining the ROI of the image to be processed; the image to be processed is an image in YUV420 format.
[0029] In the embodiment of the present application, there is no limitation on the specific implementation method of determining the ROI of the image to be processed, and any implementation method in the related art may be used.
[0030] Step 202: read the image data corresponding to the ROI from the HBM to the GMB.
[0031] Step 203: If it is determined that the ROI is an odd-sized region, the ROI is expanded on the GMB to an even-sized region as a calculation region. Execute step 205.
[0032] Step 204: If it is determined that the ROI is an even-sized region, the ROI region is used as the calculation region.
[0033] Step 205 , based on the minimum unit of the YUV420 format, the image data corresponding to the calculation area on the GMB are processed respectively, and the Y, U and V values of the processing results located within the ROI are written back to the GMB.
[0034] If the ROI is extended on the GMB, the image data corresponding to the calculation area in this step is the image data of the even-sized area; if the ROI is not extended, the image data corresponding to the calculation area in this step is the image data of the ROI.
[0035] When processing image data on the GMB, processing results may exceed the ROI. In the specific implementation, only the Y, U, and V values of the processing results within the ROI are written back to the GMB, that is, the Y, U, and V values outside the ROI are directly discarded.
[0036] Step 206: In response to the completion of the image data processing on the GMB, the image data on the GMB is written back to the HBM.
[0037] In this embodiment, the image data corresponding to the ROI of the image to be processed in the format of YUV420 is read from the HBM to the GMB; in the case where the ROI is an odd-sized area, the ROI is expanded to an even-sized area on the GMB; then the data is processed, and only the Y, U, and V values of the processing results located within the ROI are written back to the GMB, and further written back to the HBM from the GMB. In this solution, the on-chip memory GMB is used to isolate the memory access during processing, avoiding the possible HBM memory access out-of-bounds problem; and because the YUV420 format image is directly processed, and the minimum unit of the YUV420 format is greatly reduced compared to the number of pixel elements of the same size RGB, therefore, the access volume is further reduced under the premise of only processing the ROI, and thus the solution greatly improves the image processing efficiency.
[0038] The specific implementation method of GMB out-of-bounds memory access in the present application embodiment is not limited, and any method that can be implemented in software or hardware driver related technologies can be used. The value read out of bounds by GMB does not affect the output image data on the final HBM.
[0039] In step 203, the odd-sized ROI may be expanded to an even-sized region according to a preset rule, wherein the preset rule may be to expand toward the lower right corner. The specific implementation of the expansion may be: If the length and / or width of the ROI is determined to be an odd number, the ROI is determined to be an odd-sized region; When the length of the ROI is an odd number, expand the ROI to the right to an even-sized area; When the width of the ROI is an odd number, expand the ROI downward to an even-sized area; When the length and width of the ROI are both odd numbers, the ROI is expanded to the lower right to an even-sized area.
[0040] Combined with the attached figures, odd-numbered ROIs in different situations and the corresponding expansion situations are given. Figure 3 It is a schematic diagram of expanding a ROI with an odd length in an embodiment of the present application. Figure 4 It is a schematic diagram of expanding a ROI with an odd width in an embodiment of the present application. Figure 5 This is a schematic diagram of the expansion of a ROI whose length and width are both odd numbers in an embodiment of the present application.
[0041] in, Figure 3 The left image in the middle shows an ROI with an odd length through a dotted box, and the right image shows an ROI that is extended to an even-sized area through a dotted box.
[0042] Figure 4 The left image in the middle shows an ROI with an odd width through a dotted box, and the right image shows an ROI that is expanded to an even-sized area through a dotted box.
[0043] Figure 5 The left image in the middle shows an ROI whose length and width are both odd numbers by a dotted box, and the right image shows an ROI that is expanded to an even-sized area by a dotted box.
[0044] For the case where the ROI also has odd and even starting points, the starting point coordinates of the ROI are established with the first pixel in the upper left corner of the image to be processed as the (0, 0) point. The starting point of the ROI is an odd point, which means that the x or y coordinates of the first pixel in the upper left corner of the ROI relative to the first pixel in the upper left corner of the image to be processed are odd. The starting point of the ROI is an even point, which means that the x and y coordinates of the first pixel in the upper left corner of the ROI relative to the first pixel in the upper left corner of the image to be processed are both even.
[0045] If the starting point of the ROI is an even-numbered point, no additional processing is performed. If the starting point of the ROI is an odd-numbered point, after determining the ROI of the image to be processed and before reading the image data corresponding to the ROI from the HBM to the GMB, the following steps are further performed: If it is determined that the starting point of the ROI in the image to be processed is an odd point, the U / V starting from the even point closest to the starting point in the ROI is determined as the U / V data that needs to be processed on the GMB; and it is determined that the Y data in the ROI are all Y data that need to be processed on the GMB, that is, the Y data has nothing to do with whether the starting point of the ROI in the image to be processed is an odd point or an even point, and they are all data to be processed on the GMB.
[0046] If it is determined that the starting point of the ROI in the image to be processed is an even point, it is determined that all Y, U, and V in the ROI are data to be processed on the GMB.
[0047] See also Figure 6 , Figure 6 This is a schematic diagram of an ROI with an odd-numbered starting point in an embodiment of the present application. Figure 6 The area shown in the dotted box is the ROI area, and the ROI area is an area with an odd-numbered starting point. The U / V therein are all within the U / V starting from the even-numbered point closest to the starting point in the ROI. Therefore, it is determined that the Y, U, and V in the ROI area are all data that need to be processed on the GMB.
[0048] In the embodiment of the present application, the image data in the ROI can be read from the HBM to the GMB line by line, or in batches; the image data on the GMB can be written back to the HBM from the GMB line by line, or in batches. The specific implementation process of batch reading and writing back to realize image processing in the embodiment of the present application is given in Figure 7 , Figure 7 This is another image processing flow diagram in the embodiment of the present application. The specific steps are: Step 701, determining the ROI of the image to be processed; the image to be processed is an image in YUV420 format.
[0049] In the embodiments of the present application, there is no limitation on the specific implementation method of determining the ROI of the image to be processed, and any implementation method in the related art may be used.
[0050] Step 702: Read the image data corresponding to the ROI from the HBM to the GMB in batches.
[0051] The batch reading in this step refers to reading all image data from the address where the first data in the ROI is located to the address where the last data in the ROI is located from the HBM to the GMB.
[0052] See also Figure 8 , Figure 8 This is a schematic diagram of batch reading image data corresponding to ROI from HBM to GMB in an embodiment of the present application. Figure 8 The dotted box in the left figure shows the ROI, and the YUV data shown in the right figure is the data read from the HBM to the GMB in batches. Figure 8 It can be seen that the data read in batches are data with continuous addresses, so the image data read on the GMB is more than the image data corresponding to the ROI; however, the data that needs to be processed is still the data related to the ROI.
[0053] Step 703: If it is determined that the ROI is an odd-sized region, the ROI is expanded on the GMB to an even-sized region as a calculation region. Execute step 705.
[0054] Step 704: If the ROI is an even-sized region, the ROI region is used as the calculation region.
[0055] Step 705 , based on the minimum unit of the YUV420 format, the image data corresponding to the calculation area on the GMB are processed respectively; and the Y, U and V values of the processing results located within the ROI are written back to the GMB.
[0056] If the ROI is extended on the GMB, the image data corresponding to the calculation area is the image data of the even-sized area; if the ROI is not extended, the image data corresponding to the calculation area is the image data of the ROI.
[0057] Although the data on the GMB read in batches exceeds the ROI, in the specific implementation, the related YUV data read beyond the ROI is not processed.
[0058] When processing data on the GMB, the processing results may exceed the ROI. In the specific implementation, only the Y, U, and V values of the processing results within the ROI are written back to the GMB, that is, the Y, U, and V values outside the ROI are directly discarded.
[0059] Step 706 , in response to completion of the image data processing on the GMB, the image data on the GMB are written back to the HBM in batches.
[0060] In this step, when writing the image data on the GMB back to the HBM in batches, similar to batch reading, not only the processing results corresponding to the ROI are written back, but also the images outside the ROI previously read on the GMB are written back to the same address position on the HBM; in this way, the YUV data outside the ROI is not processed, so it is still written back to the original position on the HBM according to the original value.
[0061] In the embodiment of the present application, the image data corresponding to the ROI of the image to be processed in the format of YUV420 is read from the HBM to the GMB; in the case where the ROI is an odd-sized area, the ROI is expanded to an even-sized area on the GMB, and then the data is processed, and only the Y, U and V values of the processing results located in the ROI are written back to the GMB, and further written back from the GMB to the HBM to realize the processing of the YUV420 format image. This scheme uses GMB to isolate the memory access during processing, avoiding the possible HBM memory access out-of-bounds problem; and because the YUV420 format image is directly processed, and the minimum unit of the YUV420 format is greatly reduced compared to the number of pixel elements of RGB of the same size, therefore, the access volume is further reduced under the premise of processing only the ROI, and then the scheme can greatly improve the image processing efficiency; and in this embodiment, the image data corresponding to the ROI is also read in batches, and the processing results corresponding to the ROI are written back in batches; it can greatly improve the reading and writing speed.
[0062] The specific implementation method of GMB out-of-bounds memory access in the present application embodiment is not limited, and any method that can be implemented in software or hardware driver related technologies can be used. The value read out of bounds by GMB does not affect the output image data on the final HBM.
[0063] In the embodiment of the present application, before processing the image to be processed, it is necessary to determine whether the image to be processed is an inplace image to determine whether to copy data between different memories of the HBM. Fig. 9 , Fig. 9 This is a flow chart of the process from obtaining the image to be processed to obtaining the image processing result in the embodiment of the present application. The specific steps are: Step 901, obtaining an image to be processed.
[0064] Step 902 , determining whether the image to be processed is an image to be processed in situ, if yes, executing step 904 ; otherwise, executing step 903 .
[0065] Step 903: copy the image to be processed from the input memory of the HBM to the output memory.
[0066] Step 904, determining the ROI of the image to be processed; the image to be processed is an image in YUV420 format.
[0067] In the embodiment of the present application, there is no limitation on the specific implementation method of determining the ROI of the image to be processed, and any implementation method in the related art may be used.
[0068] Step 905 , determining whether the starting point of the ROI in the image to be processed is an odd point, if yes, executing step 906 , otherwise, executing step 907 .
[0069] Step 906: determine the U / V starting from the even-numbered point closest to the starting point in the ROI as the U / V data to be processed on the GMB; and determine that all Y in the ROI are data to be processed on the GMB. Execute step 908.
[0070] In this step, the U / V starting from the even-numbered point closest to the starting point in the ROI is determined as the U / V data that needs to be processed on the GMB, that is, the other U / Vs are determined as the U / V data that does not need to be processed on the GMB; and all Y in the ROI are data to be processed on the GMB; Step 907, determine that the Y, U, and V in the ROI are all data to be processed on the GMB.
[0071] For ROIs whose starting point is an even-numbered point, it is determined that all Y, U, and Y in the ROI are data that need to be processed on the GMB.
[0072] The operations in step 906 and step 907 are to determine the YUV processed on the GMB, but do not affect the batch reading of the data corresponding to the ROI.
[0073] Step 908: Read the image data corresponding to the ROI from the HBM to the GMB in batches.
[0074] The batch reading in this step refers to reading all image data from the address of the first data in the ROI to the address of the last data in the ROI from the HBM to the GMB; it can be seen that the image data to be processed on the GMB is less than or equal to the image data batch read to the GMB.
[0075] Step 909: If it is determined that the ROI is an odd-sized region, the ROI is expanded on the GMB to an even-sized region as a calculation region. Execute step 911.
[0076] In this step, the ROI is expanded to an even-sized area on the GMB, and the odd-sized ROI can be expanded to an even-sized area according to a preset rule, wherein the preset rule can be expanded to the lower right corner. The specific expansion can be: If the length and / or width of the ROI is determined to be an odd number, the ROI is determined to be an odd-sized region; When the length of the ROI is an odd number, expand the ROI to the right to an even-sized area; When the width of the ROI is an odd number, expand the ROI downward to an even-sized area; When the length and width of the ROI are both odd numbers, the ROI is expanded to the lower right to an even-sized area.
[0077] Step 910: If the ROI is an even-sized region, the ROI region is used as the calculation region.
[0078] Step 911, based on the minimum unit of the YUV420 format, the image data corresponding to the calculation area on the GMB are processed respectively; and the Y, U and V values of the processing results located in the ROI are written back to the GMB.
[0079] If the ROI is extended on the GMB, the image data corresponding to the calculation area is the image data of the even-sized area; if the ROI is not extended, the image data corresponding to the calculation area is the image data of the ROI.
[0080] When processing image data on the GMB, processing results may exceed the ROI. In the specific implementation, only the Y, U, and V values of the processing results within the ROI are written back to the GMB, that is, the Y, U, and V values outside the ROI are directly discarded.
[0081] Step 912: In response to the completion of the image data processing on the GMB, the image data on the GMB are written back to the HBM in batches.
[0082] In this step, when writing the image data on the GMB back to the HBM in batches, similar to batch reading, not only the processing results corresponding to the ROI are written back, but also the images outside the ROI previously read on the GMB are written back to the same address position on the HBM. In this way, the YUV data outside the ROI is not processed, so it is still written back to the original position on the HBM according to the original value.
[0083] In the embodiment of the present application, the image to be processed in the YUV420 format which is not processed in situ is first copied from the input memory of the HBM to the output memory, and then the data in the ROI that needs to be processed on the GMB is determined according to the starting point of the ROI in the image to be processed; the image data corresponding to the ROI is read from the HBM to the GMB in batches; in the case where the ROI is an odd-sized area, the ROI is expanded to an even-sized area on the GMB; then the data is processed, and only the Y, U and V values of the processing results located in the ROI are written back to the GMB, and further written back to the HBM in batches from the GMB. In this scheme, the ROI is processed specifically by the odd number of the starting point and the odd number of the ROI, and the related processing is based on the reading and writing of the GMB, so as to avoid the HBM memory access out-of-bounds problem of the last row or last column data of the odd ROI; the direct processing of the image data in the YUV420 format is realized; and the number of pixel elements of the minimum unit of the YUV420 format is greatly reduced compared with the same size of RGB. Therefore, under the premise of processing only the ROI, the access volume is further reduced, and thus the scheme greatly improves the image processing efficiency; and in this embodiment, the image data corresponding to the ROI is read in batches, and the processing results corresponding to the ROI are written back in batches; the reading and writing rates can be greatly improved.
[0084] The processing of the image in the embodiment of the present application may be the processing of one image or the fusion processing of two images. Taking the image fusion processing as an example, the specific process of implementing the image processing in the embodiment of the present application is given below.
[0085] The images to be fused are a BGRA image and a YUV420 format image; the ROI to be fused will be specified in the YUV420 format image; that is, the BGRA image is fused with the ROI in the YUV420 format image, and the size of the ROI is the same as that of the BGRA image.
[0086] If the YUV420 format image is an image processed locally, the fusion processing is directly performed on the memory where the input YUV420 format image is located; if it is not an image processed locally, the YUV420 format image is copied from the input memory of the HBM to the output memory for image fusion processing.
[0087] See also Fig.10 , Fig.10 Schematic diagram of the image fusion processing flow in the embodiment of the present application. Fig.10 First, in response to the input BGRA image, the BGRA image is batch-read from the HBM to the GMB.
[0088] Secondly, the BGRA image on the GMB is separated into a BGR image and a grayscale image of an alpha value; wherein the size of the BGRA image is the same as the size of the ROI; and the BGR image is converted into a YUV444 format image.
[0089] Since calculation or format conversion is to read, process, and write back one or a few pixels at a time, all data is moved from the farther HBM to the closer GMB in batches, so that discrete reading and writing back will be much faster. Therefore, in the embodiment of the present application, the BGRA image HBM is read in batches to the GMB for separation, format conversion, etc.; but this is only an example, and the processing of BGRA in the specific implementation is not limited to this.
[0090] Then, the ROIs of the YUV420 format images are read from the HBM to the GMB in batches.
[0091] After that, based on the grayscale image of the smallest unit of the YUV420 format according to the Alpha value, the image data corresponding to the ROI on the GMB and the image data corresponding to the YUV444 format image converted by the BGR image are respectively fused. The YUV444 format image data participates in the data fusion calculation only when the corresponding Y, U, and V values exist in the ROI of the corresponding YUV420 format image. Therefore, the UV value in the ROI of the YUV420 format image is only fused with the UV value of the YUV444 format image corresponding to its position. In this way, the UV in the YUV420 can be more accurately fused with the UV in the YUV444 with the same position.
[0092] The fusion formula for fusion can be: fusion result = YUV444 format image × Alpha / maxDateValue + ROI of YUV420 format image × (1 - Alpha / maxDateValue); The value of maxDateValue is determined according to the data type. For example, if the image data type is U8, that is, an 8-bit unsigned integer, then maxDateValue=255.
[0093] Finally, the Y, U and V values of the fusion result located within the ROI are written back to the GMB; and in response to the completion of the image fusion processing on the GMB, the image data on the GMB are written back to the HBM in batches.
[0094] Writing back to HBM in this step means writing the fusion result back to the YUV420 format image to obtain a fused image.
[0095] In the embodiment of the present application, the execution flow of the interface for directly processing the YUV420 image is simple, and the amount of read and write processing data is less than that of the RGB image; GMB is used to continuously read and write HBM in batches, and the data continuity and memory access efficiency are higher; on-chip memory GMB is used to isolate memory access during processing, avoiding possible HBM memory access out-of-bounds problems, and the parity ROI code implementation is more unified, and the processing efficiency is higher than other image processing methods.
[0096] The YUV, RGB, BGR, BGRA and grayscale in the embodiments of the present application are all data formats well known to those skilled in the art.
[0097] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present disclosure, and will not be described in detail here.
[0098] Based on the same inventive concept, an image processing device is also provided in the embodiment of the present application, which is applied on a chip. Fig.11 , Fig.11 This is a schematic diagram of the structure of an image processing device in an embodiment of the present application. The device includes: HBM1101, used to store images to be processed and image data written back from GMB; GMB1102, used to store the image data corresponding to the region of interest ROI read from the HBM, the image data corresponding to the even-sized region where the ROI is extended, and the processing results; The calculation unit 1103 is used to determine the ROI of the image to be processed; the image to be processed is an image in YUV420 format; the image data corresponding to the ROI is read from the HBM to the GMB; if the ROI is determined to be an odd-sized area, the ROI is expanded to an even-sized area on the GMB as a calculation area; if the ROI is determined to be an even-sized area, the ROI area is used as the calculation area; based on the minimum unit of the YUV420 format, the image data corresponding to the calculation area on the GMB are processed respectively, and the Y, U and V values of the processing results located in the ROI are written back to the GMB; in response to the end of the image data processing on the GMB, the image data on the GMB is written back to the HBM.
[0099] In another embodiment, The calculation unit 1103 is specifically used for, if it is determined that the ROI is an odd-sized region, then expanding the ROI to an even-sized region. If it is determined that the length and / or width of the ROI is an odd number, then the ROI is determined to be an odd-sized region; when the length of the ROI is an odd number, the ROI is expanded rightward to an even-sized region; when the width of the ROI is an odd number, the ROI is expanded downward to an even-sized region; when the length and width of the ROI are both odd numbers, the ROI is expanded downward to an even-sized region.
[0100] In another embodiment, The calculation unit 1103 is further used to determine the ROI of the image to be processed, and then read the image data corresponding to the ROI from the HBM to the GMB. If it is determined that the starting point of the ROI in the image to be processed is an odd point, the U / V starting from the even point closest to the starting point in the ROI is determined as the U / V data that needs to be processed on the GMB, and it is determined that all Y in the ROI is the Y data that needs to be processed on the GMB; if it is determined that the starting point of the ROI in the image to be processed is an even point, it is determined that all Y, U, and V in the ROI are data that need to be processed on the GMB.
[0101] In another embodiment, if the ROI is expanded on the GMB, the image data corresponding to the calculation area is the image data of the even-sized area; if the ROI is not expanded, the image data corresponding to the calculation area is the image data of the ROI.
[0102] In another embodiment, The calculation unit 1103 is specifically used to batch read the image data corresponding to the ROI from the HBM to the GMB when reading the image data corresponding to the ROI from the HBM to the GMB; and batch write the image data on the GMB back to the HBM when writing the image data on the GMB back to the HBM.
[0103] In another embodiment, The calculation unit 1103 is further configured to, before determining the ROI of the image to be processed, copy the image to be processed from the input memory of the HBM to the output memory if it is determined that the image to be processed is not an image to be processed in situ.
[0104] In another embodiment, The calculation unit 1103 is further used to respond to the input BGRA image, batch read the BGRA image from the HBM to the GMB; separate the BGRA image on the GMB into a BGR image and a grayscale image of an Alpha value; wherein the size of the BGRA image is the same as the size of the ROI; convert the BGR image into a YUV444 format image; when performing data processing on the image data on the GMB based on the minimum unit of the YUV420 format, perform data fusion on the image data corresponding to the ROI on the GMB and the image data corresponding to the YUV444 format image converted from the BGR image based on the grayscale image of the Alpha value based on the minimum unit of the YUV420 format.
[0105] The units in the above-mentioned embodiments may be integrated into one body or deployed separately; they may be combined into one unit or further divided into multiple sub-units.
[0106] Fig.12 It is a structural diagram of an electronic device provided in an embodiment of the present application. The electronic device 1200 may have relatively large differences due to different configurations or performances, and may include one or more memories 1201 for storing executable instructions and a chip 1202 integrated with GMB and HBM, wherein the memory 1201 stores at least one program code, and the at least one program code is loaded and executed by the chip 1202 to implement the image processing methods provided in the above-mentioned embodiments. Of course, the electronic device 1200 may also have components such as a wired or wireless network interface, a keyboard, and an input and output interface for input and output. The electronic device 1200 may also include other components for implementing device functions, which will not be repeated here.
[0107] In an exemplary embodiment, a computer-readable storage medium including at least one instruction is also provided. When the at least one instruction in the computer-readable storage medium is executed by a chip of an electronic device, the electronic device can implement the image processing method provided by the above-mentioned embodiments.
[0108] Optionally, the above-mentioned computer-readable storage medium may be a non-temporary computer-readable storage medium, for example, the non-temporary computer-readable storage medium may include ROM (Read-Only Memory), RAM (Random-Access Memory), CD-ROM (Compact Disc Read-Only Memory), magnetic tape, floppy disk and optical data storage device, etc.
[0109] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0110] The flow chart and block diagram in the accompanying drawings of the present application show the possible architecture, function and operation of the system, method and computer program product according to the various embodiments disclosed in the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the above-mentioned module, program segment or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the box can also occur in the order of the standards in different figures. For example, the boxes represented by two connections can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0111] Those skilled in the art will appreciate that the features described in the various embodiments and / or claims disclosed in this application may be combined and / or combined in a variety of ways, even if such combinations and / or combinations are not explicitly described in this application. In particular, without departing from the spirit and teachings of this application, the features described in the various embodiments and / or claims of this application may be combined and / or combined in a variety of ways, and all of these combinations and / or combinations fall within the scope disclosed in this application.
[0112] Specific embodiments are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core ideas, and is not used to limit the present application. For those skilled in the art, changes can be made in the specific implementation methods and application scopes according to the ideas, spirits and principles of the present invention, and any modifications, equivalent substitutions, improvements, etc. made therein should be included in the scope of protection of this application.
Claims
1. An image processing method, It is characterized in that Applied to a chip integrating a high bandwidth memory HBM and an on-chip cache GMB, the method comprises: Determine a region of interest ROI of an image to be processed; the image to be processed is an image in YUV420 format; Read the image data corresponding to the ROI from the HBM to the GMB; If it is determined that the ROI is an odd-sized region, the ROI is expanded on the GMB to an even-sized region as a calculation region; if it is determined that the ROI is an even-sized region, the ROI region is used as the calculation region; Based on the minimum unit of YUV420 format, the image data corresponding to the calculation area on the GMB is processed respectively, and the Y, U and V values of the processing results located within the ROI are written back to the GMB; In response to the completion of the image data processing on the GMB, the image data on the GMB is written back to the HBM.
2. The method according to claim 1, It is characterized in that If it is determined that the ROI is an odd-sized region, the ROI is expanded on the GMB to an even-sized region as a calculation region, including: If it is determined that the length and / or the width of the ROI is an odd number, then the ROI is determined to be an odd-sized region; When the length of the ROI is an odd number, the ROI is expanded to the right to an even-sized area; When the width of the ROI is an odd number, the ROI is expanded downward to an even-sized area; When the length and width of the ROI are both odd numbers, the ROI is expanded to the lower right to become an even-sized area.
3. The method according to claim 1, It is characterized in that After determining the ROI of the image to be processed and before reading the image data corresponding to the ROI from the HBM to the GMB, the method further includes: If it is determined that the starting point of the ROI in the image to be processed is an odd point, the U / V starting from the even point closest to the starting point in the ROI is determined as the U / V data that needs to be processed on the GMB, and the Y in the ROI is determined to be the Y data that needs to be processed on the GMB; If it is determined that the starting point of the ROI in the image to be processed is an even point, it is determined that all Y, U, and V in the ROI are data that need to be processed on the GMB.
4. The method according to claim 1, It is characterized in that If the ROI is extended on the GMB, the image data corresponding to the calculation area is the image data of the even-sized area; if the ROI is not extended, the image data corresponding to the calculation area is the image data of the ROI.
5. The method according to claim 1, It is characterized in that The step of reading the image data corresponding to the ROI from the HBM to the GMB includes: Batch read the image data corresponding to the ROI from the HBM to the GMB; Writing the image data on the GMB back to the HBM includes: The image data on the GMB is written back to the HBM in batches.
6. The method according to claim 1, It is characterized in that Before determining the ROI of the image to be processed, the method further comprises: If it is determined that the image to be processed is not an image to be processed locally, the image to be processed is copied from the input memory of the HBM to the output memory.
7. The method according to any one of claims 1 to 6, It is characterized in that The method further comprises: In response to an input BGRA image, batch read the BGRA image from the HBM to the GMB; Separate the BGRA image on the GMB into a BGR image and a grayscale image of an Alpha value; wherein the size of the BGRA image is the same as the size of the ROI; Convert the BGR image to a YUV444 format image; The minimum unit based on the YUV420 format performs data processing on the image data on the GMB respectively, including: Based on the grayscale image of the Alpha value in the minimum unit of the YUV420 format, data fusion is performed on the image data corresponding to the ROI on the GMB and the image data corresponding to the YUV444 format image converted from the BGR image.
8. An image processing device, applied on a chip, It is characterized in that The device comprises: High bandwidth memory HBM, used to store images to be processed and image data written back from the on-chip cache GMB; GMB, used to store image data corresponding to the region of interest ROI read from the HBM, image data corresponding to the even-sized region expanded from the ROI, and processing results; A calculation unit is used to determine the ROI of an image to be processed; the image to be processed is an image in YUV420 format; the image data corresponding to the ROI is read from the HBM to the GMB; if the ROI is determined to be an odd-sized area, the ROI is expanded to an even-sized area on the GMB as a calculation area; if the ROI is determined to be an even-sized area, the ROI area is used as the calculation area; based on the minimum unit of the YUV420 format, the image data corresponding to the calculation area on the GMB are respectively processed, and the Y, U and V values of the processing results located in the ROI are written back to the GMB; in response to the end of the image data processing on the GMB, the image data on the GMB is written back to the HBM.
9. An electronic device, It is characterized in that include: Chips that integrate high-bandwidth memory HBM and on-chip cache GMB; a memory for storing executable instructions; The executable instructions are used to configure the chip to implement the image processing method according to any one of claims 1 to 7.
10. A computer-readable storage medium, It is characterized in that When at least one instruction in the computer-readable storage medium is executed by a chip of an electronic device, the electronic device is enabled to implement the image processing method according to any one of claims 1 to 7.
Citation Information
Cited By
Video coding device, video decoding device, video coding method, and video decoding method
WO2026088862A1
