Fast expansion method based on run length coding
Through the fast expansion method based on run encoding, the problems of large storage space, computing complexity and memory consumption in traditional binary image expansion operations are solved, and efficient image processing and data transmission are realized, suitable for large-scale and real-time image processing scenarios .
Patent Information
- Application Number
- CN202411410017.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-10
- Publication Date
- 2025-01-10
AI Technical Summary
Traditional binary image expansion operations have problems such as large storage space requirements, high computing complexity, large memory consumption and poor real-time performance, especially in large-scale image processing and real-time applications, which are difficult to meet efficiency requirements.
Using a fast expansion method based on run coding, it can be optimized through pre-processing and special situations, including run coding, special processing of rectangular areas, horizontal and vertical expansion operations, iteration calculation and cropping operations, reducing unnecessary computing overhead and memory consumption. Improve algorithm execution efficiency and data transmission efficiency.
It significantly reduces storage space requirements, reduces computing complexity and memory consumption, improves the speed and efficiency of image processing, is suitable for large-scale image and real-time application scenarios, and improves data transmission efficiency and algorithm execution speed.
Smart Images

Figure CN119295321A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of image processing, in particular to a fast expansion method based on run-length coding. Background Art
[0002] In image processing, a binary image is an image that contains only black and white colors, where black usually represents the background and white represents the target object. The dilation operation is a morphological processing method whose main purpose is to expand the target object in the image to make it more connected or larger. The dilation operation is often used in the fields of object detection, edge detection, image segmentation, etc., and is one of the basic steps of many image processing algorithms.
[0003] In traditional binary image processing, the dilation operation is usually implemented by convolving a binary image with a structural element (also called a convolution kernel). However, for large-scale images or real-time processing applications, traditional methods may have challenges in storage and computational efficiency. Since the size of the structural element may be large, performing the dilation operation on the entire image may result in unnecessary computational overhead and memory consumption.
[0004] In response to these challenges, run-length encoding technology has become an effective solution. Run-length encoding significantly reduces the data storage space required by compressing areas of continuous identical pixel values into a run-length sequence. This encoding method not only saves storage space, but also improves the efficiency of data transmission. In image processing, run-length encoding is often used to compress the representation of binary images, thereby reducing transmission and storage costs.
[0005] Therefore, combining run-length coding technology with binary image dilation operation can effectively solve the storage and computational efficiency problems in traditional methods. By optimizing the algorithm execution process and data representation, the dilation operation is made more efficient and reliable in large-scale image processing and real-time applications, providing important technical support for the further development of the image processing field.
[0006] However, there are some shortcomings and problems in the existing binary image dilation operation technology:
[0007] 1. Large storage space requirements: Traditional binary image expansion operations usually require the storage of a large amount of intermediate results and temporary data, especially when processing large-scale images, which will take up a lot of storage space.
[0008] 2. High computational complexity: Traditional dilation operations usually use structural elements and binary images for convolution operations, which involves the operation of a large number of pixels and has high computational complexity, especially when the structural element is large or the image resolution is high.
[0009] 3. Large memory consumption: Since a large number of intermediate results and temporary data need to be stored, the expansion operation may occupy a large amount of memory resources, especially when processing large-size images, which may cause insufficient memory or memory allocation failure.
[0010] 4. Poor real-time performance: Due to the high computational complexity and large memory consumption, traditional expansion operations may not meet the needs of real-time processing in scenarios with high real-time requirements, resulting in high latency.
[0011] These shortcomings and problems are mainly due to the limitations of traditional dilation operation methods in data representation, calculation process and memory management. The structural element convolution operation method requires calculation for each pixel, resulting in high computational complexity and large storage space requirements. At the same time, the traditional method may not be efficient enough in the storage management of intermediate results and temporary data, resulting in high memory consumption and poor real-time performance. Summary of the invention
[0012] The technical problem to be solved by the present invention is: to provide a fast expansion method based on run-length coding, and to propose an efficient solution for binary image expansion operations through run-length coding technology; to optimize storage space utilization, data transmission efficiency and algorithm execution efficiency, and to reduce unnecessary computing overhead through preprocessing and special case optimization, thereby improving the speed and efficiency of image processing and bringing important technical progress to the field of image processing.
[0013] The technical solution adopted by the present invention to solve the technical problem is: a rapid expansion method based on run-length coding, comprising the following steps:
[0014] S1, taking a binary image as an input area and performing run-length encoding to obtain the run-length; and inputting the dilation parameters height and width;
[0015] S2, determine whether the expansion parameter height and width are less than or equal to 0; if so, return an empty area; if not, proceed to the next step;
[0016] S3, determine whether the input area is a rectangle, if so, perform special expansion processing; if not, proceed to the next step;
[0017] S4, calculating the maximum possible number of allocated runs, the maximum number of runs being the number of runs in the input region multiplied by the input expansion height;
[0018] S5. Calculate the number of iterations required: calculate the logarithm of the height minus 1, and then take the integer part to obtain the number of basic iterations;
[0019] S6, performing horizontal expansion;
[0020] S7, performing vertical expansion;
[0021] S8. Merge all the run-length codes after the moves, that is, merge the run-length codes obtained after each move with the run-length codes of the previous iteration.
[0022] Furthermore, in step S3 described in the present invention, if the input area is a rectangle, the special expansion processing method is: move the starting row and starting column of the rectangular area to the upper left corner until they intersect with the cropping boundary of the upper left corner; move the ending row and ending column of the rectangular area to the lower right corner until they intersect with the cropping boundary of the lower right corner; then perform the expansion operation within the cropping boundary according to the adjusted size of the rectangular area.
[0023] Furthermore, in step S4 described in the present invention, if the expansion height is 1 pixel, a one-dimensional horizontal expansion operation is performed; the processing steps are as follows: first, the row and column positions of the output run are calculated based on the row offset and column offset of the input run; then, the input run is traversed, and adjacent runs are merged or new output runs are generated based on the changes in rows and columns; finally, the number of output runs is determined, and the terminal column of the output run is updated.
[0024] Furthermore, in step S5 of the present invention, the basic method for calculating the number of iterations is: num=log2(height-1); wherein height is the expansion height.
[0025] Furthermore, in step S6 described in the present invention, the horizontal expansion method is: first, reset the output area, and calculate the new row, start column and end column positions based on the input row and column offsets, then traverse the input strokes, merge or generate new output strokes; finally, set the end column of the output stroke, and calculate the number of output strokes to complete the horizontal expansion operation.
[0026] Furthermore, in step S7 of the present invention, the method of vertical expansion is: initialize an empty area to store the result after vertical expansion; for each input run-length code, perform the following operations: a. calculate the row and column of the run-length code and the termination column; b. move the run-length code as a whole downward to a specified number of times; c. add the moved run-length code to the result area; and return the result area as the output of the vertical expansion.
[0027] Furthermore, in step S8 of the present invention, during the merging process, if two runs have overlapping parts, they are merged into a larger run; and the merged run codes are sorted.
[0028] Furthermore, the present invention further comprises the steps of:
[0029] S9. At the end of the execution, if cropping is required, the cropping operation is performed.
[0030] Furthermore, the clipping process described in the present invention includes: determining the clipping range; clipping the final expansion result to ensure that it only contains runs within the specified row and column range; if any run crosses the clipping boundary, the run that crosses the clipping boundary will be truncated; the result after clipping is the final expansion result.
[0031] The beneficial effect of the present invention is that it solves the defects existing in the background technology, and by introducing the run-length encoding technology, the area of continuous identical pixel values is compressed into a run-length sequence, thereby greatly reducing the storage space requirement of the binary image and effectively saving storage resources; at the same time, the algorithm execution process is optimized, and through pre-processing and optimization processing of special cases, such as special processing of rectangular areas, unnecessary computing overhead is avoided, and the execution efficiency and speed of the algorithm are improved; in addition, the image data after run-length encoding requires a smaller bandwidth during transmission, which improves the efficiency of data transmission and speeds up image transmission, and is particularly suitable for network transmission and real-time processing scenarios. In summary, the present invention not only saves storage space, improves data transmission efficiency and algorithm execution speed, but also brings higher efficiency and performance to the field of image processing, provides reliable technical support for large-scale image processing and real-time application scenarios, and promotes the technical development and application prospects of related fields. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 It is a schematic flow chart of the method of the present invention. DETAILED DESCRIPTION
[0033] The present invention will now be described in further detail in conjunction with the accompanying drawings and preferred embodiments. These drawings are simplified schematic diagrams, which only illustrate the basic structure of the present invention in a schematic manner, and therefore only show the components related to the present invention.
[0034] like Figure 1 A fast dilation method based on run-length coding is shown, which relates to a binary image dilation operation in the field of image processing; the specific method steps are as follows:
[0035] 1) Assume that the input area is an m×n binary image, represented by a matrix I, where the pixel value of the target object is 1 and the value of the background pixel is 0. Run-length encoding is performed on I to obtain a series of runs R. Where: R = {(cb1, ce1, l1), (cb2, ce2, l2), ..., (cb k ,ce k ,l k )}.
[0036] The i-th run is (cbi ,ce i ,l i ) indicates that the starting column cb i , end column ce i and line l i composition.
[0037] Through run-length encoding, a binary image can be compressed into a series of runs, thereby reducing storage space and improving the efficiency of data transmission to a certain extent.
[0038] 2) According to the input expansion parameters, that is, the height is expanded by height pixels and the width is expanded by width pixels; check whether the height and width of the structure element are less than or equal to 0, or check whether the input area is empty. If the height or width of the structure element is less than or equal to 0, or the input area is empty, return an empty area.
[0039] 3) Handling special cases (input area is rectangular): Check whether the input area is rectangular. If it is rectangular, perform special dilation to improve efficiency. In the special dilation, adjust the size of the rectangular area according to the clipping parameters to ensure that the dilation operation is performed within the clipping boundary. Finally, allocate memory space for the output area according to the adjusted area size and perform run-length encoding to obtain the dilated output result.
[0040] The specific steps are as follows: Check whether clipping is required, that is, check whether the boundary of the rectangle completely overlaps with the given clipping boundary. If the rectangular area completely overlaps with the clipping boundary, there is no need to perform the dilation operation, directly copy the input area to the output area, and return the result. If the rectangular area does not completely overlap with the clipping boundary, adjust the size of the rectangular area according to the clipping boundary to ensure that the dilation operation is performed within the clipping boundary. If the rectangular area overlaps with the clipping boundary, adjust the size of the rectangular area according to the clipping parameters to ensure that the dilated area is within the clipping range.
[0041] The adjustment process includes: moving the starting row l1 and the starting column c1 of the rectangular area to the upper left corner until they intersect with the clipping boundary. Moving the ending row l2 and the ending column c2 of the rectangular area to the lower right corner until they intersect with the clipping boundary. According to the adjusted size of the rectangular area, performing the expansion operation within the clipping boundary.
[0042] l1=max(row1,l1-((height-1)>>1))
[0043] c1=max(col1,c1-((width-1)>>1))
[0044] l2=min(0,min(row2,l2+(height>>1)))
[0045] c2=min(0,min(col2,c2+(width>>1)))
[0046] In these formulas, l1, c1, l2, c2 represent the starting row, starting column, ending row, and ending column of the rectangular region, respectively. row1, col1, row2, col2 represent the starting row, starting column, ending row, and ending column of the cropping boundary, respectively. height and width represent the height and width of the dilation operation, respectively.
[0047] The special processing of rectangular regions is mainly to improve efficiency and avoid unnecessary dilation of the entire input region. By clipping the boundaries and adjusting the size of the rectangular region, the dilation operation can be performed only on the region of interest, thus saving computing resources and improving algorithm efficiency.
[0048] 4) If it is not a rectangle, first calculate the maximum possible number of allocated runs, which is the number of runs in the input area multiplied by the input run height; this is to pre-allocate enough memory.
[0049] 5) Handling special cases (input dilation height is 1 pixel): If the dilation height is 1 pixel, a one-dimensional horizontal dilation operation is performed. This is a special case because a height of 1 pixel means that dilation only needs to be performed in the horizontal direction. The processing steps are as follows: First, the row and column positions of the output run are calculated based on the row offset and column offset of the input run. Then, the input run is traversed, and adjacent runs are merged or new output runs are generated based on the changes in rows and columns. Finally, the number of output runs is determined, and the terminal column of the output run is updated. This process implements the dilation operation on the run and generates the output run.
[0050] 6) Calculate the number of iterations required, calculate the logarithm of the height minus 1, and then take the integer part to get the basic number of iterations; the calculation method is as follows:
[0051] num=log2(height-1)
[0052] 7) Perform horizontal expansion: First, reset the output area and calculate the new row, start column and end column positions based on the input row and column offsets, then traverse the input runs and merge or generate new output runs. Finally, set the end column of the output runs and calculate the number of output runs to complete the horizontal expansion operation.
[0053] 8) Perform vertical expansion: Initialize an empty area to store the result of vertical expansion. For each input run-length code, perform the following operations: a. Calculate the row and column of the run-length code and the end column. b. Move the run-length code downward by 1 pixel, 2 pixels, 4 pixels, and so on, until it moves the specified number of times. c. Add the moved run-length code to the result area. Return the result area as the output of vertical expansion.
[0054] 9) Merge all the run-length codes after the moves, that is, merge the run-length codes obtained after each move with the run-length codes of the previous iteration. In the merging process, it is necessary to consider the overlap of the runs. If two runs have overlapping parts, they are merged into a larger run. Sort the merged run-length codes to ensure that the runs are arranged in row order.
[0055] 10) At the end of the execution, if cropping is required, the cropping operation is performed. The cropping process includes:
[0056] Determine the range of clipping, usually determined by the given row and column ranges. Clip the final dilation result to ensure that it only contains runs within the specified row and column ranges. If there are runs that cross the clipping boundaries, they need to be truncated to make them within the clipping boundaries. The clipped result is the final dilation result.
[0057] The present invention introduces run-length encoding technology to compress areas of continuous identical pixel values into a run-length sequence, thereby significantly reducing the storage space requirements of binary images. Compared with traditional storage methods, run-length encoding greatly reduces the amount of stored data, thereby solving the problem of large storage space requirements.
[0058] The present invention requires a smaller bandwidth when transmitting the compressed data after run-length coding, thereby improving the data transmission efficiency and accelerating the data transmission speed.
[0059] The present invention optimizes the algorithm execution process and data representation method, performs preprocessing and optimization processing for special situations, such as special processing of rectangular areas, avoiding unnecessary expansion operations on the entire input area, reducing unnecessary computing overhead and memory consumption, reducing computing complexity, and improving the execution efficiency and speed of the algorithm, thereby improving the response speed of the expansion operation in scenarios with high real-time requirements, and solving the problems of poor real-time performance and high computing complexity.
[0060] The present invention calculates in advance the maximum number of runs that may need to be allocated and allocates sufficient memory space in advance, thereby avoiding the overhead of frequent memory allocation during algorithm execution, optimizing the utilization of memory resources, and solving the problem of large memory consumption.
[0061] In summary, this invention solves the shortcomings and problems in the prior art in terms of storage, computing, memory and real-time performance by introducing run-length encoding technology, optimizing the algorithm execution process and data representation method, improves the efficiency and performance of binary image expansion operations, and brings important technological progress to the field of image processing.
[0062] The above description only describes the specific implementation mode of the present invention. Various examples do not limit the essential content of the present invention. After reading the description, ordinary technicians in the relevant technical field can modify or deform the specific implementation modes described above without departing from the essence and scope of the invention.
Claims
1. A rapid expansion method based on run-length coding, characterized in that: The following steps are included: S1, taking a binary image as an input area and performing run-length encoding to obtain the run-length; and inputting the dilation parameters height and width; S2, determine whether the expansion parameter height and width are less than or equal to 0; if so, return an empty area; if not, proceed to the next step; S3, determine whether the input area is a rectangle, if so, perform special expansion processing; if not, proceed to the next step; S4, calculating the maximum possible number of allocated runs, where the maximum number of runs is the number of runs in the input area multiplied by the input expansion height; S5. Calculate the number of iterations required: calculate the logarithm of the height minus 1, and then take the integer part to obtain the number of basic iterations; S6, performing horizontal expansion; S7, performing vertical expansion; S8. Merge all the run-length codes after the moves, that is, merge the run-length codes obtained after each move with the run-length codes of the previous iteration.
2. A rapid expansion method based on run-length coding as claimed in claim 1, characterized in that: In step S3, if the input area is a rectangle, the special expansion processing method is: move the starting row and starting column of the rectangular area to the upper left corner until they intersect with the cropping boundary of the upper left corner; move the ending row and ending column of the rectangular area to the lower right corner until they intersect with the cropping boundary of the lower right corner; then perform the expansion operation within the cropping boundary according to the adjusted size of the rectangular area.
3. A rapid expansion method based on run-length coding as claimed in claim 1, characterized in that: In step S4, if the expansion height is 1 pixel, a one-dimensional horizontal expansion operation is performed; the processing steps are as follows: first, the row and column positions of the output run are calculated based on the row offset and column offset of the input run; then, the input run is traversed, and adjacent runs are merged or new output runs are generated based on the changes in rows and columns; finally, the number of output runs is determined, and the terminal column of the output run is updated.
4. A rapid expansion method based on run-length coding as claimed in claim 1, characterized in that: In the step S5, the basic method for calculating the number of iterations is: num=log2(height-1); wherein height is the expansion height.
5. The rapid expansion method based on run-length coding as claimed in claim 1, characterized in that: In step S6, the horizontal expansion method is as follows: first, reset the output area, and calculate the new row, start column and end column positions based on the input row and column offsets, then traverse the input strokes, merge or generate new output strokes; finally, set the end column of the output strokes, and calculate the number of output strokes to complete the horizontal expansion operation.
6. A rapid expansion method based on run-length coding as claimed in claim 1, characterized in that: In the step S7, the vertical expansion is performed by: initializing an empty area for storing the result of vertical expansion; for each input run-length code, performing the following operations: a. calculating the row and column of the run-length code and the end column; b. moving the run-length code downward as a whole until the specified number of times; c. Add the shifted run-length encoding to the result area; return the result area as the vertically expanded output.
7. A rapid expansion method based on run-length coding as claimed in claim 1, characterized in that: In the step S8, during the merging process, if two runs have overlapping parts, they are merged into a larger run; and the merged run codes are sorted.
8. A rapid expansion method based on run-length coding as claimed in claim 1, characterized in that: Also includes the steps, S9. At the end of the execution, if cropping is required, the cropping operation is performed.
9. A rapid expansion method based on run-length coding as claimed in claim 8, characterized in that: The clipping process includes: determining the clipping range; clipping the final expansion result; Ensures that it contains only runs within the specified row and column range; if any runs cross the boundaries of the clipping, The runs that cross the clipping boundary will be truncated; the result after clipping is the final expansion result.
Citation Information
Cited By
Image expansion method and device, electronic equipment and storage medium
CN120655514A
Image inflation method and device, electronic equipment and storage medium
CN120655514B