Image downsampling method and image processing device
Through the DMA function of the processor, image downsampling is performed using the three-dimensional data transmission mode, which solves the problems of low efficiency and high resource consumption in the prior art, and realizes efficient image downsampling and batch processing.
Patent Information
- Application Number
- CN202411329492.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-24
- Publication Date
- 2024-12-13
AI Technical Summary
The existing image downsampling methods are inefficient and consume large processor resources, which cannot meet the needs of efficient downsampling and batch image processing, especially in low-main frequency processors with poor real-time performance.
Using the DMA function of the processor, by defining the three-dimensional data transmission mode, using ACNT, BCNT and CCNT parameters for image downsampling, to achieve rapid data disassembly and extract, and reduce processor computing pressure.
It significantly improves image processing efficiency, reduces processor resource consumption, and realizes fast image downsampling, which is suitable for efficient batch image processing.
Smart Images

Figure CN119135862A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to an image downsampling method and an image processing device, and belongs to the technical field of image processing. Background Art
[0002] Image downsampling is often involved in some image algorithms or image processing software. Downsampling high-resolution images can reduce the computing overhead of the computing platform. The most common method is to use a for loop (a type of C language) for extraction, which is simple and easy to implement. However, if the computing platform has a low main frequency, high algorithm efficiency requirements, or many images need to be downsampled, it is very necessary to improve the efficiency of image downsampling.
[0003] Common downsampling methods are as follows: 1) Using the CPU to achieve downsampling, the for loop extraction method is used, but this method is inefficient and occupies too much CPU resources. It is not suitable for batch image processing or low-frequency processors; 2) Using the VPU (Video Process Unit) module for processing, the real-time performance is very good, but general chips do not have VPU modules and their costs are relatively high; 3) Using the image sensor to reduce the resolution. This method is to directly achieve the purpose of downsampling by configuring the image sensor resolution. This operation requires a series of software operation processes and has poor real-time performance. Similar to the iris and eye key point recognition algorithms, its real-time performance is difficult to meet the requirements. Summary of the invention
[0004] The present invention provides an image downsampling method and an image processing device, which can solve the problems that the existing downsampling method cannot achieve fast downsampling, has low algorithm efficiency, and consumes a large amount of processor resources.
[0005] In one aspect, the present invention provides an image downsampling method, the method comprising: S1, obtaining an image to be sampled and a downsampling requirement, and storing the image to be sampled byte by byte in a processor cache; S2, determining the dimension parameters of the EDMA transmission mode according to the image to be sampled and the downsampling requirement; the dimension parameters include ACNT parameters, BCNT parameters and CCNT parameters; S3. Perform byte extraction on the image to be sampled stored in the processor cache according to the dimension parameter to obtain a sampled image that meets the downsampling requirement.
[0006] Optionally, the S3 specifically includes: S31, determining an interval parameter according to the image to be sampled and the dimension parameter; the interval parameter includes a one-dimensional data interval parameter and a two-dimensional data interval parameter; S32. Perform byte extraction on the image to be sampled stored in the processor cache according to the dimension parameter and the interval parameter to obtain a sampled image that meets the downsampling requirement.
[0007] Optionally, the S31 is specifically: Obtaining a ratio of the number of columns of the image to be sampled to the number of columns after sampling in the downsampling requirement, and obtaining a product of the ratio and the ACNT parameter, and using the product as a one-dimensional data interval parameter; The ratio of the number of image rows to be sampled to the number of rows after sampling in the downsampling requirement is obtained, and the product of the ratio and the ACNT parameter is obtained, and the product is used as the two-dimensional data interval parameter.
[0008] Optionally, the S32 specifically includes: S321, setting the read / write mode of the memory address, and inputting the ACNT parameter and the BCNT parameter; S322, setting a source address position for reading the image to be sampled and a destination address position for storing the sampled image, and inputting the one-dimensional data interval parameter, the two-dimensional data interval parameter and the CCNT parameter; S323, querying the status bit of the status register, and obtaining a sampled image that meets the downsampling requirement when the status bit of the status register indicates that the data transmission is completed.
[0009] Optionally, when the image to be sampled is a black and white image, the ACNT parameter is 1 or 2; When the image to be sampled is a color image, the ACNT parameter is 2.
[0010] Optionally, the BCNT parameter is the number of columns after sampling in the downsampling requirement; The CCNT parameter is the number of post-sampling rows or half of the number of post-sampling rows in the downsampling requirement.
[0011] In another aspect, the present invention provides an image processing device, the device comprising: an image collector, a processor connected to the image collector, and a transmission chip connected to the processor; The image collector is used to collect the image to be sampled; The processor is used to downsample the image to be sampled using any of the above methods to obtain a sampled image; The transmission chip is used to transmit the sampled image to a processing terminal.
[0012] Optionally, the processor is an ARM processor; the ARM processor is connected to the image collector via a DVP interface, and is connected to the transmission chip via a FIFO interface.
[0013] Optionally, the transmission chip is a USB interface chip; the USB interface chip is connected to the processing terminal via a USB2.0 or USB3.0 interface.
[0014] The beneficial effects that the present invention can produce include: The image downsampling method provided by the present invention defines data on a three-dimensional scale by using the DMA function of the processor, which is beneficial to the disassembly and extraction of data, thereby realizing rapid downsampling, which can significantly reduce the computing pressure of the processor, reduce the processor resource consumption, and improve the image processing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 The image downsampling method provided by the embodiment of the present invention is as follows: Figure 1 ; Figure 2 The image downsampling method provided by the embodiment of the present invention is as follows: Figure 2 ; Figure 3 A schematic diagram of image pixel distribution provided by an embodiment of the present invention; Figure 4 A schematic diagram of image data composition provided by an embodiment of the present invention; Figure 5 A schematic diagram of a three-dimensional data structure in an EDMA transmission mode provided by an embodiment of the present invention; Figure 6 A schematic diagram of the image downsampling principle provided by an embodiment of the present invention; Figure 7 A schematic diagram of the image downsampling principle using the EDMA function provided by an embodiment of the present invention; Figure 8 A schematic diagram of the structure of an image processing device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0016] The present invention is described in detail below in conjunction with embodiments, but the present invention is not limited to these embodiments.
[0017] The embodiment of the present invention provides an image downsampling method, such as Figure 1 As shown, the method includes: S1, obtaining the image to be sampled and the downsampling requirement, and storing the image to be sampled byte by byte in the processor cache; S2, determining the dimension parameters of the EDMA transmission mode according to the image to be sampled and the downsampling requirements; the dimension parameters include ACNT parameters, BCNT parameters and CCNT parameters; S3. Extract bytes of the image to be sampled stored in the processor cache according to the dimension parameter to obtain a sampled image that meets the downsampling requirements.
[0018] refer to Figure 3 As shown, through the pixel distribution analysis of the image sensor, in order to obtain a complete pixel, it is necessary to extract the image data of two adjacent positions for calculation. This is because each pixel point only senses one kind of light (red, green, and blue), Gr and Gb only sense green light, R only senses red light, and B only senses blue light. For the four pixels shown in the thick black frame in the figure, if you want to get the pixel value of the Gr position, you need to calculate Gr, B, and R. Similarly, the pixel value of the R position needs to be calculated by Gb, B, and R.
[0019] Assuming that the image sensor outputs an image of size 2560 x 1944, each pixel corresponds to one byte, for a total of 4976640 bytes. The data is composed as follows: Figure 4 As shown, the image with this resolution needs to be downsampled to an image with a resolution of 640x480. According to the requirements of image composition, such as Figure 3 From the analysis, we can know that the data in the black dashed box needs to be extracted. It should be noted that the 4976640 bytes are stored continuously in the memory, that is, Y0_0 is the first data, Y0_1 is the second data, and so on to Y0_2559, and then the next data is Y1_0, and so on.
[0020] If the traditional algorithm is used for data extraction, the code is shown in Table 1 below. The amount of processor computing is huge. If the downsampling is changed to 1280x960, the amount of processor computing will be doubled.
[0021] Table 1 Traditional data extraction algorithms
[0022] The embodiment of the present invention proposes a new idea, which uses the EDMA function of the processor to extract data and realize image downsampling. The processor's DMA supports a transmission mode called EDMA3 (Enhanced Direct Memory Access). EDMA3 can be defined from three dimensions, such as Figure 5 As shown, ACNT represents the first dimension data, that is, the continuous byte transmission amount, BCNT represents the second dimension data, that is, the number of ACNT transmissions, and CCNT represents the third dimension data, that is, the number of BCNT transmissions. This data composition method is conducive to data disassembly and extraction.
[0023] According to the aforementioned Figure 4 analysis, Figure 4 The structure is adjusted to obtain Figure 6 ,from Figure 6 You can see the spatial relationship between the original 2560x 1944 bytes of data and the 640x480 bytes to be extracted. The light-colored parts are all the bytes to be extracted, and the dark-colored parts are the bytes to be discarded.
[0024] according to Figure 6 As shown, the data is simplified to obtain Figure 7 ,from Figure 7 You can see that the data composition has been Figure 5 The results are consistent, and the specific values of ACNT parameter, BCNT parameter and CCNT parameter are obtained by calculation.
[0025] Specifically, when the image to be sampled is a black and white image, the ACNT parameter can be 1 or 2; When the image to be sampled is a color image, the ACNT parameter is 2.
[0026] The BCNT parameter is the number of columns after sampling in the downsampling requirement; for example, if the downsampling requirement is to downsample a 2560 x 1944 image to 640x480, the BCNT parameter is 640.
[0027] The CCNT parameter is the number of rows after sampling or half of the number of rows after sampling in the downsampling requirement. If the image to be sampled is a black and white image, the CCNT parameter is the number of rows after sampling or half of the number of rows after sampling in the downsampling requirement. In the above example, the CCNT parameter is 480 or 240; if the image to be sampled is a color image, the CCNT parameter is half of the number of rows after sampling in the downsampling requirement. In the above example, the CCNT parameter is 240.
[0028] After determining the specific values of the ACNT parameter, the BCNT parameter, and the CCNT parameter, S3 specifically includes: S31. Determine an interval parameter according to the image to be sampled and the dimension parameter; the interval parameter includes a one-dimensional data interval parameter and a two-dimensional data interval parameter.
[0029] Specifically: Get the ratio of the number of columns of the image to be sampled to the number of columns after sampling in the downsampling requirement, and get the product of the ratio and the ACNT parameter, and use the product as the one-dimensional data interval parameter. Taking the above example, if the ACNT parameter is 2, the one-dimensional data interval parameter is 2560 / 640*2=8 bytes.
[0030] Get the ratio of the number of rows of the image to be sampled to the number of rows after sampling in the downsampling requirement, and get the product of the ratio and the ACNT parameter, and use the product as the two-dimensional data interval parameter. Taking the above example, the ACNT parameter is 2, then the two-dimensional data interval parameter is [1944 / 480*2]=8 rows.
[0031] S32, performing byte extraction on the image to be sampled stored in the processor cache according to the dimension parameter and the interval parameter to obtain a sampled image that meets the downsampling requirement.
[0032] refer to Figure 2 As shown, specifically including: S321. Set the read and write mode of the memory address and input ACNT parameters and BCNT parameters.
[0033] Among them, the reading and writing modes of the memory address include multiple modes, such as an increment mode, a decrement mode, etc., which are not limited in the embodiment of the present invention.
[0034] S322, setting a source address position for reading the image to be sampled and a destination address position for storing the sampled image, and inputting a one-dimensional data interval parameter, a two-dimensional data interval parameter and a CCNT parameter.
[0035] Taking the above example, after setting the source address position and the destination address position, you can set an interval of 8 bytes after one-dimensional data extraction and then perform a second extraction, and so on; set a two-byte interval after one-dimensional data extraction and then perform the next storage, and so on; set an interval of 8 rows after two-dimensional data extraction and then perform a second extraction, and so on; then set the value of the three-dimensional CCNT parameter to ensure that all row data are processed.
[0036] S323, querying the status bit of the status register, and obtaining a sampled image that meets the downsampling requirement when the status bit of the status register indicates that the data transmission is completed.
[0037] The code of the above method is shown in Table 2 below: Table 2 Downsampling algorithm of the present invention
[0038] The embodiment of the present invention only needs simple codes to realize downsampling of images of any size. Through experiments, the above process only needs about 5ms to complete the compression of 2560x1944 to 640x480 images. Similarly, by adjusting the parameter values of the above processor, image downsampling of other sizes can be quickly realized.
[0039] The image downsampling method provided by the present invention defines data on a three-dimensional scale by using the DMA function of the processor, which is beneficial to the disassembly and extraction of data, thereby realizing rapid downsampling, which can significantly reduce the computing pressure of the processor, reduce the processor resource consumption, and improve the image processing efficiency.
[0040] Another embodiment of the present invention provides an image processing device, such as Figure 8As shown, the device includes: an image collector, a processor connected to the image collector, and a transmission chip connected to the processor; The image collector is used to collect the image to be sampled; wherein the image collector can be an image sensor.
[0041] The processor is used to downsample the sampled image using any of the methods described above to obtain a sampled image; wherein the processor can be an ARM processor; the ARM processor is connected to the image collector through a DVP (Digital Video Port) interface, and is connected to the transmission chip through a FIFO (First Input First Output) interface.
[0042] The transmission chip is used to transmit the sampled image to the processing terminal. The transmission chip can be a USB (Universal Serial Bus) interface chip; the USB interface chip is connected to the processing terminal through a USB2.0 or USB3.0 interface.
[0043] refer to Figure 8 As shown in the figure, the image sensor outputs an image size of 2560x1944, the ARM processor has a main frequency of 432MHz, and the USB interface chip supports high-speed USB2.0 protocol or USB3.0 protocol. The ARM processor obtains image data through the DVP (Digital Video Port) interface, and then sends the data to the USB interface chip through the FIFO (First Input First Output) interface. The USB interface chip sends the data to the processing terminal through the USB2.0 or USB3.0 interface.
[0044] The image processing device provided by the present invention has a processor and a transmission chip arranged before the processing terminal, uses the processor to complete image downsampling, and uses the transmission chip to transmit the sampled image to the processing terminal, so that the processing terminal omits several steps that consume a lot of resources, such as image decompression and image downsampling, so that the efficiency of the processing terminal will be greatly improved. At the same time, since the solution does not compress the image, the image transmitted to the processing terminal is lossless, which is more conducive to processing such as image recognition and improves the accuracy.
[0045] The above are only a few embodiments of the present application and do not constitute any form of limitation to the present application. Although the present application is disclosed as above with preferred embodiments, it is not intended to limit the present application. Any technician familiar with the profession, without departing from the scope of the technical solution of the present application, using the technical content disclosed above to make slight changes or modifications are equivalent to equivalent implementation cases and fall within the scope of the technical solution.
Claims
1. An image downsampling method, characterized in that: The method comprises: S1, obtaining an image to be sampled and a downsampling requirement, and storing the image to be sampled byte by byte in a processor cache; S2, determining the dimension parameters of the EDMA transmission mode according to the image to be sampled and the downsampling requirement; the dimension parameters include ACNT parameters, BCNT parameters and CCNT parameters; S3. Perform byte extraction on the image to be sampled stored in the processor cache according to the dimension parameter to obtain a sampled image that meets the downsampling requirement.
2. The method according to claim 1, characterized in that The S3 specifically includes: S31, determining an interval parameter according to the image to be sampled and the dimension parameter; the interval parameter includes a one-dimensional data interval parameter and a two-dimensional data interval parameter; S32. Perform byte extraction on the image to be sampled stored in the processor cache according to the dimension parameter and the interval parameter to obtain a sampled image that meets the downsampling requirement.
3. The method according to claim 2, characterized in that The S31 is specifically: Obtaining a ratio of the number of columns of the image to be sampled to the number of columns after sampling in the downsampling requirement, and obtaining a product of the ratio and the ACNT parameter, and using the product as a one-dimensional data interval parameter; The ratio of the number of image rows to be sampled to the number of rows after sampling in the downsampling requirement is obtained, and the product of the ratio and the ACNT parameter is obtained, and the product is used as the two-dimensional data interval parameter.
4. The method according to claim 2, characterized in that: The S32 specifically includes: S321, setting the read / write mode of the memory address, and inputting the ACNT parameter and the BCNT parameter; S322, setting a source address position for reading the image to be sampled and a destination address position for storing the sampled image, and inputting the one-dimensional data interval parameter, the two-dimensional data interval parameter and the CCNT parameter; S323, querying the status bit of the status register, and obtaining a sampled image that meets the downsampling requirement when the status bit of the status register indicates that the data transmission is completed.
5. The method according to claim 1, characterized in that When the image to be sampled is a black and white image, the ACNT parameter is 1 or 2; When the image to be sampled is a color image, the ACNT parameter is 2.
6. The method according to claim 1 or 5, characterized in that: The BCNT parameter is the number of columns after sampling in the downsampling requirement; The CCNT parameter is the number of post-sampling rows or half of the number of post-sampling rows in the downsampling requirement.
7. An image processing device, characterized in that: The device comprises: an image collector, a processor connected to the image collector, and a transmission chip connected to the processor; The image collector is used to collect the image to be sampled; The processor is used to downsample the image to be sampled using the method described in any one of claims 1 to 6 to obtain a sampled image; The transmission chip is used to transmit the sampled image to a processing terminal.
8. The device according to claim 7, characterized in that The processor is an ARM processor; the ARM processor is connected to the image collector through a DVP interface, and is connected to the transmission chip through a FIFO interface.
9. The device according to claim 8, characterized in that The transmission chip is a USB interface chip; the USB interface chip is connected to the processing terminal via a USB2.0 or USB3.0 interface.
Citation Information
Cited By
De-sampling method based on jitter and storage medium
CN120835124A
Dithering-based down-sampling method and storage medium
CN120835124B
