CN114897661A - Image pixel copying method, image pixel copying device, storage medium and electronic device - Google Patents

Image pixel copying method, image pixel copying device, storage medium and electronic device Download PDF

Info

Publication number
CN114897661A
CN114897661A CN202210617311.7A CN202210617311A CN114897661A CN 114897661 A CN114897661 A CN 114897661A CN 202210617311 A CN202210617311 A CN 202210617311A CN 114897661 A CN114897661 A CN 114897661A
Authority
CN
China
Prior art keywords
pixel
copy
point
value
copying
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210617311.7A
Other languages
Chinese (zh)
Inventor
陈小彪
李合青
陈波扬
孙璆琛
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang Dahua Technology Co Ltd
Original Assignee
Zhejiang Dahua Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhejiang Dahua Technology Co Ltd filed Critical Zhejiang Dahua Technology Co Ltd
Priority to CN202210617311.7A priority Critical patent/CN114897661A/en
Publication of CN114897661A publication Critical patent/CN114897661A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T1/00General purpose image data processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/11Region-based segmentation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/12Edge-based segmentation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/60Analysis of geometric attributes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/70Determining position or orientation of objects or cameras
    • G06T7/73Determining position or orientation of objects or cameras using feature-based methods

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Geometry (AREA)
  • Image Processing (AREA)

Abstract

The embodiment of the invention provides a method, a device, a storage medium and an electronic device for copying image pixels, wherein the method comprises the following steps: determining a first copying area for copying the original image and a second copying area for copying the destination image; acquiring a first initial offset point in a first copy area read when a read operation is executed in a current copy operation, and a second initial offset point when a write operation is executed in a second copy area; reading a preset number of first pixel values from a first initial offset point, and writing the first pixel values in a copy destination graph by taking a second initial offset point as a starting point; and correspondingly covering the original pixel value of the pixel point corresponding to the second pixel value on the pixel point corresponding to the second pixel value under the condition that the first pixel value comprises the second pixel value written outside the second copy area. By the method and the device, the problem of low image data copying accuracy is solved, and the effect of improving the image data copying accuracy is achieved.

Description

