Image processing method based on Floyd algorithm, electronic equipment, storage medium and program product
By using n+1 storage space and cache updates in the Floyd-Steinberg error diffusion algorithm, the problem of storage space requirements in high-resolution OLED displays is solved, and more efficient image processing and display effect are achieved.
Patent Information
- Application Number
- CN202411278544.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-12
- Publication Date
- 2025-01-03
AI Technical Summary
The existing Floyd-Steinberg error diffusion algorithm needs to store grayscale values of multiple rows or even entire frames of pixels when processing images, resulting in a large demand for storage space and cannot meet the needs of high-resolution OLED display technology for improving image display quality.
By designing the error list and cache area, n+1 storage space is used to store the intermediate value of error accumulation during image processing, the cache update degradation algorithm is used to reduce the storage space requirement, and differentiate the parity frames in the time dimension for differential processing. Achieve error diffusion.
The storage space required by the error diffusion algorithm is greatly reduced, the image display quality is improved, and the average error diffusion in the time dimension is improved through parity frame distinction, which is improved.
Smart Images

Figure CN119251041A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of display technology, and in particular to an image processing method, electronic device, storage medium and program product based on Floyd algorithm. Background Art
[0002] With the rapid progress of the fifth generation of mobile communication technology (5G) and artificial intelligence technology, the wearable display industry with virtual reality (VR) and augmented reality (AR) as the core has shown a booming development momentum. Driven by this wave, organic light-emitting diode (OLED) technology is gradually penetrating and expanding into fields such as AR and VR. However, as OLED technology develops towards higher resolution, the public's expectations for image display quality are also constantly increasing. In the current OLED microdisplay technology, most of them are operated in a digital drive mode. Compared with analog drive, digital drive has many advantages such as higher precision, more stable display quality and faster switching speed.
[0003] The Floyd-Steinberg error diffusion algorithm is a classic image processing technology, which is mainly used for image binarization and modulated grayscale image display. Its core idea is to achieve a smooth grayscale transition by diffusing the pixel error to the surrounding unprocessed pixels. The application of the Floyd-Steinberg error diffusion algorithm in the field of OLED display improves the image display effect, display quality and visual experience, and has a positive role in promoting the development and application of OLED technology. However, the existing Floyd-Steinberg error diffusion algorithm usually needs to store the grayscale values of two rows of pixels in the image during image processing, which requires a large storage space. Summary of the invention
[0004] In order to solve the problems existing in the prior art, the present application provides an image processing method, electronic device, storage medium and program product based on the Floyd algorithm.
[0005] The present application provides an image processing method based on the Floyd algorithm, comprising the steps of: obtaining an image to be processed and setting a neighborhood range, wherein the image has m rows and n columns of pixels, m≥1, n≥1, and the neighborhood range is used to determine the error range of the grayscale value of each pixel in the image, and the neighborhood range is a positive integer; obtaining the initial grayscale value of the pixel to be processed at the (i, j) position in the image, wherein i and j are positive integers; providing an error list, wherein the error list is provided with n storage spaces for storing the first error value of the pixel; providing a cache area, wherein the cache area is provided with storage space; storing the first error value of the pixel to be processed in the jth storage space in the error list into the cache area, and clearing the jth storage space in the error list, wherein the first error value of the pixel to be processed is the error value diffused to the pixel to be processed by the remaining surrounding pixels except the pixel in the i-th row and the j-1th column; obtaining the second error value of the pixel to be processed, wherein the second error value of the pixel to be processed is the pixel in the i-th row and the j-1th column according to the Floyd-Stein algorithm. The error of the pixel to be processed is diffused by the Floyd-Steinberg error diffusion method; the sum of the first error value and the second error value of the pixel to be processed is stored in the cache area as the accumulated error of the pixel to be processed; the gray value of the pixel to be processed is updated by the accumulated error of the pixel to be processed, and the cache area is cleared; the first error value of the next pixel to be processed in the j+1th storage space in the error list is stored in the cache area; the error between the updated gray value of the pixel to be processed and the initial gray value of the pixel to be processed is diffused to adjacent pixels according to the Floyd-Steinberg error diffusion method, and the adjacent pixels include the next pixel to be processed and the remaining adjacent pixels, and the diffusion includes obtaining the second error value of the next pixel to be processed, and storing the sum of the second error value and the first error value of the next pixel to be processed in the cache area as the accumulated error, and storing the first error values of the remaining adjacent pixels in the storage space corresponding to the remaining adjacent pixels in the error list; repeating the above steps for each pixel in the image until all pixels are processed.
[0006] Optionally, updating the grayscale value of the pixel to be processed by the accumulated error of the pixel to be processed includes the steps of: calculating a first intermediate value of the pixel to be processed, the first intermediate value being the sum of the grayscale value of the pixel to be processed and the accumulated error of the pixel to be processed; obtaining the ratio of the first intermediate value of the pixel to be processed to a neighborhood range as the second intermediate value of the pixel to be processed; rounding the second intermediate value of the pixel to be processed as the third intermediate value of the pixel to be processed; and taking the product of the third intermediate value of the pixel to be processed and the neighborhood range as the updated grayscale value of the pixel to be processed.
[0007] Optionally, rounding the second intermediate value of the pixel to be processed as the third intermediate value of the pixel to be processed includes: rounding down the second intermediate value of the pixel to be processed as the third intermediate value of the pixel to be processed, or rounding up the second intermediate value of the pixel to be processed as the third intermediate value of the pixel to be processed.
[0008] Optionally, the images are continuous images within a period of time.
[0009] Optionally, the image processing method based on the Floyd algorithm also includes the steps of: dividing the continuous image into odd and even frames according to time order; wherein, for odd-numbered frame images in the continuous image, the second intermediate value of the pixel to be processed is rounded down as the third intermediate value of the pixel to be processed; and for even-numbered frame images in the continuous image, the second intermediate value of the pixel to be processed is rounded up as the third intermediate value of the pixel to be processed.
[0010] Optionally, the method of diffusing the error between the updated grayscale value of the pixel to be processed and the initial grayscale value of the pixel to be processed to adjacent pixels according to the Floyd-Steinberg error diffusion method includes the steps of: allocating the error between the updated grayscale value of the pixel to be processed and the initial grayscale value of the pixel to be processed to adjacent pixels according to specific weights; wherein the sum of the weights allocated to each adjacent pixel is 1.
[0011] The present application also provides an electronic device, comprising: one or more processors; a memory for storing executable instructions; wherein the one or more processors are configured to call the executable instructions stored in the memory to execute the above-mentioned image processing method based on the Floyd algorithm.
[0012] The present application also provides a computer-readable storage medium on which computer program instructions are stored. When the computer program instructions are executed by a processor, the above-mentioned image processing method based on the Floyd algorithm is implemented.
[0013] The present application also provides a computer program product, including a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code, characterized in that when the computer-readable code runs in an electronic device, a processor in the electronic device executes the above-mentioned image processing method based on the Floyd algorithm.
[0014] Compared with the prior art, the technical solution of the present application has the following beneficial effects:
[0015] The present application provides an image processing method based on the Floyd algorithm. By designing an error list and a cache area, n+1 storage spaces are used to store the intermediate values of the accumulated errors in the image processing process (n is the number of image columns), that is, n+1 storage spaces are used to implement the storage requirements of the Floyd-Steinberg algorithm. The cache update is used to downgrade the algorithm that originally required multiple rows of storage or even entire frame storage to only n+1 storage spaces, thereby greatly reducing the storage space required for applying the error diffusion algorithm.
[0016] Furthermore, the present application processes different frames of images differently by distinguishing between odd and even frames of the image. In odd frames, pixels are rounded down for error diffusion; in even frames, pixels are rounded up for error diffusion; this makes the error diffusion algorithm closer to the actual image display effect after averaging in the time dimension, thereby improving the image display quality. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0018] Figure 1 This is a flowchart of an image processing method based on the Floyd algorithm according to an embodiment of the present application;
[0019] Figure 2 A schematic diagram of the process of an image processing method based on the Floyd algorithm according to an embodiment of the present application;
[0020] Figure 3 is the error diffusion ratio of the pixel to be processed in one embodiment of the present application;
[0021] Figure 4 It is a diffusion path of the error generated by the pixel to be processed in an embodiment of the present application. DETAILED DESCRIPTION
[0022] The preferred embodiments of the present application will be described in more detail below. Although the preferred embodiments of the present application are described below, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments described herein.
[0023] In the present application, unless otherwise specified, the directional words used, such as "upper and lower", generally refer to the upper and lower parts of the device in normal use, and "inside and outside" refer to the outline of the device. In addition, the terms "first, second, third" are used for descriptive purposes only and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, features defined as "first, second, third" may explicitly or implicitly include one or more of the features. In the description of the present application, "multiple" means two or more, unless otherwise clearly and specifically defined. Since the accompanying drawings are descriptions of the same device, the same reference numerals in the drawings represent the same components.
[0024] As described in the background technology, the existing Floyd-Steinberg error diffusion algorithm usually needs to store the grayscale values of two rows or even a whole frame of pixels in the image during image processing, which requires a large storage space. Therefore, the present application provides an image processing method, electronic device, storage medium and program product based on the Floyd algorithm, which uses cache updates to downgrade the algorithm that originally requires multiple rows of storage or even a whole frame of storage to only n+1 storage spaces (n represents the number of pixels in a row), greatly reducing the storage space required for applying the error diffusion algorithm.
[0025] The present application provides an image processing method based on the Floyd algorithm, comprising the steps of: obtaining an image to be processed and setting a neighborhood range, wherein the image has m rows and n columns of pixels, m≥1, n≥1, and the neighborhood range is used to determine the error range of the grayscale value of each pixel in the image, and the neighborhood range is a positive integer; obtaining the initial grayscale value of the pixel to be processed at the (i, j) position in the image, wherein i and j are positive integers; providing an error list, wherein the error list is provided with n storage spaces for storing the first error value of the pixel; providing a cache area, wherein the cache area is provided with storage space; storing the first error value of the pixel to be processed in the jth storage space in the error list into the cache area, and clearing the jth storage space in the error list, wherein the first error value of the pixel to be processed is the error value diffused to the pixel to be processed by the remaining surrounding pixels except the pixel in the i-th row and the j-1th column; obtaining the second error value of the pixel to be processed, wherein the second error value of the pixel to be processed is the pixel in the i-th row and the j-1th column according to the Floyd-Stein algorithm. The error of the pixel to be processed is diffused by the Floyd-Steinberg error diffusion method; the sum of the first error value and the second error value of the pixel to be processed is stored in the cache area as the accumulated error of the pixel to be processed; the gray value of the pixel to be processed is updated by the accumulated error of the pixel to be processed, and the cache area is cleared; the first error value of the next pixel to be processed in the j+1th storage space in the error list is stored in the cache area; the error between the updated gray value of the pixel to be processed and the initial gray value of the pixel to be processed is diffused to adjacent pixels according to the Floyd-Steinberg error diffusion method, and the adjacent pixels include the next pixel to be processed and the remaining adjacent pixels, and the diffusion includes obtaining the second error value of the next pixel to be processed, and storing the sum of the second error value and the first error value of the next pixel to be processed in the cache area as the accumulated error, and storing the first error values of the remaining adjacent pixels in the storage space corresponding to the remaining adjacent pixels in the error list; repeating the above steps for each pixel in the image until all pixels are processed.
[0026] In order to provide a further understanding of the purpose, structure, features and functions of the present application, specific examples of the present application are further described in detail below in conjunction with the accompanying drawings.
[0027] Figure 1 FIG. 1 is a flow chart showing an image processing method based on the Floyd algorithm according to an embodiment of the present application. Figure 1 , this embodiment provides an image processing method based on the Floyd algorithm, comprising the steps of:
[0028] S1: Get the image to be processed and set the neighborhood range.
[0029] In an embodiment of the present application, the image has m rows and n columns of pixels, m≥1, n≥1, and the neighborhood range is used to determine the error range of the grayscale value of each pixel in the image, and the neighborhood range is a positive integer. For example, in a specific embodiment, the neighborhood range is set to 3, and the error range of the grayscale value of each pixel is ±3 of the original grayscale value of the pixel.
[0030] In the embodiment of the present application, an 8-bit grayscale image is obtained, and the neighborhood range can be set to 2. The neighborhood range is used to calculate the range of error values of the pixel to be processed that diffuses to the surrounding adjacent pixels.
[0031] S2: Obtain the grayscale value of the pixel to be processed at position (i, j) in the image.
[0032] Wherein, i and j are positive integers. Specifically, 1≤i≤m, 1≤j≤n.
[0033] S3: providing an error list, wherein the error list is provided with n storage spaces for storing first error values of pixels.
[0034] In the embodiments of the present application, Figure 2 As shown, an error list Error List is provided, and the error list is provided with storage spaces having the same number as the number of image columns, and the n storage spaces of the error list correspond one-to-one to the n pixels in the row where the to-be-processed pixels are located.
[0035] In an embodiment of the present application, before the error of the last pixel that has been processed is diffused to the pixel to be processed, the error list is used as a container to temporarily store the error generated by the surrounding adjacent pixels and passed to the pixel to be processed, that is, the first error value of the pixel to be processed. For the pixel to be processed at the (i, j) position, before the error generated by the pixel at the (i, j-1) position is passed to the pixel to be processed, the jth storage space in the error list is used to store the error value generated by the remaining adjacent pixels around the pixel to be processed and passed to the pixel to be processed, and the error value generated by the remaining adjacent pixels around the pixel to be processed and passed to the pixel to be processed is the first error value of the pixel to be processed. After the error of the surrounding adjacent pixels is diffused to the pixel to be processed, the jth storage space in the error list is also used to temporarily store the error value generated by the pixel to be processed and passed to the pixel at the (i+1, j) position, that is, the first error value of the pixel at the (i+1, j) position. When the image processing reaches the (i+1, j) position of the i+1th row, the first error value in the jth storage space in the error list is used to update the gray value of the pixel at the (i+1, j) position.
[0036] S4: Providing a cache area, wherein the cache area is provided with a storage space.
[0037] exist Figure 2In the illustrated embodiment, a cache area Cache is provided for temporarily storing the first error value of the pixel to be processed in the corresponding storage space in the error list during the image processing process, and temporarily storing the sum of the first error value and the second error value of the pixel to be processed, wherein the second error value includes the pixel value diffused from the previous pixel that has been processed to the pixel to be processed.
[0038] S5: storing the first error value of the pixel to be processed in the j-th storage space in the error list into a cache area, and clearing the j-th storage space in the error list.
[0039] In an embodiment of the present application, the first error value of the pixel to be processed is an error value diffused to the pixel to be processed from surrounding pixels except the pixel in the i-th row and the j-1-th column.
[0040] S6: Obtain a second error value of the pixel to be processed.
[0041] In an embodiment of the present application, the second error value of the pixel to be processed is the error diffused to the pixel to be processed by the pixel in the i-th row and j-1-th column according to the Floyd-Steinberg error diffusion method.
[0042] S7: storing the sum of the first error value and the second error value of the pixel to be processed in the buffer area as the accumulated error of the pixel to be processed.
[0043] S8: updating the grayscale value of the pixel to be processed according to the accumulated error of the pixel to be processed, and clearing the buffer area.
[0044] Specifically, the method of updating the grayscale value of the pixel to be processed by the accumulated error of the pixel to be processed includes the following steps: calculating a first intermediate value of the pixel to be processed, wherein the first intermediate value is the sum of the grayscale value of the pixel to be processed and the accumulated error; obtaining a ratio of the first intermediate value of the pixel to be processed to a neighborhood range as a second intermediate value of the pixel to be processed; rounding the second intermediate value of the pixel to be processed as a third intermediate value of the pixel to be processed; and taking the product of the third intermediate value of the pixel to be processed and the neighborhood range as the updated grayscale value of the pixel to be processed.
[0045] Among them, rounding the second intermediate value of the pixel to be processed as the third intermediate value of the pixel to be processed includes: rounding down the second intermediate value of the pixel to be processed as the third intermediate value of the pixel to be processed, or rounding up the second intermediate value of the pixel to be processed as the third intermediate value of the pixel to be processed.
[0046] In a specific embodiment, assuming that the neighborhood range a is 2, the gray value I(i, j) of the pixel to be processed is 127, and the cumulative error error of the gray values of the surrounding pixels assigned to the pixel to be processed is 2, then the first intermediate value x, the second intermediate value y, the third intermediate value z of the pixel to be processed and the updated gray value t of the pixel to be processed are respectively:
[0047] x=I(i,j)+error=127+2=129;
[0048] y=x / 2a=129 / 4=32.25;
[0049] The second intermediate value 32.25 of the pixel to be processed is rounded down to obtain the third intermediate value z of the pixel to be processed, that is, z=32. The calculation formula of the updated gray value t of the pixel to be processed is:
[0050] t=z*2a=32*4=128;
[0051] Then the updated grayscale value of the pixel to be processed is 128.
[0052] In another embodiment, the third intermediate value z' of the pixel to be processed may also be obtained by rounding up, that is, the third intermediate value z' of the pixel to be processed is 33, and the updated gray value t' of the pixel to be processed is:
[0053] t'=z'*2a=33*4=132;
[0054] By rounding up, the updated grayscale value of the pixel to be processed is 132.
[0055] S9: storing the first error value of the next pixel to be processed in the j+1th storage space in the error list into the cache area.
[0056] S10: Diffusion of the error between the updated grayscale value of the pixel to be processed and the initial grayscale value of the pixel to be processed to adjacent pixels according to the Floyd-Steinberg error diffusion method.
[0057] Specifically, the adjacent pixels include a next pixel to be processed and the remaining adjacent pixels, the next pixel to be processed is a pixel in the i-th row and the j+1-th column, the diffusion includes obtaining a second error value of the next pixel to be processed, storing the sum of the second error value and the first error value of the next pixel to be processed as a cumulative error in the cache area, and storing the first error values of the remaining adjacent pixels in the storage space corresponding to the remaining adjacent pixels in the error list.
[0058] In an embodiment of the present application, the method of diffusing the error between the updated grayscale value of the pixel to be processed and the initial grayscale value of the pixel to be processed to the adjacent pixels according to the Floyd-Steinberg error diffusion method includes the steps of: allocating the error between the updated grayscale value of the pixel to be processed and the initial grayscale value of the pixel to be processed to the adjacent pixels according to specific weights; wherein the sum of the weights allocated to each adjacent pixel is 1.
[0059] For example, in a specific embodiment, for the pixel to be processed at position (i, j), it is set to distribute the error of the updated pixel to be processed to several surrounding pixels. One error transfer ratio is, for example, Figure 3 As shown, it is the error generated by the pixel to be processed, where Passed to the pixel immediately to the right of the pixel to be processed, Passed to the pixel directly below the pixel to be processed, The pixel to the lower right of the pixel to be processed is passed to Passed to the pixel below and to the left of the pixel to be processed.
[0060] In some other embodiments, the error between the updated pixel to be processed and the initial grayscale value of the pixel to be processed may be distributed to four surrounding pixels adjacent to the pixel to be processed in the horizontal and vertical directions, wherein the error distributed to each surrounding pixel is a factor of the error of the pixel to be processed.
[0061] In different embodiments, the neighboring pixels to which the error of the pixel to be processed is allocated and the weight ratio allocated to each neighboring pixel can be set according to actual needs, and the present application does not limit this.
[0062] S11: Repeat the above steps for each pixel in the image until all pixels are processed.
[0063] The following is a detailed description of the image processing method based on the Floyd algorithm of the present application through a specific embodiment. Figure 2-4 For a frame of image to be processed, it is assumed that the pixel to be processed currently is the pixel at position (i, j+1), and its gray value is I(i, j+1). A row of error list Error List is provided, and the error list has n storage spaces. The first error value of the pixel to be processed is stored in the storage space E(j+1) in the error list. The first error value of the pixel to be processed is the error value assigned to the pixel to be processed by the surrounding adjacent pixels, including The error of I(i-1, j), The error of I(i-1, j+1) and At the same time, a cache area Cache is provided, and the Cache includes a storage space.
[0064] When processing the pixel to be processed at position (i, j+1), firstly, the first error value of the pixel to be processed stored in E(j+1) is stored in the Cache, and E(j+1) is cleared. Next, the error value assigned to the pixel to be processed by the pixel at position (i, j), i.e., the second error value of the pixel to be processed, is obtained, and the sum of the error value and the first error value of the pixel to be processed is stored in the Cache, i.e., the accumulated error of the pixel to be processed is stored in the Cache. Afterwards, the gray value of the pixel to be processed is updated by the accumulated error stored in the Cache, and the Cache is cleared.
[0065] Next, the error value Error(i, j+1) diffused from the pixel to be processed to the surrounding pixels is calculated based on the updated grayscale value of the pixel to be processed and the initial grayscale value of the pixel to be processed. Specifically, for the next pixel at the position (i, j+2), the first error value of the next pixel stored in E(j+2) is first stored in the Cache, and then the error value diffused from the updated pixel j+1 in the i-th row to the pixel j+2 is stored in the Cache; at the same time, the error diffused from the pixel j+1 in the i-th row to the pixel j+1 in the i+1-th row, the pixel j+1 in the i+1-th row, and the pixel j+2 in the i+1-th row is stored in the storage spaces E(j), E(j+1), and E(j+2) in the Error List according to the set ratio. At this time, the accumulated error of the pixel at the position (i, j+2) is stored in the Cache, and then the grayscale value of the pixel at the position (i, j+2) is updated according to the accumulated error. Each pixel in the image is updated in sequence according to the above steps, and the error is diffused to the surrounding adjacent pixels, so as to obtain a processed image.
[0066] The present application provides an image processing method based on the Floyd algorithm, which cleverly uses cache updates to downgrade the algorithm that originally requires multiple lines of storage or even entire frame storage to only n+1 storage spaces (n represents the number of pixels in a row), greatly reducing the storage space required for applying the error diffusion algorithm.
[0067] In some embodiments, the image is a continuous image within a period of time, and the image processing method based on the Floyd algorithm also includes: dividing the continuous image into odd and even frames according to time order; wherein, for the odd-numbered frame images in the continuous image, the second intermediate value of the pixel to be processed is rounded down as the third intermediate value of the pixel to be processed; for the even-numbered frame images in the continuous image, the second intermediate value of the pixel to be processed is rounded up as the third intermediate value of the pixel to be processed.
[0068] The present application provides an image processing method based on the Floyd algorithm, which further distinguishes in the time dimension and processes odd and even frames separately, thereby reducing the visual distortion caused by error diffusion under the effect of time averaging, thereby improving the image display effect.
[0069] The present application also provides an electronic device, comprising: one or more processors; a memory for storing executable instructions; wherein the one or more processors are configured to call the executable instructions stored in the memory to execute the image processing method based on the Floyd algorithm.
[0070] The present application also provides a computer-readable storage medium having computer program instructions stored thereon, and the computer program instructions, when executed by a processor, implement the image processing method based on the Floyd algorithm.
[0071] The present application also provides a computer program product, including a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in an electronic device, a processor in the electronic device executes the image processing method based on the Floyd algorithm.
[0072] The image processing method, electronic device, storage medium and program product based on the Floyd algorithm of the present application can use n+1 storage spaces to store the intermediate values of the accumulated errors in the image processing process by designing an error list and a cache area, that is, use n+1 storage spaces to implement the storage requirements of the Floyd-Steinberg algorithm, and use cache updates to downgrade the algorithm that originally required multiple lines of storage or even entire frame storage to only n+1 storage spaces, thereby greatly reducing the storage space required for applying the error diffusion algorithm.
[0073] It is to be understood that the structures illustrated in the embodiments of the present application do not constitute specific limitations on the image processing method, electronic device, storage medium, and program product based on the Floyd algorithm. In other embodiments of the present application, more or fewer components than shown in the figure may be included, or some components may be combined, or some components may be split, or different component arrangements may be provided. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0074] The various embodiments of the mechanism disclosed in the present application can be implemented in hardware, software, firmware or a combination of these implementation methods. The embodiments of the present application can be implemented as a computer program or program code executed on a programmable system, which includes at least one processor, a storage system (including volatile and non-volatile memory and / or storage elements), at least one input device and at least one output device.
[0075] Program code can be applied to input instructions to perform the functions described in this application and generate output information. The output information can be applied to one or more output devices in a known manner.
[0076] Program code can be implemented with high-level programming language or target area-oriented programming language to communicate with the processing system. When necessary, program code can also be implemented with assembly language or machine language. In fact, the mechanism described in this application is not limited to the scope of any specific programming language. In either case, the language can be a compiled language or an interpreted language.
[0077] In some cases, the disclosed embodiments may be implemented in hardware, firmware, software, or any combination thereof. The disclosed embodiments may also be implemented as instructions carried or stored on one or more temporary or non-temporary machine-readable (e.g., computer-readable) storage media, which may be read and executed by one or more processors. For example, instructions may be distributed over a network or through other computer-readable media. Therefore, machine-readable media may include any mechanism for storing or transmitting information in a machine (e.g., computer) readable form, including, but not limited to, floppy disks, optical disks, optical disks, read-only memories (CD-ROMs), magneto-optical disks, read-only memories (ROMs), random access memories (RAMs), erasable programmable read-only memories (EPROMs), electrically erasable programmable read-only memories (EEPROMs), magnetic or optical cards, flash memory, or a tangible machine-readable memory for transmitting information (e.g., carrier waves, infrared signals, digital signals, etc.) using the Internet in electrical, optical, acoustic, or other forms of propagation signals. Therefore, machine-readable media include any type of machine-readable media suitable for storing or transmitting electronic instructions or information in a machine (e.g., computer) readable form.
[0078] In the accompanying drawings, some structural or method features may be shown in a specific arrangement and / or order. However, it should be understood that such a specific arrangement and / or order may not be required. Instead, in some embodiments, these features may be arranged in a manner and / or order different from that shown in the illustrative drawings. In addition, the inclusion of structural or method features in a particular figure does not mean that such features are required in all embodiments, and in some embodiments, these features may not be included or may be combined with other features.
[0079] It should be noted that the units / modules mentioned in the various device embodiments of the present application are all logical units / modules. Physically, a logical unit / module can be a physical unit / module, or a part of a physical unit / module, or can be implemented as a combination of multiple physical units / modules. The physical implementation method of these logical units / modules themselves is not the most important. The combination of functions implemented by these logical units / modules is the key to solving the technical problems proposed by the present application. In addition, in order to highlight the innovative part of the present application, the above-mentioned device embodiments of the present application do not introduce units / modules that are not closely related to solving the technical problems proposed by the present application, which does not mean that there are no other units / modules in the above-mentioned device embodiments.
[0080] The above descriptions are merely embodiments of the present application and are not intended to limit the patent scope of the present application. Any equivalent structural or equivalent process transformations made using the contents of the specification and drawings of the present application, such as the mutual combination of technical features between the embodiments, or direct or indirect application in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. An image processing method based on Floyd algorithm, characterized in that: Includes steps: Acquire an image to be processed and set a neighborhood range, wherein the image has m rows and n columns of pixels, m≥1, n≥1, and the neighborhood range is used to determine the error range of the gray value of each pixel in the image, and the neighborhood range is a positive integer; Obtaining the initial grayscale value of the pixel to be processed at position (i, j) in the image, where i and j are positive integers; Providing an error list, wherein the error list is provided with n storage spaces for storing first error values of pixels; Providing a cache area, wherein the cache area is provided with a storage space; The first error value of the pixel to be processed in the j-th storage space in the error list is stored in the cache area, and the j-th storage space in the error list is cleared, wherein the first error value of the pixel to be processed is the error value diffused to the pixel to be processed by the surrounding pixels except the pixel in the i-th row and the j-1-th column; Obtaining a second error value of the pixel to be processed, where the second error value of the pixel to be processed is an error diffused from the pixel in the i-th row and the j-1-th column to the pixel to be processed according to the Floyd-Steinberg error diffusion method; storing the sum of the first error value and the second error value of the pixel to be processed in the buffer area as the accumulated error of the pixel to be processed; Updating the grayscale value of the pixel to be processed according to the accumulated error of the pixel to be processed, and clearing the buffer area; storing the first error value of the next pixel to be processed in the j+1th storage space in the error list into the buffer area; Diffusion of the error between the updated grayscale value of the pixel to be processed and the initial grayscale value of the pixel to be processed to adjacent pixels according to the Floyd-Steinberg error diffusion method, wherein the adjacent pixels include the next pixel to be processed and the remaining adjacent pixels, wherein the diffusion includes obtaining a second error value of the next pixel to be processed, storing the sum of the second error value and the first error value of the next pixel to be processed as the accumulated error in the cache area, and storing the first error values of the remaining adjacent pixels in the storage space corresponding to the remaining adjacent pixels in the error list; The above steps are repeated for each pixel in the image until all pixels have been processed.
2. The image processing method based on the Floyd algorithm according to claim 1, characterized in that: The method of updating the grayscale value of the pixel to be processed by the accumulated error of the pixel to be processed comprises the steps of: calculating a first intermediate value of the pixel to be processed, wherein the first intermediate value is the sum of the grayscale value of the pixel to be processed and the accumulated error of the pixel to be processed; Obtaining a ratio of a first intermediate value of the pixel to be processed to a neighborhood range as a second intermediate value of the pixel to be processed; Rounding the second intermediate value of the pixel to be processed as the third intermediate value of the pixel to be processed; The product of the third intermediate value of the pixel to be processed and the neighborhood range is used as the updated grayscale value of the pixel to be processed.
3. The image processing method based on Floyd algorithm as claimed in claim 2, characterized in that: The step of rounding the second intermediate value of the pixel to be processed as the third intermediate value of the pixel to be processed includes: rounding down the second intermediate value of the pixel to be processed as the third intermediate value of the pixel to be processed, or rounding up the second intermediate value of the pixel to be processed as the third intermediate value of the pixel to be processed.
4. The image processing method based on Floyd algorithm as claimed in claim 2, characterized in that: The images are continuous images within a period of time.
5. The image processing method based on Floyd algorithm according to claim 4, characterized in that: Also includes the steps: The continuous images are divided into odd and even frames according to the time sequence; wherein, For odd-numbered frame images in the continuous images, the second intermediate value of the pixel to be processed is rounded down to an integer as the third intermediate value of the pixel to be processed; For even-numbered frame images in the continuous images, the second intermediate value of the pixel to be processed is rounded up to an integer as the third intermediate value of the pixel to be processed.
6. The image processing method based on Floyd algorithm according to claim 1, characterized in that: The method of diffusing the error between the updated grayscale value of the pixel to be processed and the initial grayscale value of the pixel to be processed to the adjacent pixels according to the Floyd-Steinberg error diffusion method includes the following steps: allocating the error between the updated grayscale value of the pixel to be processed and the initial grayscale value of the pixel to be processed to the adjacent pixels according to specific weights; wherein the sum of the weights allocated to each adjacent pixel is 1.
7. An electronic device, characterized in that: include: one or more processors; a memory for storing executable instructions; The one or more processors are configured to call the executable instructions stored in the memory to execute the method according to any one of claims 1 to 6.
8. A computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the computer program instructions are executed by a processor, the method according to any one of claims 1 to 6 is implemented.
9. A computer program product comprising computer readable code, or a non-volatile computer readable storage medium carrying computer readable code, characterized in that: When the computer readable code is executed in an electronic device, a processor in the electronic device executes the method according to any one of claims 1 to 6.
Citation Information
Cited By
Image display method and device based on LED and nonvolatile storage medium
CN120375759A