A method and apparatus for improving processing speed of image distance transformation
By gradually expanding the search radius and optimizing the search order, the slow processing speed of the image distance transformation algorithm is solved, and parallel computing and efficient image processing on multi-core processors are achieved.
Patent Information
- Application Number
- CN202211550719.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-05
- Publication Date
- 2026-02-06
- Estimated Expiration
- 2042-12-05
AI Technical Summary
Existing image distance transformation algorithms require multiple image traversals, which are computationally complex and difficult to implement in parallel processing, resulting in slow processing speeds, especially with poor performance on certain types of images.
The algorithm finds the nearest zero pixel to a non-zero pixel by gradually expanding the search radius. By setting a two-dimensional coordinate system and a symmetrical pixel set, the search order is optimized, enabling distance calculation in a single image traversal. This algorithm is suitable for parallel computation on multi-core processors.
It significantly improves image processing speed, especially for specific images, and integrates binarization and distance transform without increasing computational load, making it suitable for deployment on GPUs.
Smart Images

Figure CN116757975B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of image detection and high-performance computing, in particular to a method and device for improving the processing speed of image distance transformation. BACKGROUND
[0002] After a pair of images is converted into a binary image according to a threshold value, the pixels in the image can be divided into two categories: background pixels (pixel value is 0) and target pixels (pixel value is 1), and distance transformation refers to the process of transforming the pixel values 0 and 1 of each pixel in the binary image into the distance value from the nearest background pixel. There are generally three types of distance: DIST_L1 (Manhattan distance), DIST_L2 (Euclidean distance), and DIST_C (chessboard distance). The image after distance transformation can better highlight the edge, geometric skeleton and other information of the image, thereby facilitating image morphological processing (such as thinning, thickening, skeleton extraction, etc.), so distance transformation has always been a research hotspot in the field of image processing.
[0003] However, the current algorithm generally uses fixed steps for images, and the processing speed for some special images has not been greatly improved. For example, the existing Manhattan distance transformation generally needs to traverse the image multiple times, such as forward loop, backward loop, or from top to bottom, from bottom to top, from left to right, from right to left, four times of traversing the image, in addition, when calculating the Manhattan distance, the calculation of the next point needs to update the calculation information of the previous point before calculation, making it difficult to parallelize multiple points and implement parallel processing. SUMMARY
[0004] To solve the above problems, the present application provides a method for improving the processing speed of image distance transformation, which can well improve the image processing speed under certain conditions.
[0005] Specifically, the technical scheme of the present application is as follows:
[0006] The present application provides a method for improving the processing speed of image distance transformation, comprising the steps of:
[0007] obtaining a to-be-processed image;
[0008] dividing the pixel points of the to-be-processed image into zero pixel points and non-zero pixel points according to a preset threshold value;
[0009] selecting a non-zero pixel point as a target non-zero pixel point, and searching whether there is a zero pixel point within a preset search radius range centered on the target non-zero pixel point;
[0010] when the zero pixel point is found, taking the zero pixel point as the nearest zero pixel point to the target non-zero pixel point;
[0011] When the zero pixel point is not found, the search radius is enlarged to continue searching until the zero pixel point closest to the target non-zero pixel point is found; wherein the search radius is enlarged by one pixel distance each time;
[0012] After obtaining each non-zero pixel point and its closest zero pixel point, the Manhattan distance between each non-zero pixel point and its closest zero pixel point is determined.
[0013] In some embodiments, the search is centered on the target non-zero pixel point, and whether there is a zero pixel point within a search radius of a predetermined search radius is determined, specifically including:
[0014] A two-dimensional coordinate system is set to determine the coordinate position of the target non-zero pixel point;
[0015] According to the predetermined search radius, the search interval range is determined;
[0016] The pixel points in the search interval range are divided into a plurality of sets of symmetric pixel points; each set of symmetric pixel points contains at least one pair of symmetric pixel points;
[0017] According to the predetermined search order rule, whether the pixel points in each set of symmetric pixel points are zero pixel points is sequentially searched.
[0018] In some embodiments, the pixel points in the search interval range are divided into a plurality of sets of symmetric pixel points, specifically including:
[0019] The ratio of the search radius to the pixel distance is obtained as a reference number;
[0020] According to the reference number, the number of groups for grouping the pixel points in the search interval range is determined; the number of groups is one more than the reference number;
[0021] The coordinate positions of the reference pixel points of each group are sequentially determined;
[0022] The symmetric pixel points of the reference pixel points with respect to the X-axis, the Y-axis, and the origin are obtained to obtain the symmetric pixel point set of the group.
[0023] In some embodiments, whether the pixel points in each set of symmetric pixel points are zero pixel points is sequentially searched according to the predetermined search order rule, specifically including:
[0024] According to the predetermined search order, the search order of the plurality of sets of symmetric pixel points is determined;
[0025] According to the searching order of the plurality of groups of symmetrical pixel point sets, whether a zero pixel point is contained in each group of symmetrical pixel point sets is searched in sequence, and the searching stops once the zero pixel point is found, otherwise the searching continues until all the symmetrical pixel point sets are traversed.
[0026] In some embodiments, the step of dividing the pixel points of the image to be processed into zero pixel points and non-zero pixel points according to the preset threshold value specifically comprises:
[0027] According to the preset threshold value, the image to be processed is binarized to obtain a corresponding binarized image;
[0028] The pixel points in the binarized image are divided into zero pixel points and non-zero pixel points.
[0029] Based on the same technical concept, the application further provides a device for improving the processing speed of image distance transformation,
[0030] In some embodiments, the device comprises:
[0031] An acquisition module is configured to acquire an image to be processed;
[0032] A preprocessing module is configured to divide the pixel points of the image to be processed into zero pixel points and non-zero pixel points according to a preset threshold value;
[0033] A pixel point searching module is configured to select a non-zero pixel point as a target non-zero pixel point, search whether there is a zero pixel point within a preset search radius interval range centered on the target non-zero pixel point, when the zero pixel point is found, take the zero pixel point as the zero pixel point closest to the target non-zero pixel point, when the zero pixel point is not found, continue searching by expanding the search radius until the zero pixel point closest to the target non-zero pixel point is found, and the expansion range of the search radius is one pixel distance each time.
[0034] A distance calculation module is configured to determine the Manhattan distance between each non-zero pixel point and the zero pixel point closest to the non-zero pixel point after each non-zero pixel point and the zero pixel point closest to the non-zero pixel point are acquired.
[0035] In some embodiments, the pixel point searching module specifically comprises:
[0036] A coordinate establishing submodule is configured to set a two-dimensional coordinate system and determine the coordinate position of the target non-zero pixel point.
[0037] An interval determining submodule is configured to determine a searching interval range according to a preset search radius.
[0038] a grouping submodule, configured to divide the pixel points in the search interval range into a plurality of sets of symmetrical pixel points, each set of symmetrical pixel points containing at least one pair of symmetrical pixel points;
[0039] a searching submodule, configured to sequentially search, according to a preset searching sequence rule, whether the pixel points in each set of symmetrical pixel points are zero pixel points.
[0040] In some embodiments, the grouping submodule specifically comprises:
[0041] a group number determination unit, configured to obtain a reference number as a ratio of the search radius and the pixel distance, and determine a group number for grouping the pixel points in the search interval range according to the reference number, the group number being one greater than the reference number;
[0042] a reference determination unit, configured to sequentially determine the coordinate positions of the reference pixel points in each group;
[0043] a symmetrical point acquisition unit, configured to obtain the symmetrical pixel points of the reference pixel points with respect to the X axis, the Y axis and the origin point, respectively, to obtain the set of symmetrical pixel points.
[0044] In some embodiments, the preprocessing module specifically comprises:
[0045] a binarization processing submodule, configured to perform binarization processing on the image to be processed to obtain a corresponding binarized image;
[0046] a pixel distinguishing submodule, configured to divide the pixel points in the binarized image into zero pixel points and non-zero pixel points.
[0047] In some embodiments, the present application further provides an electronic device comprising one or more processors and a memory storing computer instructions, which, when executed by the processor, cause the processor to perform the image distance transformation processing method according to any one of the above embodiments.
[0048] Compared with the prior art, the image distance transformation processing method provided by the present application has at least the following beneficial effects:
[0049] 1、The method for improving the processing speed of image distance transformation provided by the patent adopts the way of gradually expanding the search radius to search for the nearest zero pixel point of the non-zero pixel point one by one, such as searching the interval with a pixel distance as the search radius first, checking whether there is a zero pixel point in the pixel point (adjacent pixel point) with a pixel distance from the non-zero pixel point, if not, expanding the search radius to two pixel distances, checking whether there is a zero pixel point in the pixel point with a distance of two pixel distances from the non-zero pixel point, if there is, stopping the search, if not, continuing to expand the search radius to three, and so on until the zero pixel point is found or all pixel points in the image are traversed. As can be seen, the present application only needs to traverse the image once to calculate the distance between the pixels, greatly improving the processing speed for specific images.
[0050] 2、The method for improving the processing speed of image distance transformation of the present application can be calculated in parallel between points, which is more suitable for deployment on a multi-core processor such as GPU, so as to perform concurrent calculation and processing, thereby improving the image processing speed.
[0051] 3、The method for improving the processing speed of image distance transformation provided by the patent only needs to replace the judgment of zero point with comparison with the binary threshold value when binary fusion is needed, and the value less than the threshold value is zero point and the value greater than the threshold value is non-zero point, which can well fuse binary and distance transformation without increasing the calculation amount. BRIEF DESCRIPTION OF DRAWINGS
[0052] The above features, technical characteristics, advantages and their implementation will be further described in the following in a clear and understandable manner in combination with the preferred embodiments and the accompanying drawings.
[0053] Figure 1 is a flow diagram of one embodiment of the image distance transformation processing method provided by the present application;
[0054] Figure 2 is a pixel diagram of an image;
[0055] Figure 3 is a module block diagram of one embodiment of the image distance transformation processing method device provided by the present application;
[0056] Figure 4 is a module block diagram of another embodiment of the image distance transformation processing method device provided by the present application. DETAILED DESCRIPTION
[0057] In the following description, for purposes of explanation and not limitation, specific details are set forth such as particular architectures, techniques, etc. in order to provide a thorough understanding of the embodiments of the present application. However, it will be apparent to those skilled in the art that the present application can be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known methods, devices, circuits, and
[0058] It should be understood that the term "comprises" when used in this specification and the appended claims indicates the presence of the described features, integers, steps, operations, elements, and / or components but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.
[0059] It should also be further understood that the term "and / or" when used in the specification and in the claims, means any one and all combinations of one or more of the associated listed items.
[0060] In addition, in the description of the present application, the terms "first", "second", etc. are only used to distinguish descriptions, and cannot be understood as indicating or implying relative importance.
[0061] In order to more clearly illustrate the technical solutions of the embodiments of the present application or the prior art, the specific embodiments of the present application will be described below with reference to the drawings. Obviously, the drawings in the following description are only some embodiments of the present application, and for those skilled in the art, other drawings can be obtained from these drawings without creative labor, and other embodiments can also be obtained.
[0062] In one embodiment, with reference to Figure 1 The method for improving the processing speed of image distance transformation provided by the present application comprises the steps of:
[0063] S100, acquiring an image to be processed;
[0064] S200, dividing the pixel points of the image to be processed into zero pixel points and non-zero pixel points according to a preset threshold value;
[0065] Specifically, the traditional distance transformation method usually takes the image after binaryzation processing as input when processing, while the present method can directly preset the threshold value of binaryzation, and realizes the distance transformation processing of the image without increasing the amount of calculation.
[0066] S300, selecting a non-zero pixel point as a target non-zero pixel point, and searching whether there is a zero pixel point within the interval range of the preset search radius with the target non-zero pixel point as the center;
[0067] Specifically, with reference toFigure 2 , assuming that the label 0 position is a non-zero point, to find the nearest zero point from the point position, so as to calculate the Manhattan distance, it should be emphasized that the search radius in the present patent is different from the general radius, the search radius here is the distance sum of the horizontal and vertical directions, not the straight line distance between two pixel points.
[0068] S400, when the zero pixel point is found, the zero pixel point is taken as the nearest zero pixel point to the target non-zero pixel point;
[0069] When no zero pixel point is found, the search radius is expanded to continue searching until the nearest zero pixel point to the target non-zero pixel point is found; wherein the expansion range of the search radius is one pixel distance per expansion;
[0070] S500, after obtaining each non-zero pixel point and its nearest zero point pixel point, the Manhattan distance between each non-zero pixel point and its nearest zero point pixel point is determined.
[0071] Specifically, as shown in Figure 2 , first set the search radius to 1 pixel distance, search for labels 1, 2, 3, and 4, if no zero pixel point is found, set the search radius to 2 pixel distance, search for 8 points in the range of 5, 6, 7, 8, 9, 10, 11, 12. If no zero point is found, set the radius to 3 and repeat the above operation until a zero point is found, and then calculate the corresponding Manhattan distance.
[0072] In one embodiment, on the basis of the above embodiment, it is determined whether there is a zero pixel point in the range with the target non-zero pixel point as the center and with a preset search radius as the search radius, specifically comprising:
[0073] Set a two-dimensional coordinate system to determine the coordinate position of the target non-zero pixel point;
[0074] Specifically, for example, the target non-zero pixel point can be set as the origin of the coordinate system, and the pixel points in the same row as the target non-zero pixel point are on the horizontal coordinate, and the pixel points in the same column as the target non-zero pixel point are on the vertical coordinate.
[0075] According to the preset search radius, determine the search interval range;
[0076] Divide the pixel points in the search interval range into a plurality of groups of symmetric pixel points; each group of symmetric pixel points contains at least one pair of symmetric pixel points;
[0077] According to the preset search order rule, sequentially search whether the pixel points in each group of symmetric pixel points are zero pixel points.
[0078] Specifically, still refer toFigure 2 For the same search radius, the search space is set to several groups of symmetric points, for example, when the radius is 2, the search space is divided into {5, 9}, {7, 11} and {6, 8, 10, 12} three groups of symmetric points, since the four points are symmetric, their offset distances in X and Y directions relative to the center point are consistent, assuming x_t and y_t are the offset distances in X and Y directions, the coordinates of the symmetric four points are calculated as:
[0079] (X0+x_t, Y0+y_t), (X0-x_t, Y0+y_t), (X0+x_t, Y0-y_t), (X0-x_t, Y0-y_t),
[0080] At this time, only one update of x_t and y_t value can calculate four coordinate points, when x_t and y_t are not equal to zero, (X0+x_t, Y0+y_t) and (X0-x_t, Y0+y_t), (X0+x_t, Y0-y_t) and (X0-x_t, Y0-y_t) are stored in the same row, the storage location in memory is closer, and the calculation together can improve the memory access efficiency, so the corresponding calculation order is right up, left up, left down and right down four coordinate points, as shown in the following table.
[0081]
[0082]
[0083] The zero point ratio of 1% is converted into 11.5TFLOPS, and the results of the present patent are flat when the zero point ratio is 50%, the performance of MALI G77 and the mainstream algorithm on GTX 1080. If GTX 1080 is used for testing, the performance will be obviously better than other algorithms. The method can be used in the field of image distance transformation processing, especially for images with relatively uniform zero point distribution, which has excellent processing effect, for example, in automatic driving, the distance of each point from the lane line is detected, there are several lane lines, and they are arranged at equal intervals, or when judging whether the object on the previous image and the next image is the same object. When two images are collected at a very short interval, the displacement distance of an object on the image is very small, and the object with the shortest distance in image one and image two is the same object. In the medical field, some cells or bacteria are calculated, and the distribution of bacteria or cells is calculated. There are more bacteria in some places, and the distance of each point is smaller, and vice versa. The present patent controls the probability of occurrence of uniformly distributed zero points on the whole image to generate corresponding test images, and the test results are shown in the following table.
[0084] Zero scale 512x512 1024x1024 2048x2048 1% 4.3319 ms 16.4691 ms 64.7820 ms 10% 1.0065 ms 3.3897 ms 15.3227 ms 30% 0.4567 ms 1.5459 ms 6.7348 ms 50% 0.2939 ms 1.0208 ms 3.9181 ms 70% 0.1896 ms 0.8111 ms 2.6078 ms
[0085] In one embodiment, on the basis of the above-mentioned embodiments, the pixel points in the search interval range are divided into a plurality of sets of symmetrical pixel points, and the method specifically comprises:
[0086] The ratio of the search radius and the pixel distance is obtained as a reference number;
[0087] According to the reference number, the number of groups into which the pixel points in the search interval range are divided is determined; the number of groups is one more than the reference number;
[0088] The coordinate positions of the reference pixel points of each group are determined in sequence;
[0089] The symmetrical pixel points of the reference pixel points relative to the X axis, the Y axis and the origin are obtained, to obtain the set of symmetrical pixel points of the group.
[0090] Specifically, the current search radius of the non-zero pixel point determines the number of groups into which the pixel points in the current search interval range are divided. For example, if the current search radius is 1 pixel distance, the corresponding number of groups is 2 groups, i.e., the two pixel points that are 1 pixel distance away from the target non-zero pixel point in the X axis direction are the first group, and the two pixel points that are 1 pixel distance away from the target non-zero pixel point in the Y axis direction are the second group. If the current search radius is 5 pixel distances, the corresponding number of groups to be divided is 6 groups.
[0091] After the groups are determined, the specific coordinates of the pixel points in each group can be determined. In this embodiment, the coordinate positions of the reference pixel points of each group are first determined, and the coordinate positions of the reference pixel points can be selected in combination with the preset search direction. For example, as shown in FIG. 4, the coordinate positions of the reference pixel points of each group are determined in combination with the preset search direction. Figure 2As shown, if the middle 0 is a target non-zero pixel point, a two-dimensional coordinate system is established with the target non-zero pixel point as the origin, the pixel points in the same row of the target non-zero pixel point are on the X axis, and the pixel points in the same column of the target non-zero pixel point are on the Y axis. Assuming that the search radius is expanded to 3 pixel distances (the previous search radius did not find a zero pixel point), it can be determined that the pixel points can be divided into 4 groups under the current search radius; then the reference pixel points of each group are determined, for example, according to the search direction sequence, the reference pixel point 13 of the first group is determined (for example, the coordinate position (3, 0)), so that the symmetric pixel point of the point relative to the target non-zero pixel point is found based on the reference pixel point, which is the pixel point 19 (the coordinate position (-3, 0)), that is, the first group of symmetric pixel point set contains the pixel points {13, 19}; the reference pixel point of the second group, which can be obtained by shifting the horizontal coordinate to the left by one pixel distance and the vertical coordinate upward by one pixel distance based on the coordinate position of the reference pixel point 13, is the reference pixel point 14, and then the symmetric pixel points 18, 20, and 24 of the pixel point 14 relative to the Y axis, the target non-zero pixel point (origin), and the X axis are obtained, respectively; so that the pixel points {14, 18, 20, 24} of the second group of symmetric pixel point set are obtained; the reference pixel point of the third group, which is obtained by continuing to shift the horizontal coordinate to the left by one pixel distance and the vertical coordinate upward by one pixel distance based on the reference pixel point of the second group (of course, it can also be obtained by shifting the horizontal coordinate to the left by two pixel distances and the vertical coordinate upward by two pixel distances based on the reference pixel point of the first group), is the reference pixel point 15, and the symmetric pixel points 17, 21, and 23 of the pixel point 15 relative to the Y axis, the target non-zero pixel point (origin), and the X axis are obtained based on the reference pixel point 15, respectively; the pixel {15, 17, 21, 23} of the third group of symmetric pixel point set is obtained; and the reference pixel of the last group, which is obtained by further shifting the horizontal coordinate to the left by one pixel distance and the vertical coordinate upward by one pixel distance based on the reference pixel of the previous group (of course, it can also be obtained by shifting the horizontal coordinate to the left by three pixel distances and the vertical coordinate upward by three pixel distances based on the reference pixel point of the first group), is the reference pixel point 16, and the symmetric pixel point 22 is further determined based on the reference pixel point 16, that is, the fourth group of symmetric pixel point set is {16, 22}. Except that the symmetric pixel point set of the first group and the last group has only two pixels (the pixel point of the first group is on the X axis, and the pixel point of the last group is on the Y axis, so it has only one symmetric point), the symmetric pixel point set of each group in the middle contains 4 pixel points, and the remaining three symmetric pixel points can be calculated based on the reference pixel point of each group.
[0092] In one embodiment, on the basis of the above-mentioned embodiment, whether the pixel points in each group of symmetric pixel point set are zero pixel points is sequentially searched according to a preset search sequence rule, which specifically includes:
[0093] According to the preset search order, the search order of the plurality of sets of symmetric pixel point sets is determined.
[0094] According to the search order of the plurality of sets of symmetric pixel point sets, it is sequentially searched whether the zero pixel point is contained in each set of symmetric pixel point sets. Once the zero pixel point is found, the search is stopped, otherwise the search is continued until all the symmetric pixel point sets are traversed.
[0095] Specifically, the zero pixel point is searched in a symmetric manner, and the pixel points stored in the memory close to the target pixel point are searched preferentially. When the zero pixel point is found, the Manhattan distance of the zero pixel point from the target pixel point is calculated. If the zero pixel point is not found, the search is continued until all the symmetric pixel point sets are traversed.
[0096] In one embodiment, on the basis of the above embodiment, the pixel points of the image to be processed are divided into zero pixel points and non-zero pixel points according to a preset threshold, and specifically comprising:
[0097] The image to be processed is binarized according to the preset threshold to obtain a corresponding binarized image.
[0098] The pixel points in the binarized image are divided into zero pixel points and non-zero pixel points.
[0099] Specifically, the method can first binarize the image to obtain a binarized image, or can distinguish the zero pixel points and the non-zero pixel points by a threshold, which is not limited herein.
[0100] Based on the same technical concept, in one embodiment, referring to Figure 3 The application further provides a device for improving the processing speed of image distance transformation, comprising:
[0101] The acquisition module 10 is used for acquiring an image to be processed.
[0102] The preprocessing module 20 is used for dividing the pixel points of the image to be processed into zero pixel points and non-zero pixel points according to a preset threshold.
[0103] Specifically, according to the binarization threshold input by a user, the pixel points and the non-zero pixel points are determined by comparing the pixel value with the size of the binarization threshold input by the user.
[0104] The pixel point searching module 30 is used for selecting a non-zero pixel point as a target non-zero pixel point, searching whether there is a zero pixel point in a preset search radius interval range centered on the target non-zero pixel point. When the zero pixel point is found, the zero pixel point is taken as the zero pixel point closest to the target non-zero pixel point. When the zero pixel point is not found, the search radius is enlarged to continue searching until the zero pixel point closest to the target non-zero pixel point is found. The search radius is enlarged by one pixel distance each time.
[0105] The distance calculation module 40 is configured to determine the Manhattan distance between each non-zero pixel point and its nearest zero pixel point after obtaining each non-zero pixel point and its nearest zero pixel point.
[0106] Specifically, a non-zero pixel point is determined as a target pixel point, and a radius is set as one pixel point to search for a zero pixel point. If no zero pixel point is found within the radius, the search radius is expanded by one unit (one pixel) to continue searching until the nearest zero pixel point is found. Then, the Manhattan distance between the non-zero pixel point and the nearest zero pixel point is calculated by the distance calculation module.
[0107] In one embodiment, with reference to Figure 4 On the basis of the above embodiment, the pixel point searching module specifically includes:
[0108] The coordinate establishing submodule 31 is configured to set a two-dimensional coordinate system and determine the coordinate position of the target non-zero pixel point.
[0109] The interval determining submodule 32 is configured to determine the search interval range according to the preset search radius.
[0110] The grouping submodule 33 is configured to divide the pixel points in the search interval range into a plurality of sets of symmetric pixel points. Each set of symmetric pixel points includes at least one pair of symmetric pixel points.
[0111] The searching submodule 34 is configured to sequentially search whether the pixel points in each set of symmetric pixel points are zero pixel points according to a preset search order rule.
[0112] Specifically, the coordinate establishing submodule is used to establish a two-dimensional coordinate system, in which the distance between the target pixel point and the nearest zero pixel point is calculated. The interval determining submodule is used to determine the search radius, and when no zero pixel point is found within the search radius, the search radius is expanded to continue searching. Before searching for the zero pixel point, the pixel points within the search radius are combined according to symmetry, and then the searching submodule is used to search according to the order.
[0113] In one embodiment, on the basis of the above embodiment, the grouping submodule specifically includes:
[0114] The group number determining unit is configured to obtain the ratio of the search radius to the pixel distance as a reference number, and determine the group number of the pixel points in the search interval range according to the reference number. The group number is one more than the reference number.
[0115] Specifically, the reference number is obtained by the search radius and the pixel distance, and then the group number is determined according to the reference number.
[0116] A reference determination unit is used to sequentially determine the coordinate positions of reference pixels in each group;
[0117] The symmetry point acquisition unit is used to acquire the symmetric pixels of the reference pixel relative to the X-axis, Y-axis and origin respectively, to obtain the set of symmetric pixels of this group.
[0118] In one embodiment, based on the above embodiments, the preprocessing module specifically includes:
[0119] The binarization processing submodule is used to perform binarization processing on the image to be processed to obtain the corresponding binarized image;
[0120] The pixel region module is used to divide pixels in a binarized image into zero pixels and non-zero pixels.
[0121] Specifically, the binarization processing submodule is used to binarize the image to obtain a binarized image. Then, the pixel region submodule divides the pixels in the binarized image into two types: zero pixels and non-zero pixels, so as to facilitate subsequent pixel search and distance calculation.
[0122] In one embodiment, the present invention also provides an electronic device including one or more processors and a memory storing computer instructions that, when executed by the processor, perform the distance transformation method of any of the above embodiments.
[0123] Specifically, these can be implemented using computer-executable program code, thus allowing them to be stored in a storage device for execution by a computing device, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Therefore, this invention is not limited to any particular hardware and software combination.
[0124] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0125] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0126] The units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected to achieve the purpose of the embodiment scheme according to actual needs.
[0127] In addition, the functional units in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0128] It should be noted that the above embodiments can be freely combined as needed. The above is only the preferred embodiment of the present application. It should be noted that for those skilled in the art, without departing from the principles of the present application, a number of improvements and refinements can be made, which should be considered as the protection scope of the present application.
Claims
1. A method of improving processing speed of image distance transform, characterized by, The method comprises the steps of: obtaining a to-be-processed image; dividing pixel points of the to-be-processed image into zero pixel points and non-zero pixel points according to a preset threshold value; selecting a non-zero pixel point as a target non-zero pixel point, and searching whether there is a zero pixel point in a range of a preset search radius centered on the target non-zero pixel point; when the zero pixel point is found, taking the zero pixel point as a zero pixel point closest to the target non-zero pixel point; when the zero pixel point is not found, then expanding the search radius to continue searching until the zero pixel point closest to the target non-zero pixel point is found; wherein the search radius is expanded by one pixel distance each time; after obtaining each non-zero pixel point and the zero pixel point closest to the non-zero pixel point, determining a Manhattan distance between each non-zero pixel point and the zero pixel point closest to the non-zero pixel point; wherein the searching whether there is a zero pixel point in the range with the preset search radius centered on the target non-zero pixel point comprises: setting a two-dimensional coordinate system to determine a coordinate position of the target non-zero pixel point; determining a search interval range according to the preset search radius; dividing pixel points in the search interval range into a plurality of sets of symmetrical pixel points; each set of symmetrical pixel points contains at least one pair of symmetrical pixel points; according to a preset search order rule, sequentially searching whether pixel points in each set of symmetrical pixel points are zero pixel points.
2. The method of claim 1, wherein, The dividing the pixel points in the search interval range into the plurality of sets of symmetrical pixel points comprises: obtaining a ratio of the search radius to a pixel distance as a reference number; determining a group number for grouping the pixel points in the search interval range according to the reference number; the group number is one more than the reference number; sequentially determining coordinate positions of reference pixel points of each group; obtaining symmetrical pixel points of the reference pixel points relative to an X axis, a Y axis and an origin to obtain a set of symmetrical pixel points.
3. The method of claim 1, wherein, The sequentially searching whether the pixel points in each set of symmetrical pixel points are zero pixel points according to the preset search order rule comprises: determining a search order of the plurality of sets of symmetrical pixel points according to a preset search order; according to the search order of the plurality of sets of symmetrical pixel points, sequentially searching whether each set of symmetrical pixel points contains a zero pixel point; once the zero pixel point is found, the searching stops; otherwise, the searching continues until all symmetrical pixel points are traversed.
4. A method of increasing the processing speed of an image distance transform according to any one of claims 1 to 3, characterized in that, The dividing the pixel points of the to-be-processed image into zero pixel points and non-zero pixel points according to the preset threshold value comprises: performing binaryzation processing on the to-be-processed image according to a preset threshold value to obtain a corresponding binaryzation image; dividing pixel points in the binaryzation image into zero pixel points and non-zero pixel points.
5. An apparatus for improving processing speed of image distance transform, characterized by, The method comprises: an obtaining module, configured to obtain a to-be-processed image; a preprocessing module, configured to divide pixel points of the to-be-processed image into zero pixel points and non-zero pixel points according to a preset threshold value; The pixel point searching module is configured to select a non-zero pixel point as a target non-zero pixel point, and search whether there is a zero pixel point within a preset search radius interval range centered on the target non-zero pixel point; when the zero pixel point is found, the zero pixel point is taken as a zero pixel point closest to the target non-zero pixel point; When the zero pixel point is not found, the search radius is expanded to continue searching until the zero pixel point closest to the target non-zero pixel point is found; wherein the search radius is expanded by one pixel distance each time; The distance calculation module is configured to determine the Manhattan distance between each non-zero pixel point and the zero pixel point closest to the non-zero pixel point after obtaining each non-zero pixel point and the zero pixel point closest to the non-zero pixel point. The pixel point searching module specifically includes: The coordinate establishing submodule is configured to set a two-dimensional coordinate system and determine the coordinate position of the target non-zero pixel point; The interval determining submodule is configured to determine the search interval range according to the preset search radius; The grouping submodule is configured to divide the pixel points in the search interval range into a plurality of groups of symmetric pixel points; each group of symmetric pixel points includes at least one pair of symmetric pixel points; The searching submodule is configured to sequentially search whether the pixel points in each group of symmetric pixel points are zero pixel points according to a preset searching order rule.
6. The apparatus of claim 5, wherein, The grouping submodule specifically includes: The grouping number determining unit is configured to obtain the ratio of the search radius to the pixel distance as a reference number, and determine the number of groups for grouping the pixel points in the search interval range according to the reference number; the number of groups is one more than the reference number; The reference determining unit is configured to sequentially determine the coordinate positions of the reference pixel points in each group; The symmetric point obtaining unit is configured to obtain the symmetric pixel points of the reference pixel points with respect to the X axis, the Y axis, and the origin, to obtain the symmetric pixel point set of the group.
7. The apparatus of claim 5, wherein, The preprocessing module specifically includes: The binarization processing submodule is configured to perform binarization processing on the image to be processed to obtain a corresponding binarization image; The pixel distinguishing submodule is configured to divide the pixel points in the binarization image into zero pixel points and non-zero pixel points.
8. An electronic device, comprising: The computer program product comprises one or more processors and a memory storing computer instructions, which, when executed by the processor, cause the processor to execute the method for improving the processing speed of image distance transformation according to any one of claims 1-4.
Citation Information
Patent Citations
Method for fast transforming full distance of binary image
CN102737360A
Image data processing method and apparatus, and electronic device
CN106920252A