Image pixel copying method, image pixel copying device, storage medium and electronic device
Technical Field
The embodiment of the invention relates to the field of image processing, in particular to a method and a device for copying image pixels, a storage medium and an electronic device.
Background
In the related art, image data copying is a common image data processing means, and in a Linux device, CPU resources are limited, and time consumption of an application program is required to be high. Copying image data using a CPU is a common method, especially for large images and frequent copy operations, which inevitably consumes a lot of CPU resources, bandwidth resources and increases the time consumption of application programs.
In the prior art, a hardware unit of a device is usually used for processing, so that not only can a large amount of CPU and bandwidth resources be saved, but also the overall performance of an application program can be improved. The GPU hardware resources supporting OpenCL are acceleration units commonly used in linux devices, and are often used to optimize acceleration operations. However, in the process of copying data by using OpenCL, due to the characteristic of reading lines (reading a fixed number of pixels each time), when a required area boundary is read from an original image, several pixel points outside the required area are read, so that invalid data outside an unnecessary area appears when the read image data is written into a target image, and the accuracy of copying the image data is low. There is therefore a need for a method to achieve that the data in the destination image is all valid data within the required area. This not only speeds up by means of the GPU hardware unit but also avoids the writing of invalid data.
In view of the above problems in the related art, no effective solution has been proposed.
Disclosure of Invention
Embodiments of the present invention provide a method and an apparatus for copying image pixels, a storage medium, and an electronic apparatus, so as to at least solve the problem of low accuracy of image data copying in the related art.
According to an embodiment of the invention, there is provided a method of copying pixels of an image, comprising: determining a first copying area for copying the original image and a second copying area for copying the destination image; acquiring a first starting offset point in the first copy area read when a read operation is executed in a current copy operation and a second starting offset point when a write operation is executed in the second copy area, wherein the second starting offset point is located in the second copy area; reading a preset number of first pixel values from the first initial offset point, and writing the first pixel values in the copy destination graph by taking the second initial offset point as a starting point; and correspondingly covering the original pixel value of the pixel point corresponding to the second pixel value on the pixel point corresponding to the second pixel value under the condition that the first pixel value comprises the second pixel value written in the second copying area, wherein the pixel point corresponding to the second pixel value is the pixel point written in the second pixel value in the copying target image.
Optionally, the original pixel value is determined by: in the copy destination graph, under the condition that the second initial offset point is used as a starting point to write the first pixel values of the preset number in the copy destination graph, coordinates of edge pixel points positioned on a right frame of the second copy area in pixel points corresponding to the first pixel values of the preset number are predetermined; and based on the coordinates of the edge pixel points, acquiring and storing original pixel values of the preset number of pixel points selected from the edge pixel points to the right in the copied target image, wherein the original pixel values of the preset number of pixel points comprise the original pixel values of the pixel points corresponding to the second pixel values.
Optionally, in the copy destination graph, when the first pixel value is written using the second initial offset point as a starting point, predetermining coordinates of edge pixel points located on a right frame of the second copy area among the pixel points corresponding to the preset number of first pixel values, including: determining a region width value for the second copy region; determining the sum of the abscissa value of the coordinate point of the initial pixel in the second copy area and the area width value as the abscissa of the edge pixel point; and determining the ordinate value of the second initial offset point as the ordinate of the edge pixel point.
Optionally, when it is determined that the first pixel value includes a second pixel value written outside the second copy area, correspondingly covering an original pixel value of a pixel point corresponding to the second pixel value on a pixel point corresponding to the second pixel value, including: determining the preset number of pixel points selected rightwards from the edge pixel points in the copy destination picture, wherein the preset number of pixel points comprise pixel points corresponding to the second pixel values; and correspondingly covering the original pixel values of the preset number of pixel points on the preset number of pixel points.
Optionally, a first starting offset point in the first copy area read when a read operation is performed in a current copy operation and a second starting offset point when a write operation is performed in the second copy area are obtained, and the method includes: acquiring an initial offset coordinate value of a work item, wherein the work item is used for copying a pixel point in the original copy image to the image of the copy destination; determining the first initial offset point based on the sum of the initial offset coordinate value and the coordinate value of the initial pixel point of the first copy area; and determining the second initial offset point based on the sum of the initial offset coordinate value and the coordinate value of the initial pixel point of the second copy area.
Optionally, determining a region width value of the second copy region includes: updating the original width value of the second copy area to the first copy area width value if the first copy area width value is less than the original width value of the second copy area; keeping the second copy area width value unchanged if the second copy area width value is smaller than the first copy area width value.
Optionally, the method further comprises: determining a first target pixel point corresponding to a pixel value written into the copy destination graph at the last included in the first pixel value under the condition that the preset number of first pixel values are written into the copy destination graph by taking the second initial offset point as a starting point; and under the condition that the abscissa of the first target pixel point is larger than the abscissa of a second target pixel point, determining a second pixel value which is included in the first pixel value and written outside the second copy area, wherein the second target pixel point is a pixel point located on the right frame of the second copy area.
According to another embodiment of the invention, there is provided an apparatus for copying pixels of an image, comprising: the first determining module is used for determining a first copying area for copying the original image and a second copying area for copying the destination image; an obtaining module, configured to obtain a first starting offset point in the first copy area read when a read operation is performed in a current copy operation, and a second starting offset point when a write operation is performed in the second copy area, where the second starting offset point is located in the second copy area; a writing module, configured to read a preset number of first pixel values from the first initial offset point, and write the first pixel values in the copy destination graph with the second initial offset point as a starting point; and the covering module is used for correspondingly covering the original pixel value of the pixel point corresponding to the second pixel value on the pixel point corresponding to the second pixel value under the condition that the first pixel value is determined to comprise the second pixel value written in the second copying area, wherein the pixel point corresponding to the second pixel value is the pixel point written in the second pixel value in the copying target image.
According to yet another embodiment of the invention, there is also provided a computer-readable storage medium having a computer program stored therein, wherein the computer program, when executed by a processor, implements the steps of the method as set forth in any of the above.
According to yet another embodiment of the present invention, there is also provided an electronic device, including a memory in which a computer program is stored and a processor configured to execute the computer program to perform the steps in any of the above method embodiments.
By the invention, a first initial offset point in the first copy area read when the reading operation is executed in the previous copying operation and a second initial offset point in the second copy area are obtained by determining the first copy area to be copied in the original image and the second copy area of the copy destination image, a preset number of first pixel values are read by taking the first initial offset point as a starting point, the first pixel values are written by taking the second initial offset point as a starting point in the copy destination image, and under the condition that the written first pixel values comprise second pixel values written outside the second copy area, the original pixel values of the pixel points corresponding to the second pixel values in the copy destination image are correspondingly covered on the pixel points corresponding to the second pixel values, so that invalid data outside the required second copy area can be removed, and only valid data in the second copy area is reserved, therefore, the problem of low accuracy of image data copying in the prior art can be solved, and the effect of improving the accuracy of image data copying is achieved.
Drawings
Fig. 1 is a block diagram of a hardware configuration of a mobile terminal of a copy method of image pixels according to an embodiment of the present invention;
FIG. 2 is a flow diagram of copying of image pixels according to an embodiment of the invention;
FIG. 3 is a flowchart of an alternative OpenCL-based image copy edge data processing method according to an embodiment of the present invention;
fig. 4 is a block diagram of a copy apparatus of image pixels according to an embodiment of the present invention.
Detailed Description
Hereinafter, embodiments of the present invention will be described in detail with reference to the accompanying drawings in conjunction with the embodiments.
It should be noted that the terms "first," "second," and the like in the description and claims of the present invention and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order.
The method embodiments provided in the embodiments of the present application may be executed in a mobile terminal, a computer terminal, or a similar computing device. Taking the example of being operated on a mobile terminal, fig. 1 is a hardware structure block diagram of the mobile terminal of a copy method of image pixels according to an embodiment of the present invention. As shown in fig. 1, the mobile terminal may include one or more (only one shown in fig. 1) processors 102 (the processor 102 may include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA), and a memory 104 for storing data, wherein the mobile terminal may further include a transmission device 106 for communication functions and an input-output device 108. It will be understood by those skilled in the art that the structure shown in fig. 1 is only an illustration, and does not limit the structure of the mobile terminal. For example, the mobile terminal may also include more or fewer components than shown in FIG. 1, or have a different configuration than shown in FIG. 1.
The memory 104 can be used for storing computer programs, for example, software programs and modules of application software, such as a computer program corresponding to the copy method of the image pixel in the embodiment of the present invention, and the processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, so as to implement the above-mentioned 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 examples, the memory 104 may further include memory located remotely from the processor 102, which may be connected to the mobile terminal over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The transmission device 106 is used to receive or transmit data via a network. Specific examples of the network described above may include a wireless network provided by a communication provider of the mobile terminal. In one example, the transmission device 106 includes a Network adapter (NIC) that can be connected to other Network devices through a base station to communicate with the internet. In one example, the transmission device 106 may be a Radio Frequency (RF) module, which is used to communicate with the internet in a wireless manner.
In the present embodiment, a copy method of image pixels operating in the mobile terminal is provided, and fig. 2 is a flowchart of copy of image pixels according to an embodiment of the present invention, as shown in fig. 2, the flowchart includes the following steps:
step S202, determining a first copying area for copying the original image and a second copying area for copying the destination image;
the first copy area may be any designated area in the original copy map that needs to be copied, the second copy area may be any designated area in the destination copy map that needs to be copied, and the basic principle of image data copying is to read a certain pixel value from the first copy area in the original copy map and then write the pixel value into the second copy area in the destination copy map.
Step S204, obtaining a first initial offset point in the first copy area read when a read operation is executed in the current copy operation, and a second initial offset point when a write operation is executed in the second copy area, wherein the second initial offset point is located in the second copy area;
wherein the first initial offset point may be an initial coordinate point of a work item for reading pixels in the first copy area, the second initial offset point may be an initial coordinate point of a work item for writing pixels to the second copy area, and the second offset point for writing pixels is located within the second copy area.
Step S206, reading a preset number of first pixel values from the first initial offset point, and writing the first pixel values in the copy destination graph with the second initial offset point as a starting point;
the preset number may represent the number of pixels in a row read by a workitem at a time, and may be 4, 8, or 16, where the preset number is not limited, and assuming that the preset number is 16, 16 first pixel values may be read from the first initial offset point as a starting point in the original copy image, and the 16 first pixel values may be written from the second initial offset point as a starting point in the destination copy image.
Step S208, in a case that it is determined that the first pixel value includes a second pixel value written in outside the second copy area, correspondingly covering an original pixel value of a pixel point corresponding to the second pixel value on a pixel point corresponding to the second pixel value, where the pixel point corresponding to the second pixel value is the pixel point written in the copy destination image.
After writing 16 first pixel values in the copy destination graph, if the written 16 first pixel values include second pixel values located outside the second copy area, for example, the 16 first pixel values include 10 first pixel values located inside the second copy area and also include 6 first pixel values located outside the second copy area, at this time, the 6 first pixel values located outside the second copy area are determined as the second pixel values, and the original pixel values of the pixel points corresponding to the second pixel values are covered in the pixel points corresponding to the 6 second pixel values outside the second copy area.
Optionally, the main body of the above steps may be a background processor, or other devices with similar processing capabilities, and may also be a machine integrated with at least an image acquisition device and a data processing device, where the image acquisition device may include a graphics acquisition module such as a camera, and the data processing device may include a terminal such as a computer and a mobile phone, but is not limited thereto.
Through the steps, a first initial offset point in the first copy area read when the reading operation is executed in the previous copying operation and a second initial offset point in the second copy area are obtained by determining the first copy area to be copied in the original image and the second copy area of the copy destination image, a preset number of first pixel values are read by taking the first initial offset point as a starting point, the first pixel values are written by taking the second initial offset point as a starting point in the copy destination image, and under the condition that the written first pixel values comprise second pixel values written outside the second copy area, the original pixel values of the pixel points corresponding to the second pixel values in the copy destination image are correspondingly covered on the pixel points corresponding to the second pixel values, so that invalid data outside the required second copy area can be removed, and only valid data in the second copy area is reserved, therefore, the problem of low accuracy of image data copying in the prior art can be solved, and the effect of improving the accuracy of image data copying is achieved.
Optionally, the original pixel value is determined by: in the copy destination graph, under the condition that the second initial offset point is used as a starting point to write the first pixel values of the preset number in the copy destination graph, coordinates of edge pixel points positioned on a right frame of the second copy area in pixel points corresponding to the first pixel values of the preset number are predetermined; and based on the coordinates of the edge pixel points, acquiring and storing original pixel values of the preset number of pixel points selected from the edge pixel points to the right in the copied target image, wherein the original pixel values of the preset number of pixel points comprise the original pixel values of the pixel points corresponding to the second pixel values.
As an optional implementation manner, assuming that the preset number is 16, the coordinate of the second start offset point Dstpos is (16,32), in the copy destination diagram, when a row of 16 pixel values is written from the second start offset point Dstpos as a starting point, it is necessary to determine in advance the coordinate of the edge pixel point on the right frame of the second copy area among the 16 pixel points corresponding to the 16 pixel values, and assuming that the abscissa of the right frame of the second copy area is 26, the coordinate of the edge pixel point is (26,32), and obtain and store the original pixel values of the 16 pixel points selected to the right in the copy destination diagram starting from the edge pixel point coordinate (26, 32).
Optionally, in the copy destination graph, when the first pixel value is written using the second initial offset point as a starting point, predetermining coordinates of edge pixel points located on a right frame of the second copy area among the pixel points corresponding to the preset number of first pixel values, including: determining a region width value for the second copy region; determining the sum of the abscissa value of the coordinate point of the initial pixel in the second copy area and the area width value as the abscissa of the edge pixel point; and determining the ordinate value of the second initial offset point as the ordinate of the edge pixel point.
As an alternative embodiment, assuming that the copy start point (upper left corner) coordinates of the second copy region DstRect in the copy destination map Dstimg are (Dx0, Dy0) and the end point (lower right corner) coordinates are (Dx1, Dy1), the region width value Rw of the second copy region may be determined as Dx 1-Dx 0+ 1. Assuming that the first start offset point is Srcpos and the ordinate of the second start offset point Dstpos is dstpos.y, when a preset number of first pixel values read from Srcpos positions are all written to Dstpos positions, a part of data following the preset number of first pixel values will be outside the right side of the frame of the second copy area DstRect, belonging to invalid data. In this case, it can be calculated that after the Dstpos position writes a preset number of first pixel values backward, the coordinate tmp _ Dstpos of the edge pixel point falling on the frame on the right side of DstRect is (Dx0+ Rw, Dstpos.
Optionally, when it is determined that the first pixel value includes a second pixel value written outside the second copy area, correspondingly overlaying an original pixel value of a pixel point corresponding to the second pixel value on a pixel point corresponding to the second pixel value, includes: determining the preset number of pixel points selected rightwards from the edge pixel points in the copy destination picture, wherein the preset number of pixel points comprise pixel points corresponding to the second pixel values; and correspondingly covering the original pixel values of the preset number of pixel points on the preset number of pixel points.
As an alternative embodiment, a preset number of first pixel value data src _ data read from a first start offset point Srcpos position of the copied original image is written into a second start offset point Dstpos position of the copied destination image, where there may be a first pixel value that does not need to be copied outside a right frame of the second copy area DstRect, and the first pixel value outside the right frame of the second copy area DstRect is determined as the second pixel value. The second pixel value is used for representing invalid data, and is a pixel value corresponding to a section of pixel points backward from the start point of the coordinate tmp _ dstpos of the edge pixel point. Assuming that the preset number is 16 and the number of the pixel points corresponding to the second pixel value is 6, at this time, the original pixel values tmp _ dst _ data of the 16 pixel points, which are stored in advance and read from the coordinates tmp _ dstpos of the edge pixel points of the target copy map as a starting point, may be correspondingly covered on the 16 pixel points that have been copied, and the 16 pixel points covered at this time include 6 pixel points corresponding to the second pixel values, so that the covering operation of the invalid original image data copied in the target copy map is completed, and by covering the invalid second pixel values outside the second copy area with the original pixel values, the problem of low original image accuracy caused by the invalid original image data existing in the target map when the image data in the prior art is copied can be solved.
Optionally, a first starting offset point in the first copy area read when a read operation is performed in a current copy operation and a second starting offset point when a write operation is performed in the second copy area are obtained, and the method includes: acquiring an initial offset coordinate value of a work item, wherein the work item is used for copying a pixel point in the original copy image to the image of the copy destination; determining the first initial offset point based on the sum of the initial offset coordinate value and the coordinate value of the initial pixel point of the first copy area; and determining the second initial offset point based on the sum of the initial offset coordinate value and the coordinate value of the initial pixel point of the second copy area.
As an optional implementation manner, each work item of OpenCL obtains a start offset address idx (data of int2 type) of a current work item through get _ global _ id, and calculates a first start offset point Srcpos (int2 type, two-dimensional array) read by copying original pixels through start offset coordinate idx and coordinate values Sx0, Sy0 of a start pixel point of a first copy area, where Srcpos is idx + (int2) (Sx0, Sy 0). Meanwhile, a second initial offset point Dstpos (int2 type, two-dimensional array) written by the copy destination image pixel is calculated by the initial offset coordinate value idx and coordinate values Dx0, Dy0 of the initial pixel point of the second copy area, wherein Dstpos is idx + (int2) (Dx0, Dy 0).
Optionally, determining a region width value of the second copy region includes: updating the original width value of the second copy area to the first copy area width value if the first copy area width value is less than the original width value of the second copy area; keeping the second copy area width value unchanged if the second copy area width value is smaller than the first copy area width value.
As an alternative, assuming that the area width value of the first copy area is SRw and the original width value of the second copy area is DRw, it is necessary to ensure that the area width values of the first copy area SrcRect and the second copy area DstRect are equal, if the area width value of the first copy area SrcRect and the area width value of the second copy area DstRect are not correspondingly equal. The minimum value of the area width value is required to be used as the final width of the copy area, and in the case that the first copy area width value SRw is smaller than the original width value DRw of the second copy area, the original width value DRw of the second copy area is updated to the first copy area width value SRw; in the case where the second copy area width value DRw is less than the first copy area width value SRw, the second copy area width value is kept unchanged.
Optionally, in a case that the preset number of first pixel values are written in the copy destination graph with the second starting offset point as a starting point, determining a first target pixel point corresponding to a pixel value written in the copy destination graph, which is included in the first pixel values, last; and under the condition that the abscissa of the first target pixel point is larger than the abscissa of a second target pixel point, determining a second pixel value which is included in the first pixel value and written outside the second copy area, wherein the second target pixel point is a pixel point located on the right frame of the second copy area.
As an alternative, assume that the second starting offset point is (16,32), the preset number is 16, in the copy destination image, under the condition of writing 16 first pixel values by taking the pixel points (16,32) as starting points, the pixel point corresponding to the last pixel value is determined as a first target pixel point, and determines the coordinates of the first target pixel point to be (31, 32) in the copy destination image, assuming the coordinates of the second target pixel point located on the right frame of the second copy area to be (26,32), the abscissa 31 of the first destination pixel (31, 32) is now greater than the abscissa 26 of the second destination pixel, it may be determined that the written first pixel values include second pixel values written outside the second copy area, and at this time, pixel values corresponding to pixels from the second target pixel (26,32) to the first target pixel (31, 32) may be determined as the second pixel values.
As an optional embodiment, in the image data copying method, a CPU + GPU heterogeneous mode is adopted, the powerful data computing capability of the GPU and the logic scheduling processing capability of the CPU are utilized, an OpenCL parallelization language is used, and platform hardware resources are fully utilized to accelerate data copying operations. Firstly, obtaining corresponding copy area starting point coordinates and width and height information according to an original copy area (SrcRect) of a copy original image (Srcimg) and a target copy area (DstRect) of a copy target image (Dstimg), wherein the SrcRect is composed of four data, namely copy area starting point (upper left corner) coordinates (Sx0, Sy0) and end point (lower right corner) coordinates (Sx1, Sy1), and the DstRect is also composed of four data, namely copy area starting point (upper left corner) coordinates (Dx0, Dy0) and end point (lower right corner) coordinates (Dx1, Dy 1). The width Rw and the height Rh of the copy area are calculated from the coordinate information (it should be noted here that the width and the height of the two copy areas must be the same, and the origin of the coordinates is the coordinate at the upper left corner of the image, the positive direction of the x-axis toward the right, and the positive direction of the y-axis toward the bottom). Assuming that during the operation of OpenCL, the global id (x, y, z) start offset value of each Work item Work-item is idx, idx is temporarily set as Srcpos after being shifted by (Sx0, Sy0), Srcpos is the start point position of reading pixel values from SrcRect of Srcimg, idx is temporarily set as Dstpos after being shifted by (Dx0, Dy0), and Dstpos is the start point position of writing pixel values into DstRect of Dstimg.
Suppose that a work item first fixedly reads a row of 16 pixel values src _ data from the Srcpos position of Srcimg, and then determines what processing mode to do with the 16 pixel values read from the Srcpos position of Srcimg according to the relationship between the starting point idx, the copy region width Rw, and the number 16 of copied pixel values. Is written to the Dstpos location corresponding to Dstimg in the destination graph. Or return directly, without writing data anywhere in Dstimg. Or writing the destination diagram Dstimg to the Dstpos position after edge special processing is needed. And then, sequentially carrying out the operations until all pixels in the copy area SrcRect corresponding to the original image Srcimg are copied to the copy area DstRect corresponding to the target image Dstim, and carrying out special optimization processing on SrcRect edge data in the copying process to ensure that data outside the SrcRect area cannot be copied to Dstim in the whole copying process.
The overall design flow diagram is shown in fig. 3, and the variables in the above are still used in fig. 3 and when introduced. In the following flowcharts and descriptions, num pixels in a row are read at a time by the work item, where num may be 4, 8, 16, and vxc _ uchar16 may be vxc _ uchar4, vxc _ uchar8, float4, or other data types.
As shown in fig. 3, in the method for processing OpenCL-based image copy edge data, a line of num pixel values is read from a certain offset position of a SrcRect frame of an original image to be copied Srcimg, and whether special edge processing is required to be performed on the data is determined according to a relationship among the offset position idx.x, the frame width Rw, and the number num until all copy operations are completed. The flow shown in fig. 3 will be described in detail below.
S301, checking effectiveness of SrcRect and DstRect;
first, width (Sw) and height (Sh) information are acquired from the copy original image Srcimg, and width (Dw) and height (Dh) information are acquired from the copy destination image Dstimg. Copy start (upper left) coordinates (Sx0, Sy0) and end (lower right) coordinates (Sx1, Sy1) are obtained from the original copy region SrcRect, and the width SRw (SRw ═ Sx 1-Sx 0+1) and the height SRh (SRh ═ Sy 1-Sy 0+1) of the original copy frame are calculated. Copy start point (upper left corner) coordinates (Dx0, Dy0) and end point (lower right corner) coordinates (Dx1, Dy1) are obtained from the target copy region DstRect, and the width DRw (DRw ═ Dx 1-Dx 0+1) and the height DRh (DRh ═ Dy 1-Dy 0+1) of the target copy frame are calculated.
Firstly, it is ensured that the copy area SrcRect of the original image Srcimg is always within the effective range of Srcimg. The copy region DstRect of Dstimg of the copy destination must also be within the effective range of Dstimg. The width and height of the SrcRect frame and the DstRect frame are equal, if the width and height of the SrcRect frame and the width and height of the DstRect frame are not correspondingly equal. And taking the minimum value of the width and the height as the width and the height of the final copy frame, keeping the coordinate of the upper left corner of each frame unchanged, and changing the coordinate of the lower right corner along with the change of the width and the height of each frame. Assume that the final copy frame width is denoted Rw and the frame height is denoted Rh.
Step S302, checking the validity of the initial coordinates of the OpenCL workitems;
each work item work is to obtain the start address idx (data of int2 type) of the current work item through get _ global _ id. If idx.x is less than 0 or idx.y is less than 0, the coordinate area is located outside the image area and belongs to the invalid starting address idx, and the copying task of the work item can be finished directly.
Step S303, determining the positions of Srcpos and Dstpos;
during the operation of each work item, obtaining a start offset value idx (data of int2 type, two-dimensional array) of the current work item through get _ global _ id (), calculating a copy original image pixel reading start offset point Srcpos (int2 type, two-dimensional array) through idx and Sx0, Sy0, wherein Srcpos is idx + (int2) (Sx0, Sy 0);
calculating copy destination image pixel writing starting offset points Dstpos (int2 type, two-dimensional array) through idx and Dx0, Dy0, Dstpos ═ idx + (int2) (Dx0, Dy 0).
Step S304, reading the pixel value and judging whether edge data processing is needed or not;
a row of num pixel values is read from the Srcpos location where the original image Srcimg was copied and saved in the src _ data (vxc _ uchar16 type array) variable. Whether the read src _ data needs to be specially processed can be determined according to the following three cases.
Step S3041, idx.x + Sx0+ num is less than or equal to Rw + Sx0 or idx.x + num is less than or equal to Rw;
in this case, srcpos.x indicates that the x-coordinate position indicated by srcpos.x is inside the region of SrcRect of Srcimg, and that the coordinate position srcpos.x + num-1 after reading num pixels from the srcpos.x coordinate is still inside SrcRect. The num pixel values src _ data thus read from the srcpos.x location of Srcimg are all internal to SrcRect and are valid data that require copying. In this case, no special processing is required for the x-ordinate of srcpos.x, dstpos.x. The process advances to step S306.
Step S3042, idx.x + Sx0 is more than or equal to Rw + Sx0 or idx.x is more than or equal to Rw;
in this case it is indicated that the x coordinate position indicated by srcpos.x is already to the right of Srcimg's SrcRect right border. In this case, no copy operation is required, and the return returns to the copy task that ends the work item this time. The process advances to step S306.
Step S3043, Rw + Sx0< idx.x + Sx0+ num and idx.x + Sx0< Rw + Sx0, i.e., idx.x + Sx0< Rw + Sx0< idx.x + Sx0+ num, i.e., idx.x < Rw < idx.x + num, indicates that the x-coordinate position indicated by srcpos.x is inside the region of srcmg' S srcpect and the coordinate position after reading num pixels from srcpos.x coordinates is outside the right side box of srcpect. If a row of num pixel values src _ data is read from srcpos.x of Srcimg at this time, the num pixel values are partly inside the SrcRect frame (valid data that needs to be copied) and partly outside the right frame of SrcRect (invalid data that does not need to be copied). If the num pixel values of src _ data are written directly to the Dstpos coordinate locations of Dstimg at this time, this will result in part of the invalid data being written to the Dstimg map. If the problem is to be solved, special operations are made to deal with the problem. Step S305 will focus on the processing method.
Step S305, an edge data special processing method;
this section will focus on the description of the processing method on the premise of the case of step S3043 in step S304. The main core idea of processing is image data overlay.
Step S3051, determining a tmp _ dstpos position in Dstimg;
when num pixels read from the Srcpos location are written in their entirety to the Dstpos location, the data of the portion following src _ data will be outside the right side of the DstRect frame and belong to invalid data. In this case, it can be calculated that the coordinates tmp _ Dstpos of the point falling on the right frame of DstRect, i.e., tmp _ Dstpos ═ is (Dx0+ Rw, dstpos.y), after the Dstpos position is written backward by num pixel points.
Step S3052, obtaining tmp _ dst _ data from a tmp _ dstpos position;
num pixel values are read from the tmp _ dstp position of the destination copy map and saved in the tmp _ dst _ data variable. Where the num pixel values held in tmp _ dst _ data are all the data outside the right frame of DstRect.
Step S3053, writing the src _ data into the Dstpos position;
num pixel value src _ data read from the Srcpos position of the copied original image is written into the Dstpos position of the copy destination image, and invalid original image data which does not need to be copied exists outside the right frame of the DstRect (a section of pixel area backward from the tmp _ Dstpos as the starting point).
Step S3054, writing tmp _ dst _ data into a tmp _ dstpos position;
the tmp _ dst _ data of num pixel values read from the tmp _ dstpos position of the destination copy map in step S3052 is written to the tmp _ dstpos position of the destination copy map (the ineffective original image data which does not need to be copied in step S3053 is overwritten). The process advances to step S306.
And S306, if all data copying is finished, ending the operation, and otherwise, returning to the step S302.
As an optional embodiment, in the event of an abnormal edge, the present invention recalculates the tmp _ Dstpos position according to the values of the x coordinate Dx0 at the upper left corner of the copy destination image DstRect, the width Rw of the DstRect frame, and the y coordinate dstpos.y of the destination image writing pixel value start point Dstpos, where tmp _ Dstpos is (Dx0+ Rw, dstpos.y). And reads num pixel values tmp _ dst _ data from the tmp _ dstpos location of the destination map. And solving the problem of invalid data at the edge by adopting a data-first covering mode. And overwriting tmp _ dst _ data with invalid data in src _ data written in the right side of the DstRect border frame from the tmp _ dstpos position. The problem of edge invalid data is solved by combining tmp _ dstpos position calculation, tmp _ dst _ data pixel value reading, src _ data writing, tmp _ dst _ data writing coverage and the like.
Through the above description of the embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but the former is a better implementation mode in many cases. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present invention.
In this embodiment, a copying apparatus for image pixels is also provided, and the apparatus is used to implement the foregoing embodiments and preferred embodiments, and the description of which has been already made is omitted. As used below, the term "module" may be a combination of software and/or hardware that implements a predetermined function. Although the means described in the embodiments below are preferably implemented in software, an implementation in hardware, or a combination of software and hardware is also possible and contemplated.
FIG. 4 is a block diagram of an apparatus for copying pixels of an image according to an embodiment of the present invention, as shown in FIG. 4, the apparatus includes a first determining module 42 for determining a first copy area for copying original images and a second copy area for copying destination images; an obtaining module 44, configured to obtain a first starting offset point in the first copy area read when a read operation is performed in a current copy operation, and a second starting offset point when a write operation is performed in the second copy area, where the second starting offset point is located in the second copy area; a writing module 46, configured to read a preset number of first pixel values from the first initial offset point, and write the first pixel values in the copy destination map with the second initial offset point as a starting point; and a covering module 48, configured to, in a case that it is determined that the first pixel value includes a second pixel value written outside the second copy area, correspondingly cover an original pixel value of a pixel point corresponding to the second pixel value on a pixel point corresponding to the second pixel value, where the pixel point corresponding to the second pixel value is the pixel point written with the second pixel value in the copy destination image.
Optionally, the original pixel value in the above-mentioned overlay module 48 is determined by: in the copy destination graph, under the condition that the second initial offset point is used as a starting point to write the first pixel values of the preset number in the copy destination graph, coordinates of edge pixel points positioned on a right frame of the second copy area in pixel points corresponding to the first pixel values of the preset number are predetermined; and based on the coordinates of the edge pixel points, acquiring and storing original pixel values of the preset number of pixel points selected from the edge pixel points to the right in the copied target image, wherein the original pixel values of the preset number of pixel points comprise the original pixel values of the pixel points corresponding to the second pixel values.
Optionally, the apparatus further comprises: a second determining module for determining a region width value of the second copy region; a third determining module, configured to determine a sum of an abscissa value of a coordinate point of a start pixel located in the second copy area and the area width value as an abscissa of the edge pixel point; and the fourth determining module is used for determining the ordinate value of the second initial offset point as the ordinate of the edge pixel point.
Optionally, the writing module 46 includes: the first determining submodule is used for determining the pixels of the preset number which are selected rightwards from the edge pixels in the copied target image, wherein the pixels of the preset number comprise pixels corresponding to the second pixel value; and the covering submodule is used for correspondingly covering the original pixel values of the preset number of the pixels on the preset number of the pixels.
Optionally, the obtaining module 44 includes: the obtaining submodule is used for obtaining an initial offset coordinate value of a work item, wherein the work item is used for copying pixel points in the original copy image to the copy target image; a second determining submodule for determining the first initial offset point based on the sum of the initial offset coordinate value and the coordinate value of the initial pixel point of the first copy area; and a third determining submodule, configured to determine the second initial offset point based on a sum of the initial offset coordinate value and a coordinate value of an initial pixel point of the second copy area.
Optionally, the fifth determining module further includes: an updating subunit, configured to update the original width value of the second copy area to the first copy area width value when the first copy area width value is smaller than the original width value of the second copy area; and the comparison submodule is used for keeping the second copy area width value unchanged under the condition that the second copy area width value is smaller than the first copy area width value.
The above-mentioned device still includes: a sixth determining module, configured to determine, when the preset number of first pixel values are written in the copy destination graph with the second initial offset point as a starting point, a first target pixel point corresponding to a last pixel value written in the copy destination graph included in the first pixel values; a seventh determining module, configured to determine, when the abscissa of the first target pixel is greater than the abscissa of a second target pixel, a second pixel value that is included in the first pixel value and is written outside the second copy area, where the second target pixel is a pixel located on a right frame of the second copy area.
It should be noted that, the above modules may be implemented by software or hardware, and for the latter, the following may be implemented, but not limited to: the modules are all positioned in the same processor; alternatively, the modules are respectively located in different processors in any combination.
Embodiments of the present invention also provide a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the method as set forth in any of the above.
Alternatively, in the present embodiment, the storage medium may be configured to store a computer program for executing the steps of:
s1, determining a first copying area for copying the original image and a second copying area for copying the destination image;
s2, acquiring a first initial offset point in the first copy area read when a read operation is performed in the current copy operation, and a second initial offset point when a write operation is performed in the second copy area, where the second initial offset point is located in the second copy area;
s3, reading a preset number of first pixel values from the first initial offset point, and writing the first pixel values in the copy destination graph with the second initial offset point as a starting point;
s4, under the condition that it is determined that the first pixel value includes a second pixel value written in the outside of the second copy area, correspondingly covering an original pixel value of a pixel point corresponding to the second pixel value on a pixel point corresponding to the second pixel value, where the pixel point corresponding to the second pixel value is the pixel point written in the copy destination image.
In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to: various media capable of storing computer programs, such as a usb disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic disk, or an optical disk.
Embodiments of the present invention also provide an electronic device comprising a memory having a computer program stored therein and a processor arranged to run the computer program to perform the steps of any of the above method embodiments.
In an exemplary embodiment, the electronic apparatus 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.
For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary embodiments, and details of this embodiment are not repeated herein.
Optionally, in this embodiment, the processor may be configured to execute the following steps by a computer program:
s1, determining a first copying area for copying the original image and a second copying area for copying the destination image, wherein the second starting offset point is located in the second copying area;
s2, acquiring a first initial offset point in the first copy area read when a read operation is executed in the current copy operation, and a second initial offset point when a write operation is executed in the second copy area;
s3, reading a preset number of first pixel values from the first initial offset point, and writing the first pixel values in the copy destination graph with the second initial offset point as a starting point;
s4, under the condition that it is determined that the first pixel value includes a second pixel value written in the outside of the second copy area, correspondingly covering an original pixel value of a pixel point corresponding to the second pixel value on a pixel point corresponding to the second pixel value, where the pixel point corresponding to the second pixel value is the pixel point written in the copy destination image.
It will be apparent to those skilled in the art that the various modules or steps of the invention described above may be implemented using a general purpose computing device, they may be centralized on a single computing device or distributed across a network of computing devices, and they may be implemented using program code executable by the computing devices, such that they may be stored in a memory device and executed by the computing device, and in some cases, the steps shown or described may be performed in an order different than that described herein, or they may be separately fabricated into various integrated circuit modules, or multiple ones of them may be fabricated into a single integrated circuit module. Thus, the present invention is not limited to any specific combination of hardware and software.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. A method of copying pixels of an image, comprising:
determining a first copying area for copying the original image and a second copying area for copying the destination image;
acquiring a first starting offset point in the first copy area read when a read operation is executed in a current copy operation and a second starting offset point when a write operation is executed in the second copy area, wherein the second starting offset point is located in the second copy area;
reading a preset number of first pixel values from the first initial offset point, and writing the first pixel values in the copy destination graph by taking the second initial offset point as a starting point;
and correspondingly covering the original pixel value of the pixel point corresponding to the second pixel value on the pixel point corresponding to the second pixel value under the condition that the first pixel value comprises the second pixel value written in the second copying area, wherein the pixel point corresponding to the second pixel value is the pixel point written in the second pixel value in the copying target image.
2. The method of claim 1, wherein the raw pixel value is determined by:
in the copy destination graph, under the condition that the second initial offset point is used as a starting point to write the first pixel values of the preset number in the copy destination graph, coordinates of edge pixel points positioned on a right frame of the second copy area in pixel points corresponding to the first pixel values of the preset number are predetermined;
and based on the coordinates of the edge pixel points, acquiring and storing original pixel values of the preset number of pixel points selected from the edge pixel points to the right in the copied target image, wherein the original pixel values of the preset number of pixel points comprise the original pixel values of the pixel points corresponding to the second pixel values.
3. The method according to claim 2, wherein, in the copy destination graph, when the first pixel value is written using the second initial offset point as a starting point, predetermining coordinates of edge pixel points located on a right frame of the second copy area among the pixel points corresponding to the preset number of first pixel values, comprises:
determining a region width value for the second copy region;
determining the sum of the abscissa value of the coordinate point of the initial pixel in the second copy area and the area width value as the abscissa of the edge pixel point;
and determining the ordinate value of the second initial offset point as the ordinate of the edge pixel point.
4. The method according to claim 2, wherein in a case that it is determined that the first pixel value includes a second pixel value written outside the second copy area, overlaying an original pixel value of a pixel point corresponding to the second pixel value on a pixel point corresponding to the second pixel value correspondingly comprises:
determining the preset number of pixel points selected rightwards from the edge pixel points in the copy destination picture, wherein the preset number of pixel points comprise pixel points corresponding to the second pixel values;
and correspondingly covering the original pixel values of the preset number of pixel points on the preset number of pixel points.
5. The method of claim 3, wherein determining the region width value for the second copy region comprises:
updating the original width value of the second copy area to the first copy area width value if the first copy area width value is less than the original width value of the second copy area;
keeping the second copy area width value unchanged if the second copy area width value is smaller than the first copy area width value.
6. The method of claim 1, further comprising:
determining a first target pixel point corresponding to a pixel value written into the copy destination graph at the last included in the first pixel value under the condition that the preset number of first pixel values are written into the copy destination graph by taking the second initial offset point as a starting point;
and under the condition that the abscissa of the first target pixel point is larger than the abscissa of a second target pixel point, determining a second pixel value which is included in the first pixel value and written outside the second copy area, wherein the second target pixel point is a pixel point located on the right frame of the second copy area.
7. An apparatus for copying pixels of an image, comprising:
the first determining module is used for determining a first copying area for copying the original image and a second copying area for copying the destination image;
an obtaining module, configured to obtain a first starting offset point in the first copy area read when a read operation is performed in a current copy operation, and a second starting offset point when a write operation is performed in the second copy area, where the second starting offset point is located in the second copy area;
a writing module, configured to read a preset number of first pixel values from the first initial offset point, and write the first pixel values in the copy destination graph with the second initial offset point as a starting point;
and the covering module is used for correspondingly covering the original pixel value of the pixel point corresponding to the second pixel value on the pixel point corresponding to the second pixel value under the condition that the first pixel value is determined to comprise the second pixel value written in the second copying area, wherein the pixel point corresponding to the second pixel value is the pixel point written in the second pixel value in the copying target image.
8. The apparatus of claim 7, wherein the raw pixel value is determined by:
in the copy destination graph, under the condition that the second initial offset point is used as a starting point to write the first pixel values of the preset number in the copy destination graph, coordinates of edge pixel points positioned on a right frame of the second copy area in pixel points corresponding to the first pixel values of the preset number are predetermined;
and based on the coordinates of the edge pixel points, acquiring and storing original pixel values of the preset number of pixel points selected from the edge pixel points to the right in the copied target image, wherein the original pixel values of the preset number of pixel points comprise the original pixel values of the pixel points corresponding to the second pixel values.
9. A computer-readable storage medium, in which a computer program is stored, which computer program, when being executed by a processor, carries out the method of any one of claims 1 to 6.
10. An electronic device comprising a memory and a processor, wherein the memory has stored therein a computer program, and wherein the processor is arranged to execute the computer program to perform the method of any of claims 1 to 6.
CN202210617311.7A 2022-06-01 2022-06-01 Image pixel copying method, image pixel copying device, storage medium and electronic device Pending CN114897661A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210617311.7A CN114897661A (en) 2022-06-01 2022-06-01 Image pixel copying method, image pixel copying device, storage medium and electronic device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210617311.7A CN114897661A (en) 2022-06-01 2022-06-01 Image pixel copying method, image pixel copying device, storage medium and electronic device

Publications (1)

Publication Number Publication Date
CN114897661A true CN114897661A (en) 2022-08-12

Family

ID=82725517

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210617311.7A Pending CN114897661A (en) 2022-06-01 2022-06-01 Image pixel copying method, image pixel copying device, storage medium and electronic device

Country Status (1)

Country Link
CN (1) CN114897661A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117055790A (en) * 2023-08-11 2023-11-14 广东盈科电子有限公司 Interactive control method and device applied to image test area and storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117055790A (en) * 2023-08-11 2023-11-14 广东盈科电子有限公司 Interactive control method and device applied to image test area and storage medium
CN117055790B (en) * 2023-08-11 2024-02-13 广东盈科电子有限公司 Interactive control method and device applied to image test area and storage medium

Similar Documents

Publication Publication Date Title
CN107438860B (en) Architecture for high performance power efficient programmable image processing
US7663621B1 (en) Cylindrical wrapping using shader hardware
US7038686B1 (en) Programmable graphics processor for multithreaded execution of programs
EP2023292A1 (en) Processing device
CN102648449A (en) Trap handler architecture for a parallel processing unit
US10943389B2 (en) Removing or identifying overlapping fragments after z-culling
KR20100017645A (en) Dynamic motion vector analysis method
US7760205B2 (en) Information processing apparatus for efficient image processing
CN109242967B (en) Three-dimensional terrain rendering method and device
KR20210070369A (en) Data reading/writing method and system, storage medium and terminal during 3D image processing
CN114897661A (en) Image pixel copying method, image pixel copying device, storage medium and electronic device
CN110232665B (en) Maximum pooling method and device, computer equipment and storage medium
CN113506305B (en) Image enhancement method, semantic segmentation method and device for three-dimensional point cloud data
WO2023151386A1 (en) Data processing method and apparatus, and terminal and readable storage medium
US11748933B2 (en) Method for performing shader occupancy for small primitives
US11798218B2 (en) Methods and apparatus for pixel packing
EP4231243A1 (en) Data storage management method, object rendering method, and device
CN114372928A (en) Data processing method and device and electronic equipment
CN114627225A (en) Method and device for rendering graphics and storage medium
CN115049529A (en) Image gradient determination method, device, equipment and storage medium
CN111179399A (en) Image rendering method, device and system and storage medium
US20130328884A1 (en) Direct opencl graphics rendering
CN116188552B (en) Region-based depth test method, device, equipment and storage medium
US9978117B2 (en) Semiconductor apparatus and high speed image data processing
CN117093105B (en) Label display method, device, equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination