Data writing method and apparatus
By dividing the image processing into valid and invalid storage areas and writing preset data into the invalid area, the problem of image data overlay is solved, and the accuracy of image processing is improved.
Patent Information
- Application Number
- CN202210785297.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-05
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2042-07-05
AI Technical Summary
In the process of image processing, the phenomenon of image data superposition leads to a decrease in the accuracy of image processing, and existing technologies have not been able to effectively solve this problem.
By obtaining the parameters of the original image and the preset storage area, the target parameters are determined, the valid and invalid storage areas are divided, and the preset data is written into the invalid area to avoid image data superposition.
It effectively avoids the problem of image data overlay and improves the accuracy of image processing.
Smart Images

Figure CN115049533B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing, and more specifically, to a data writing method and apparatus. Background Technology
[0002] In the field of image processing, image preprocessing is a crucial step. Image preprocessing can improve the accuracy and speed of image processing. For example, images are typically preprocessed before being processed by neural network models.
[0003] Image scaling is an image preprocessing method that involves scaling, color space conversion, mean subtraction, normalization, and other operations on the original image before writing the image data to a destination address. However, the width and height of the images obtained after scaling are usually different. In this case, the image data at the edges of the previous frame written to the destination address will be superimposed on the image data of the next and subsequent frames (the image data written to the destination address cannot completely cover the image data of the previous frame, causing the edges of the preprocessed image data of the previous frame to be superimposed on the preprocessed image data of several subsequent frames). For example, if the width and height of the previous frame written to the destination address are W1 and H1, and the width and height of the next frame are W2 and H2, assuming W1 is greater than W2 (or H1 is greater than H2), then the image data at the edges of the previous frame will be superimposed on the image data of the next and subsequent frames, resulting in image data superposition. This image data superposition phenomenon affects the accuracy of image processing.
[0004] There is currently no effective solution to the above problems. Summary of the Invention
[0005] This invention provides a data writing method and apparatus to at least solve the problem of image data overlay when writing image data in related technologies.
[0006] According to an embodiment of the present invention, a data writing method is provided, comprising: acquiring original image parameters of an original image and preset storage parameters of a preset storage area; determining target parameters based on the original image parameters and the preset storage parameters; determining a valid storage area in the preset storage area using the target parameters, and writing image data processed from the original image into the valid storage area; and writing preset data into the invalid storage area if an invalid storage area exists in the preset storage area, wherein the invalid storage area is a storage area in the preset storage area other than the valid storage area.
[0007] In one exemplary embodiment, obtaining original image parameters and preset storage parameters of a preset storage area includes: obtaining the width and height of the original image, and the preset storage width and preset storage height of the preset storage area; determining target parameters based on the original image parameters and the preset storage parameters includes: determining a target scaling ratio based on the width and height of the original image, and the preset storage width and preset storage height; wherein the original image parameters include the width and height of the original image, the preset storage parameters include the preset storage width and the preset storage height, and the target parameters include the target scaling ratio.
[0008] In one exemplary embodiment, determining the target scaling ratio based on the width and height of the original image, as well as the preset storage width and the preset storage height, includes: determining an original width scaling ratio based on the width of the original image and the preset storage width; determining an original height scaling ratio based on the height of the original image and the preset storage height; and determining the target scaling ratio as the maximum value of the original width scaling ratio and the original height scaling ratio.
[0009] In an exemplary embodiment, determining the effective storage area in the preset storage area using the target parameters includes: determining the effective storage width and effective storage height in the preset storage area based on the target scaling ratio, the width of the original image, and the height of the original image; and determining the effective storage area using the effective storage width and the effective storage height, as well as the preset storage width and the preset storage height.
[0010] In an exemplary embodiment, when an invalid storage area exists in the preset storage area, writing preset data in the invalid storage area includes: obtaining the starting offset position of the target work item; and when the starting offset position is located in the invalid storage area, writing the preset data in the invalid storage area through the target work item.
[0011] In one exemplary embodiment, writing preset data in the invalid storage area includes: writing data 0 in the invalid storage area, wherein the preset data includes data 0; or writing other preset data in the invalid storage area, wherein the other preset data is data other than 0.
[0012] In one exemplary embodiment, writing the processed image data of the original image into the effective storage area includes: scaling the original image to obtain a scaled image by means of the target scaling ratio when the target parameter is a target scaling ratio; and writing the image data of the scaled image into the effective storage area.
[0013] In one exemplary embodiment, writing the processed image data of the original image into the effective storage area includes: scaling the original image to obtain a scaled image by means of the target scaling ratio when the target parameter is a target scaling ratio; performing image processing on the scaled image to obtain a target image; and writing the image data of the target image into the effective storage area.
[0014] According to another embodiment of the present invention, a data writing device is provided, comprising: an acquisition module for acquiring original image parameters of an original image and preset storage parameters of a preset storage area; a determination module for determining target parameters based on the original image parameters and the preset storage parameters; a first writing module for determining a valid storage area in the preset storage area using the target parameters and writing image data processed from the original image into the valid storage area; and a second writing module for writing preset data into the invalid storage area if an invalid storage area exists in the preset storage area, wherein the invalid storage area is a storage area in the preset storage area other than the valid storage area.
[0015] According to yet another embodiment of the present invention, a computer-readable storage medium is also provided, wherein a computer program is stored therein, wherein the computer program, when executed by a processor, implements the steps of the method described in any of the preceding claims.
[0016] According to yet another embodiment of the present invention, an electronic device is also provided, including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the steps in any of the above method embodiments.
[0017] Through this invention, for each frame of original image written to the preset storage area corresponding to the destination address, the target parameters are determined by the original image parameters and the preset storage parameters. Based on the target parameters, the effective storage area is determined in the preset storage area. The image data after processing of the original image is written in the effective storage area. Preset data is written in the invalid storage area of the preset storage area.
[0018] For the original image currently being written to the preset storage area, its image data is written to the valid storage area of the preset storage area, while the invalid storage area in the preset storage area is written to preset data. This avoids the edge parts of the previous frame image data or the previous few frames image data from being superimposed on the data of the original image currently being written to the preset storage area, thus avoiding the problem of image data superposition when writing image data in related technologies. Therefore, the problem of image data superposition when writing image data can be solved, thereby achieving the effect of improving the accuracy of image processing. Attached Figure Description
[0019] Figure 1 This is a hardware structure block diagram of a mobile terminal for a data writing method according to an embodiment of the present invention;
[0020] Figure 2 This is a flowchart of a data writing method according to an embodiment of the present invention;
[0021] Figure 3 This is an overall flowchart of a data writing method according to an embodiment of the present invention;
[0022] Figure 4 This is a schematic diagram of writing image data into a preset storage area according to an embodiment of the present invention;
[0023] Figure 5 This is a schematic diagram of writing image data into a preset storage area according to another embodiment of the present invention;
[0024] Figure 6 This is a structural block diagram of a data writing device according to an embodiment of the present invention. Detailed Implementation
[0025] The embodiments of the present invention will be described in detail below with reference to the accompanying drawings and examples.
[0026] It should be noted that the terms "first," "second," etc., in the specification, claims, and drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0027] The methods and embodiments provided in this application can be executed on a mobile terminal, computer terminal, or similar computing device. Taking running on a mobile terminal as an example, Figure 1 This is a hardware structure block diagram of a mobile terminal for a data writing method according to an embodiment of the present invention. Figure 1 As shown, a mobile terminal may include one or more ( Figure 1Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing data are also shown. The mobile terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the mobile terminal described above. For example, the mobile terminal may also include components that are more... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0028] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the data writing method in this embodiment of the invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, thus implementing the above-described method. The memory 104 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the mobile terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0029] The transmission device 106 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the mobile terminal's communication provider. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module used for wireless communication with the Internet.
[0030] This embodiment provides a method for writing data to the aforementioned mobile terminal. Figure 2 This is a flowchart of a data writing method according to an embodiment of the present invention, such as... Figure 2 As shown, the process includes the following steps:
[0031] Step S202: Obtain the original image parameters of the original image and the preset storage parameters of the preset storage area;
[0032] Step S204: Determine the target parameters based on the original image parameters and the preset storage parameters;
[0033] Step S206: Determine an effective storage area in the preset storage area using the target parameters, and write the processed image data of the original image into the effective storage area;
[0034] Step S208: If there is an invalid storage area in the preset storage area, write preset data into the invalid storage area, wherein the invalid storage area is a storage area in the preset storage area other than the valid storage area.
[0035] Optionally, the entity performing the above steps may be a background processor or other devices with similar processing capabilities, or a machine that integrates at least an image acquisition device and a data processing device. The image acquisition device may include an image acquisition module such as a camera, and the data processing device may include a terminal such as a computer or a mobile phone, but is not limited thereto.
[0036] Through the above steps, for the original image currently being written to the preset storage area, its image data is written to the valid storage area of the preset storage area, while the invalid storage area in the preset storage area is written to preset data. This avoids the edge parts of the previous frame image data or the previous few frames image data from being superimposed on the data of the original image currently being written to the preset storage area, thus avoiding the problem of image data superposition when writing image data in related technologies. Therefore, the problem of image data superposition when writing image data can be solved, thereby achieving the effect of improving the accuracy of image processing.
[0037] In one exemplary embodiment, obtaining original image parameters and preset storage parameters of a preset storage area includes: obtaining the width and height of the original image, and the preset storage width and preset storage height of the preset storage area; determining target parameters based on the original image parameters and the preset storage parameters includes: determining a target scaling ratio based on the width and height of the original image, and the preset storage width and preset storage height; wherein the original image parameters include the width and height of the original image, the preset storage parameters include the preset storage width and the preset storage height, and the target parameters include the target scaling ratio.
[0038] As an optional implementation, the original image described above can be acquired using an image acquisition device, including but not limited to a camera or webcam. The original image can be used in Srcimg representation. The parameters of the original image include, but are not limited to, the width (represented by RoiWid) and height (represented by RoiHei) of the region of interest (Roi region). RoiWid is (lr.x - ul.x + 1). RoiHei is (lr.y - ul.y + 1), where lr represents the lower right corner of the Roi region and ul represents the upper left corner of the Roi region.
[0039] The aforementioned preset storage area (Dstimg) can be the storage area corresponding to the destination address. The preset storage parameters include, but are not limited to, the preset storage width (DstWid) and the preset storage height (DstHei). The aforementioned target parameters include, but are not limited to, the target scaling ratio, which can be the scaling ratio when scaling proportionally.
[0040] The aforementioned valid storage area is the preset storage area used to store the image data of the original image. The aforementioned invalid storage area is the storage area outside the valid storage area within the preset storage area. Preset data is written into the invalid storage area. The preset data can be set according to the actual situation, such as 0, 1, etc.
[0041] In one exemplary embodiment, determining the target scaling ratio based on the width and height of the original image, as well as the preset storage width and the preset storage height, includes: determining an original width scaling ratio based on the width of the original image and the preset storage width; determining an original height scaling ratio based on the height of the original image and the preset storage height; and determining the target scaling ratio as the maximum value of the original width scaling ratio and the original height scaling ratio.
[0042] As an optional implementation method, the scaling ratio derivation formula is normally as follows:
[0043]
[0044]
[0045] Where XRatio is the original width scaling ratio, representing the scaling ratio in the width direction, and YRatio is the original height scaling ratio, representing the scaling ratio in the height direction.
[0046] The formula for deriving the scaling ratio (target scaling ratio) during proportional scaling is as follows:
[0047] XRatio_1=(XRatio>YRatio)? XRatio:YRatio
[0048] YRatio_1 = XRatio_1
[0049] Where XRatio_1 and YRatio_1 are the target scaling ratios, representing the scaling ratios in the width and height directions respectively when scaling proportionally.
[0050] In an exemplary embodiment, determining the effective storage area in the preset storage area using the target parameters includes: determining the effective storage width and effective storage height in the preset storage area based on the target scaling ratio, the width of the original image, and the height of the original image; and determining the effective storage area using the effective storage width and the effective storage height, as well as the preset storage width and the preset storage height.
[0051] As an optional implementation, the effective storage width (orgDstWid) refers to the actual effective data width in the width direction (x direction) calculated by the target scaling ratio XRatio_1 when scaling proportionally, and the effective storage height (orgDstHei) refers to the actual effective data height in the height direction (y direction) calculated by the target scaling ratio YRatio_1 when scaling proportionally.
[0052] The formulas for deriving the width and height of actual effective image data are as follows:
[0053]
[0054]
[0055] As an optional implementation, the invalid storage width (subx) of the above-mentioned invalid storage area represents the distance from the edge of the preset storage area Dstimg in the width direction (x direction) to the starting point of writing valid data, and the invalid storage height (suby) of the above-mentioned invalid storage area represents the distance from the edge of the preset storage area Dstimg in the height direction (y direction) to the starting point of writing valid data.
[0056] The derivation formulas for the above invalid storage width and invalid storage height are as follows:
[0057] subx=abs(orgDstWid-DstWid)>>1
[0058] suby=abs(orgDstHei-DstHei)>>1
[0059] The valid storage area can be determined from the preset storage area by using the above invalid storage width and invalid storage height.
[0060] In an exemplary embodiment, when an invalid storage area exists in the preset storage area, writing preset data in the invalid storage area includes: obtaining the starting offset position of the target work item; and when the starting offset position is located in the invalid storage area, writing the preset data in the invalid storage area through the target work item.
[0061] As an optional implementation, the target work item mentioned above is a work item in the OpenCL process. The starting offset position of the globalid of each work item Woek-item in the OpenCL process can be represented by Id, and the starting offset position of the data to be filled can be represented by coord_fill.
[0062] The starting offset position is obtained as follows:
[0063] int2 Id=(int2)(get_global_id(0),get_g1obal_id(1))
[0064] The condition for determining whether the starting offset is outside the valid memory area (within the invalid memory area):
[0065] if((Id.x<subx)||(Id.x>(DstWid-subx))||
[0066] (Id.y<suby)||(Id.y<(DstHei-suby)))
[0067] The starting offset point for writing preset data is obtained as follows:
[0068] int4 coord_fill=(int4)(id.x, id.y, 0, 0)
[0069] In one exemplary embodiment, writing preset data in the invalid storage area includes: writing data 0 in the invalid storage area, wherein the preset data includes data 0; or writing other preset data in the invalid storage area, wherein the other preset data is data other than 0.
[0070] As an optional implementation, the above-mentioned preset data can be set according to the actual situation. For example, it can be 0, 1, or other values such as 2, 3, 255, etc.
[0071] In one exemplary embodiment, writing the processed image data of the original image into the effective storage area includes: scaling the original image to obtain a scaled image by means of the target scaling ratio when the target parameter is a target scaling ratio; and writing the image data of the scaled image into the effective storage area.
[0072] As an optional implementation, the original image can be scaled according to the target scaling ratio, and the scaled image data can be written to the valid storage area. If there is an invalid storage area, preset data can be written to the invalid storage area.
[0073] In one exemplary embodiment, writing the processed image data of the original image into the effective storage area includes: scaling the original image to obtain a scaled image by means of the target scaling ratio when the target parameter is a target scaling ratio; performing image processing on the scaled image to obtain a target image; and writing the image data of the target image into the effective storage area.
[0074] As an optional implementation, the above image processing includes, but is not limited to, color space conversion, mean subtraction, normalization, and other processing methods.
[0075] In intelligent algorithms, a complete algorithm goes through three processes: image preprocessing, forward inference, and post-processing to obtain the final result. The image preprocessing process involves operations such as image matting and scaling, color space conversion, and mean subtraction normalization.
[0076] Image matting and scaling involves extracting an image data of the size of a given Roi region from the original input image data and scaling it to the size required by the algorithm model. This Roi region can be any valid area of the original image. In the above embodiments, the original image can be the original input image or its Roi region. Color space conversion primarily converts image data compressed to other formats into RGB format, aiming to reduce the memory resource usage of the original image data on the embedded device. Mean subtraction normalization normalizes the image data (0-255) to the range of 0-1, reducing the adverse effects of data distribution on the algorithm. The image data written to the valid storage area can be image data after scaling, color space conversion, and mean subtraction normalization.
[0077] As an optional implementation, the flowchart is as follows: Figure 3As shown, firstly, by obtaining the original image parameters (original image width and original image height RoiWid, RoiHei) of the original image Srcimg, and the preset storage parameters (preset storage width and preset storage height DstWid, DstHei) of the preset storage area, the original width scaling ratio and the original height scaling ratio XRatio and YRatio under normal scaling conditions are calculated.
[0078] Calculate the target scaling ratios XRatio_1 and YRatio_1 under the condition of constant scaling based on XRatio and YRatio. Under the condition of constant scaling, calculate the effective storage width orgDstWid and effective storage height orgDstHei of the effective storage area Dstimg using the target scaling ratio. Then calculate the invalid storage width and invalid storage height subx and suby of the invalid storage area.
[0079] Different measures are taken depending on whether the starting offset of the work item is in the valid storage area or the invalid storage area. If it is in the valid storage area, it is scaled using the conventional bilinear interpolation algorithm, and after image processing such as color space conversion and normalization, the image data is written to the single or three channels corresponding to the valid storage area. If it is in the invalid storage area, the single or three channels of that area are directly set to zero or filled with externally passed padding values, until all work items are completed.
[0080] The following examples illustrate this concept. In these examples, it is assumed that the preset storage width DstWid of the preset storage area Dstimg is 300 and the preset storage height DstHei is 200.
[0081] Specific Implementation Example 1 (XRatio = YRatio)
[0082] Assume the original image Srcimg has a width RoiWid of 600 and a height RoiHei of 400. The calculated scaling ratios for the original width and height are:
[0083]
[0084]
[0085] Since the original width scaling ratio and the original height scaling ratio are the same, the target scaling ratio XRatio_1 = YRatio_1 = 2 << 15.
[0086] The effective storage width (orgDstWid) and effective storage height (orgDstHei) are:
[0087]
[0088]
[0089] The above invalid storage width and invalid storage height are:
[0090] subx=abs(orgDstWid-DstWid)>>1=0
[0091] suby=abs(orgDstHei-DstHei)>>1=0
[0092] In this case, there are no invalid storage areas in the preset storage area because the work item ID is located within the valid storage area:
[0093] 0≤Id.x<DstWid
[0094] 0≤Id.y<DstHei
[0095] The following conditions are not met:
[0096] if((Id.x<subx)||(Id.x>(DstWid-subx))||
[0097] (Id.y<suby)||(Id.y<(DstHei-suby)))
[0098] In this case, there will be no problem with frame result overlay, and there is no need to write preset data. Just process it according to the normal procedure.
[0099] Specific Implementation Example 2 (XRatio > YRatio)
[0100] Assume the original image Srcimg has a width RoiWid of 800 and a height RoiHei of 500. The calculated scaling ratios for the original width and height are:
[0101]
[0102]
[0103] Since XRatio is greater than YRatio, the target scaling ratio is:
[0104]
[0105] Calculate the effective storage width and effective storage height of the effective storage area:
[0106]
[0107]
[0108] The invalid storage width and invalid storage height are calculated as follows:
[0109] subx=abs(orgDstWid-DstWid)>>1=0
[0110] suby=abs(orgDstHei-DstHei)>>1=6
[0111] Therefore, the effective storage area of the original image is 6≤Id.y≤194&&0≤Id.x≤299.
[0112] Assuming that the effective storage area of the next frame of the original image is obtained after the same calculation steps as above, the effective storage area of the next frame of the original image is: 30≤Id.y≤170&&0≤Id.x≤299.
[0113] like Figure 4 As shown in the left figure, the effective storage area for the previous frame of the original image is (0, 6)-(299, 194). The effective storage area for the next frame of the original image is (0, 30)-(299, 170). In the prior art, the image data of the next frame may retain the image data of the original image (0, 6)-(299, 29) and (0, 171)-(299, 194).
[0114] Alternatively, suppose that after the same calculation steps are performed on the next frame of the original image, the effective storage area of the next frame is: 0≤Id.y≤199&&40≤Id.x≤260.
[0115] like Figure 4 As shown in the right figure, the effective storage area of the previous frame of the original image is (0, 6)-(299, 194). The effective storage area of the next frame of the original image is (40, 0)-(260, 199). In the prior art, the image data of the next frame may retain the image data of the original image (0, 6)-(39, 194) and (261, 6)-(299, 194).
[0116] Regardless of the above Figure 4 In either case, the address of the next frame will retain part of the preprocessed edge box image data of the original image of the previous frame. This results in unnecessary invalid data in the address of the next frame, which in turn causes abnormal operation of the overall algorithm.
[0117] Therefore, to avoid the problems caused by the above phenomenon, the method of determining whether the work item is located in an invalid storage area and writing a preset value into the invalid storage area can be used to solve the problem. For example... Figure 4As shown in the left figure, when the valid storage area is (0, 6)-(299, 194), a preset value can be written to the invalid storage areas (0, 0)-(299, 5) and (0, 195)-(299, 199). When the valid storage area is (0, 30)-(299, 170), a preset value can be written to the invalid storage areas (0, 0)-(299, 29) and (0, 171)-(299, 199). Or as... Figure 5 As shown in the right figure, when the valid storage area is (0, 6)-(299, 194), preset values can be written to the invalid storage areas (0, 0)-(299, 5) and (0, 195)-(299, 199). When the valid storage area is (40, 0)-(260, 199), preset values can be written to the invalid storage areas (0, 0)-(39, 199) and (261, 0)-(299, 199).
[0118] Specific Implementation Example 3 (XRatio < YRatio)
[0119] Assume the original image Srcimg has a width RoiWid of 800 and a height RoiHei of 600. The calculated scaling ratios for the original width and height are:
[0120]
[0121]
[0122] Since XRatio is less than YRatio, the target scaling ratio is:
[0123] XRatio_1=YRatio_1=3<<15
[0124] Calculate the effective storage width and effective storage height of the effective storage area:
[0125]
[0126]
[0127] Calculate the invalid storage width and invalid storage height as follows:
[0128] subx=abs(orgDstWid-DstWid)>>1=17
[0129] suby=abs(orgDstHei-DstHei)>>1=0
[0130] Therefore, the effective storage area of the original image is 0≤Id.y≤199&&17≤Id.x≤282.
[0131] Assuming that the effective storage area of the next frame of the original image is obtained after the same calculation steps as above, the effective storage area of the next frame is: 6≤Id.y≤194&&0≤Id.x≤299.
[0132] like Figure 5 As shown in the left figure, the effective storage area for the previous frame of the original image is (17,0)-(282,199). The effective storage area for the next frame of the original image is (0,6)-(299,194). In the prior art, the image data of the next frame may retain the image data of the original image (0,6)-(16,194) and (283,6)-(299,194).
[0133] Alternatively, suppose that after the same calculation steps are performed on the next frame of the original image, the effective storage area of the next frame is: 0≤Id.y≤199&&60≤Id.x≤239.
[0134] like Figure 5 As shown in the right figure, the effective storage area of the previous frame of the original image is (17,0)-(282,199). The effective storage area of the next frame of the original image is (60,0)-(239,199). In the prior art, the image data of the next frame may retain the image data of the original image (17,0)-(59,199) and (240,0)-(282,199).
[0135] Regardless of the above Figure 5 In either case, the address of the next frame will retain part of the preprocessed edge box image data of the original image of the previous frame. This results in unnecessary invalid data in the address of the next frame, which in turn causes abnormal operation of the overall algorithm.
[0136] Therefore, to avoid the problems caused by the above phenomenon, the method of determining whether the work item is located in an invalid storage area and writing a preset value into the invalid storage area can be used to solve the problem. For example... Figure 5 As shown in the left figure, when the valid storage area is (17, 0)-(282, 199), a preset value can be written to the invalid storage areas (0, 0)-(16, 199) and (283, 0)-(299, 199). When the valid storage area is (0, 6)-(299, 194), a preset value can be written to the invalid storage areas (0, 0)-(299, 5) and (0, 195)-(299, 199). Or as... Figure 5As shown in the right figure, when the valid storage area is (17, 0)-(282, 199), preset values can be written to the invalid storage areas (0, 0)-(16, 199) and (283, 0)-(299, 199). When the valid storage area is (60, 0)-(239, 199), preset values can be written to the invalid storage areas (0, 0)-(59, 199) and (240, 0)-(299, 199).
[0137] In the above specific embodiments, the determination of whether the starting offset position of the work item is located in the invalid storage area is based on the following condition:
[0138] if((Id.x<subx)||(Id.x>(DstWid-subx))||
[0139] (Id.y<suby)||(Id.y<(DstHei-suby)))
[0140] The starting offset point Id of the work item can be used to construct the starting offset point coord_fill for writing preset data, and the preset value can be written to the coord_fill position in the invalid storage area via a single or triple channel. The number of bytes of the preset value depends on the number of bytes that the work item normally writes to the destination address.
[0141] In the above embodiments, the frame result overlay problem is solved by adding logical judgment processing of the work item offset position and the effective storage area position in the preset storage area. Compared with the prior art, the GPU processing time is optimized while ensuring result consistency. Replacing the invalid storage area with a simple method of writing preset data optimizes the processing time by more than 15%. By adding a logical processing strategy, while ensuring that the image data after the original image preprocessing is completely written to the corresponding effective storage area of the destination address, the part outside the effective storage area (invalid storage area) is set to zero or written with preset data to solve the frame result overlay problem.
[0142] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0143] This embodiment also provides a data writing device for implementing the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that performs a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0144] Figure 6 This is a structural block diagram of a data writing device according to an embodiment of the present invention, such as... Figure 6 As shown, the device includes: an acquisition module 62, used to acquire original image parameters of the original image and preset storage parameters of a preset storage area; a determination module 64, used to determine target parameters based on the original image parameters and the preset storage parameters; a first writing module 66, used to determine a valid storage area in the preset storage area using the target parameters, and write the processed image data of the original image into the valid storage area; and a second writing module 68, used to write preset data into the invalid storage area if an invalid storage area exists in the preset storage area, wherein the invalid storage area is a storage area in the preset storage area other than the valid storage area.
[0145] In an exemplary embodiment, the above-described apparatus is further configured to acquire the width and height of the original image, and the preset storage width and preset storage height of the preset storage area; and to determine target parameters based on the original image parameters and the preset storage parameters, including: determining a target scaling ratio based on the width and height of the original image, and the preset storage width and preset storage height; wherein the original image parameters include the width and height of the original image, the preset storage parameters include the preset storage width and the preset storage height, and the target parameters include the target scaling ratio.
[0146] In an exemplary embodiment, the above-described apparatus is further configured to determine an original width scaling ratio based on the width of the original image and the preset storage width; determine an original height scaling ratio based on the height of the original image and the preset storage height; and determine the target scaling ratio as the maximum value of the original width scaling ratio and the original height scaling ratio.
[0147] In an exemplary embodiment, the above-described apparatus is further configured to determine the effective storage width and effective storage height in the preset storage area based on the target scaling ratio, the width of the original image, and the height of the original image; and to determine the effective storage area using the effective storage width and the effective storage height, as well as the preset storage width and the preset storage height.
[0148] In an exemplary embodiment, the above-described apparatus is further configured to obtain the starting offset position of the target work item; and if the starting offset position is located in the invalid storage area, to write the preset data in the invalid storage area through the target work item.
[0149] In one exemplary embodiment, the above-described apparatus is further configured to write data 0 into the invalid storage area, wherein the preset data includes the data 0; or, to write other preset data into the invalid storage area, wherein the other preset data is data other than the data 0.
[0150] In an exemplary embodiment, the above-described apparatus is further configured to scale the original image by the target scaling ratio when the target parameter is a target scaling ratio, to obtain a scaled image; and to write the image data of the scaled image into the effective storage area.
[0151] In an exemplary embodiment, the above-described apparatus is further configured to, when the target parameter is a target scaling ratio, scale the original image to obtain a scaled image by the target scaling ratio; perform image processing on the scaled image to obtain a target image; and write the image data of the target image into the effective storage area.
[0152] It should be noted that the above modules can be implemented by software or hardware. For the latter, they can be implemented in the following ways, but are not limited to: all the above modules are located in the same processor; or, the above modules are located in different processors in any combination.
[0153] Embodiments of the present invention also provide a computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the steps of the method described in any of the preceding claims.
[0154] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.
[0155] Embodiments of the present invention also provide an electronic device including a memory and a processor, the memory storing a computer program and the processor being configured to run the computer program to perform the steps in any of the above method embodiments.
[0156] In one exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor and the input / output device is connected to the processor.
[0157] Specific examples in this embodiment can be found in the examples described in the above embodiments and exemplary implementations, and will not be repeated here.
[0158] It is obvious to those skilled in the art that the modules or steps of the present invention described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. They can be implemented using computer-executable program code, and thus can be stored in a storage device for execution by a computing device. In some cases, the steps shown or described can be performed in a different order than those described herein, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.
[0159] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, or improvements made within the principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for writing data, characterized in that, include: Obtain the original image parameters of the original image and the preset storage parameters of the preset storage area, wherein the preset storage area is the storage area corresponding to the destination address for writing image data; The target parameters are determined based on the original image parameters and the preset storage parameters; The target parameters are used to determine an effective storage area in the preset storage area, and the processed image data of the original image is written into the effective storage area. If an invalid storage area exists in the preset storage area, preset data is written into the invalid storage area.
2. The method according to claim 1, characterized in that, Obtaining the original image parameters and the preset storage parameters of the preset storage area includes: obtaining the width and height of the original image, and the preset storage width and preset storage height of the preset storage area; Determining target parameters based on the original image parameters and the preset storage parameters includes: determining the target scaling ratio based on the width and height of the original image, as well as the preset storage width and the preset storage height; The original image parameters include the width and height of the original image, the preset storage parameters include the preset storage width and the preset storage height, and the target parameters include the target scaling ratio.
3. The method according to claim 2, characterized in that, Determining the target scaling ratio based on the width and height of the original image, as well as the preset storage width and the preset storage height, includes: The original width scaling ratio is determined based on the width of the original image and the preset storage width; The original height scaling ratio is determined based on the height of the original image and the preset storage height; The target scaling ratio is the maximum of the original width scaling ratio and the original height scaling ratio.
4. The method according to claim 2, characterized in that, The step of determining the effective storage area in the preset storage area using the target parameters includes: Based on the target scaling ratio, the width of the original image, and the height of the original image, determine the effective storage width and effective storage height in the preset storage area; The effective storage area is determined by the effective storage width and the effective storage height, as well as the preset storage width and the preset storage height.
5. The method according to any one of claims 1 to 4, characterized in that, If an invalid storage area exists within the preset storage area, preset data is written into the invalid storage area, including: Obtain the starting offset position of the target work item; If the starting offset position is located in the invalid storage area, the preset data is written into the invalid storage area by the target work item.
6. The method according to any one of claims 1 to 4, characterized in that, Write preset data into the invalid storage area, including: Write data 0 into the invalid storage area, wherein the preset data includes the data 0; or, Write other preset data into the invalid storage area, wherein the other preset data is data other than 0.
7. The method according to claim 1, characterized in that, The image data after processing of the original image is written into the effective storage area, including: When the target parameter is a target scaling ratio, the original image is scaled according to the target scaling ratio to obtain a scaled image; Write the image data of the scaled image into the valid storage area.
8. The method according to claim 1, characterized in that, The image data after processing of the original image is written into the effective storage area, including: When the target parameter is a target scaling ratio, the original image is scaled according to the target scaling ratio to obtain a scaled image; The scaled image is processed to obtain the target image, and the image data of the target image is written into the effective storage area.
9. A data writing device, characterized in that, include: The acquisition module is used to acquire the original image parameters of the original image and the preset storage parameters of the preset storage area, wherein the preset storage area is the storage area corresponding to the destination address for writing image data; The determination module is used to determine the target parameters based on the original image parameters and the preset storage parameters; The first writing module is used to determine a valid storage area in the preset storage area by means of the target parameters, and to write the image data after processing of the original image into the valid storage area; The second write module is used to write preset data into the invalid storage area when there is an invalid storage area in the preset storage area, wherein the invalid storage area is a storage area in the preset storage area other than the valid storage area.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the steps of the method described in any one of claims 1 to 8.
11. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the method as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Medical image processing method and device, computer equipment and storage medium
CN114219918A