A method and device for generating thick and thin contour lines
Obtain the original coordinate data of the contour line through computer methods, calculate the pixel point coordinates and slope aspect values, and determine the pixel point width based on these values, which solves the problem of the existing technology that the contour line does not have a strong three-dimensional effect and achieves richer details. and contour drawing with a stronger three-dimensional sense.
Patent Information
- Application Number
- CN202010753694.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-30
- Publication Date
- 2025-01-21
- Estimated Expiration
- 2040-07-30
AI Technical Summary
The three-dimensional sense of drawing contour lines in existing computer methods is not strong and cannot effectively reflect the morphology.
By obtaining the original coordinate data of the contour line, the coordinates of the pixel points on the sub-line segments are calculated, and the slope aspect value of the pixel point is obtained using the inverse distance weighted average method. According to the slope value and illumination direction angle, as well as the set minimum and maximum width of the contour line, the width of each pixel is determined, and then the contour line is drawn.
The generated contours have richer details and stronger three-dimensionality, are better than existing computer rendering methods, and have a higher rendering speed.
Smart Images

Figure CN111915728B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of image data processing, and in particular relates to a method and device for generating thick and thin contour lines. Background Art
[0002] Contour lines are closed curves formed by connecting points of equal elevation on the ground in order of adjacency. Based on contour lines, we can determine both the location of landforms and the undulating shapes of landforms, such as identifying basic landforms such as mountain tops, saddles, ridges, slopes and valleys. However, the essence of contour lines is to "grade" the continuous surface, which lacks a clear sense of three-dimensionality and makes it impossible for observers to quickly determine the landform shape based on contour lines. Usually, observers need to accumulate visual experience to quickly determine the landform shape.
[0003] In order to increase the three-dimensional effect of contour lines, there are mainly two types of thick and thin contour line drawing methods in the prior art:
[0004] 1) Manually draw thick and thin contour lines. For example, the author Gu Baoqing proposed in a paper titled "Design of Thick and Thin Light and Dark Contour Line Method" that based on the basic thick and thin contour line generation method, the contour lines on the backlit surface are drawn as thick lines, and the contour lines on the lighted surface are drawn as thin lines. The maximum line width of the contour line drawing is determined according to the purpose, scale and landform characteristics of the map, so as to constrain the change of pen width when manually drawing thick and thin contour lines.
[0005] The disadvantages of this method are that the workload of manually drawing contour lines is too large, the drawing speed is slow, and the efficiency is low; in addition, the thickness of the contour lines is greatly affected by the subjective factors of the drawer (such as attention), and a good drawing effect cannot be guaranteed.
[0006] 2) Drawing thick and thin contour lines by computer. For example, in an article titled "Research on the topographic representation method combining layered coloring with gradient light and dark contour lines", the author Fang Qiangfei proposed that the contour lines be divided into six types according to the angle between the slope and the light source direction, and corresponding width values are set for different types of contour lines. Finally, each type of contour line is drawn according to the width value, thereby realizing the drawing of thick and thin contour lines in a computer environment.
[0007] The advantages of this method are that it is simple and easy to implement; the disadvantages are that the drawn thick and thin contour lines are not detailed enough and the three-dimensional effect is not strong enough. Summary of the invention
[0008] The purpose of the present invention is to provide a method for generating thick and thin contour lines, which is used to solve the problem that the existing computer method for drawing contour lines has a weak three-dimensional effect. At the same time, the present invention proposes a device for generating thick and thin contour lines, which is used to solve the problem that the existing computer method for drawing contour lines has a weak three-dimensional effect.
[0009] Based on the above purpose, a technical solution of a method for generating thick and thin contour lines is as follows:
[0010] (1) Obtaining the original coordinate data of the contour line, determining a sub-segment between every two adjacent data points, calculating the slope of the sub-segment based on the data points at both ends of the sub-segment, and when the absolute value of the slope is less than or equal to 1, using the x-axis direction as the incremental step direction to sequentially determine the coordinates of each pixel point on the sub-segment; when the absolute value of the slope is greater than 1, using the y-axis direction as the incremental step direction to sequentially determine the coordinates of each pixel point on the sub-segment;
[0011] (2) The coordinates of each pixel point are converted into the coordinates of the aspect grid data spatial reference, and the inverse distance weighted average of the four adjacent aspect pixel values around the pixel point is performed to obtain the aspect value at the pixel point. The calculation formula is as follows:
[0012]
[0013]
[0014] In the formula, α is the slope value at the pixel point, λ i is the inverse distance weight, a i is the value of the neighboring pixel of the pixel, i=1,2,3,4, d i Indicates the distance between adjacent pixels and pixels.
[0015] (3) Determine the width of each pixel point on each sub-segment according to the slope value at the pixel point in each sub-segment, the determined illumination direction angle, and the set minimum width and maximum width of the contour line; draw each sub-segment according to the width of each pixel point on each sub-segment to generate contour lines.
[0016] Based on the above purpose, a technical solution of a thick and thin contour line generating device is as follows:
[0017] The invention comprises a memory and a processor, and a computer program stored in the memory and running on the processor. The processor is coupled with the memory, and the thick and thin contour line generating method is realized when the processor executes the computer program.
[0018] The beneficial effects of the above two technical solutions are:
[0019] The present invention first obtains the original coordinate data of the contour line, and for the sub-line segment between two sequentially adjacent data points in the coordinate data, determines the coordinates of each pixel point on the sub-line segment; then uses the inverse distance weighted average method to obtain the slope value of the pixel point, and finally determines the width of each pixel point on the sub-line segment according to the slope value and the determined illumination direction angle, as well as the set minimum width and maximum width of the contour line; draws each sub-line segment according to the pixel point width determined by the above method, and generates a contour line with richer three-dimensional sense. The method of the present invention is suitable for computer drawing of contour lines, and has better and more three-dimensional drawing effects than the existing computer drawing methods, and can ensure a high drawing speed.
[0020] Furthermore, in order to ensure that the contour line drawing effect is smoother, in step (1), the original coordinate data of the contour line is updated to obtain updated coordinate data of the contour line, and each sub-line segment is determined according to the updated coordinate data of the contour line; the step of updating the original coordinate data includes:
[0021] The original coordinate data of the contour lines are interpolated to obtain a plurality of interpolation points; the original coordinate data of the contour lines are updated using the interpolation points.
[0022] By interpolating the original data of the contour lines, the data is updated using several interpolation points obtained by interpolation to ensure that the contour line drawing effect is smoother;
[0023] Furthermore, in order to achieve a smooth effect when drawing contour lines, the original contour line data is interpolated using an angle smoothing method in step (1).
[0024] Furthermore, in order to increase the speed of generating contour lines, in step (3), the widths of N consecutive adjacent pixels on each sub-segment are equal, N>1, and the width of one of the pixels is used to replace the width of the remaining (N-1) pixels, without having to calculate the width value of each pixel on the sub-segment.
[0025] Furthermore, the calculation formula for the pixel width is as follows:
[0026] w=w min +(w max -w min )|cos(α+β)|
[0027] Where w is the width of the pixel, w min is the minimum width of the contour line, w max is the maximum width of the contour line, α is the slope value at the pixel point, and β is the illumination direction angle. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1Schematic diagram of interpolation points obtained by performing the first interpolation using the angle smoothing method in the embodiment of the method of the present invention;
[0029] Figure 2 Schematic diagram of interpolation points obtained by performing a second interpolation using the corner smoothing method in an embodiment of the method of the present invention;
[0030] Figure 3 is a flow chart of a method for generating thick and thin contour lines in an embodiment of the method of the present invention;
[0031] Figure 4-1 It is a contour drawing obtained according to the existing computer drawing method in the embodiment of the method of the present invention;
[0032] Figure 4-2 In the embodiment of the method of the present invention, Figure 3 The contour plot obtained by the method in;
[0033] Figure 5 Schematic diagram of a device for generating thick and thin contour lines in an embodiment of the device of the present invention;
[0034] The label description is as follows:
[0035] A represents a contour line obtained by using an existing computer drawing method; A1 represents a contour line obtained by using the method of the present invention. DETAILED DESCRIPTION
[0036] The specific implementation of the present invention will be further described below in conjunction with the accompanying drawings.
[0037] Method Example:
[0038] This embodiment proposes a method for generating thick and thin contour lines. The basic implementation principle of the method is to obtain original coordinate data of the contour lines, interpolate the original coordinate data of the contour lines, and obtain a plurality of interpolation points; use these interpolation points to update the original coordinate data of the contour lines, and obtain updated coordinate data of the contour lines. In these updated coordinate data, every two adjacent data points can determine a sub-line segment, so that a plurality of sub-line segments can be obtained; determine the coordinates of each pixel point on each sub-line segment, and the slope aspect value of each pixel point, and calculate the width of each pixel point on the sub-line segment according to the slope aspect value and the determined illumination direction angle, as well as the set minimum width and maximum width of the contour line; when the widths of each pixel point on all sub-line segments are calculated, draw each micro-sub-line segment according to the obtained width of the pixel point, so as to generate contour lines.
[0039] The following are the specific implementation steps of the above method:
[0040] (1) The original contour data is smoothed using the smoothing method (i.e., linear iteration method) to obtain a new coordinate set.
[0041] Specifically, obtain the original data of the contour lines, and assume that the original coordinate set corresponding to the contour lines is P1, P2, ..., P i ,…,P n , loop to take out three consecutive points P i-1 (x i-1 ,y i-1 ), P i (x i ,y i ), P i+1 (x i+1 ,y i+1 ), line segment P i-1 P i and line segment P i P i+1 The midpoints of are A and B, such as Figure 1 As shown in AP i The B interval is interpolated using the following method:
[0042] ① Calculate line segment P i-1 P i and P i P i+1 Points O1(x1, y1), O2(x2, y2), O3(x3, y3), O4(x4, y4) at 1 / 4 of the time, connect O2 and O3, and erase the corner point P i The coordinate calculation formula of O1, O2, O3, and O4 is:
[0043] x1=x i-1 +(x i -x i-1 ) / 4,y1=y i-1 +(y i -y i-1 ) / 4 (1)
[0044] x2=x i +(x i-1 -x i ) / 4,y2=y i +(y i-1 -y i ) / 4 (2)
[0045] x3=x i +(x i+1 -x i ) / 4,y3=y i +(y i+1 -y i ) / 4 (3)
[0046] x4=x i+1 +(x i -xi+1 ) / 4,y4=y i+1 +(y i -y i+1 ) / 4 (4)
[0047] ② Continue to interpolate on the line segments O1O2, O2O3, O3O4, and similarly calculate the points O1′, O2′, O3′, O4′, O5′, O6′ at 1 / 4 of each interval, such as Figure 2 As shown, connect O2′O3′, erase the corner point O2, connect O4′O5′, and erase the corner point O3.
[0048] ③Use the same method to continue interpolating the points generated in step ②, iterate 5 times, and obtain 34 interpolation points.
[0049] The other intervals all get 34 interpolation points in this way, and finally the interpolation points of all intervals are arranged in order to generate a new coordinate set of the contour line as the update data of the contour line.
[0050] (2) Draw contour lines based on the updated contour line data.
[0051] Specifically, take out two adjacent points Q from the coordinate set in turn i-1 (x s ,y s )、Q(x e ,y e ), the numerical differentiation algorithm is used to determine the sub-segment Q i-1 Q i For all the pixels passed, the steps are as follows:
[0052] ① Calculate sub-segment Q i-1 Q i The slope k:
[0053] k=(y e -y s ) / (x e -x s ) (5)
[0054] ②If |k|≤1, select the x direction as the incremental step direction. i-1 ≤x i , then each step increases by 1, that is, △x=1; if x i-1 >x i , then △x=-1, so the calculation formula for any adjacent pixel points on the line segment is:
[0055] x i+1 =x i +△x,y i+1 =y i +△x·k (6)
[0056] If |k|>1, the y direction is selected as the incremental step direction. i-1 ≤y i , then each step increases by 1, that is, △y=1; y i-1 >y i , then △y=-1, so the calculation formula for any adjacent pixel points on the line segment is:
[0057] y i+1 =y i +△y,x i+1 =x i +△y / k (7)
[0058] According to the above formula, the coordinates (x i+1 ,y i+1 ).
[0059] ③ According to the pixel point coordinates, the corresponding slope data is converted and the inverse distance weighted average method is used to calculate the slope of any pixel point (x i+1 ,y i+1 ) at the slope direction.
[0060] Specifically, since the aspect information is stored in the aspect raster data, the aspect at the pixel point is calculated based on the aspect raster data: the pixel point coordinates are converted to the coordinates under the spatial reference of the aspect raster data, and the inverse distance weighted average of the four adjacent aspect pixel values around it is performed to obtain the aspect value at the pixel point. The calculation formula is as follows:
[0061]
[0062]
[0063] Among them, α is the slope value at the pixel point, λ i is the inverse distance weight, a i is the adjacent pixel value, d i Indicates the distance between adjacent pixels and pixels.
[0064] ④Calculate any pixel point (x i+1 ,y i+1 ) at the contour line width (i.e., pixel thickness). Specifically, the following formula is used to calculate the contour line width at the pixel point:
[0065] w=w min +(w max -w min )|cos(α+β)| (10)
[0066] Among them, w is the drawing width at the pixel point, w min 、wmax are the minimum and maximum widths of the contour lines, β is the illumination direction angle, and w min 、w max , β need to be specified according to actual conditions.
[0067] ⑤According to the pixel coordinates (x i+1 ,y i+1 ) and width value w to draw each pixel on the sub-segment.
[0068] In order to speed up the drawing of contour lines, a preferred drawing method is: draw a number of pixels equal to the width value in the horizontal or vertical direction according to the slope of the line segment, so there is no need to calculate the width value of each pixel on the sub-segment, but several pixels use the same width value.
[0069] That is, except for the coordinate (x i+1 ,y i+1 ), and w-1 pixels are drawn in the horizontal or vertical direction according to the slope k of the line segment where the pixel point is located. If |k|≤1, it is drawn in the horizontal direction, and if |k|>1, it is drawn in the vertical direction. When drawing, it is preferred to use the pixel point (x i+1 ,y i+1 ) as the center and draw [(w-1) / 2] pixels on both sides; as another implementation, the pixel point (x i+1 ,y i+1 ) as the starting point and draw w-1 pixels from one side to the other.
[0070] Finally, according to the above step (2), other sub-line segments are drawn in sequence to finally complete the drawing of a contour line.
[0071] (3) Repeat the above steps (1) and (2) to draw each contour line in turn, and finally generate a complete contour line drawing. The whole process is as follows: Figure 3 shown.
[0072] In order to verify the effectiveness of the method of this embodiment, the method of this embodiment is compared with the computer algorithm mentioned in the background technology, and the parameter w is set. min =0mm,w max =3mm, β=45°, the final contour line results are as follows Figure 4-1 and Figure 4-2 As shown, Figure 4-1 A contour line A in the ellipse-marked area, drawn by the existing computer algorithm, has little difference in linear thickness and no obvious three-dimensional effect; Figure 4-1 Redraw the contour lines in Figure 4-2As shown in FIG. 1 , it can be seen that the contour lines drawn by the method of this embodiment are more detailed and have a better three-dimensional effect. Specifically, the contour line A1 in the elliptical line marked area of the figure is Figure 4-1 The contour line A in the figure is the same contour line, but the thickness of contour line A2 is very different, and the three-dimensional effect is stronger. Figure 4-2 The other contour lines in Figure 4-1 The effects of the corresponding contour lines are compared. Figure 4-2 The contour lines in the image are more detailed and the three-dimensional effect is better.
[0073] In this embodiment, the smoothing method is used to interpolate the original contour coordinate set to generate a new contour coordinate set to ensure that the contour drawing effect is smoother. As other implementation methods, other curve smoothing methods can also be used, such as the tangent smoothing method. If this effect is not considered and it is only used to solve the problem of poor three-dimensional effect of drawing thick and thin contour lines, it is also possible to directly perform the contents of steps (2) and (3) without interpolating the original contour coordinate set to achieve the purpose.
[0074] In this embodiment, on each sub-segment of the contour line, a number of pixels equal to the width value are drawn in the horizontal or vertical direction according to the slope of the segment, so as to increase the pixel drawing speed. As another implementation method, considering further and more accurate three-dimensional drawing effects, the width value of each pixel point can also be calculated, and each pixel point is drawn according to the width value of each pixel point.
[0075] Device Example:
[0076] The present embodiment provides a thick and thin contour line generation device, including a memory and a processor, and a computer program stored in the memory and running on the processor. The processor is coupled to the memory, and the processor is used to run the program instructions stored in the memory to implement the thick and thin contour line generation method in the method embodiment. Since the method is described clearly and completely in the method example, it will not be repeated in this embodiment.
[0077] That is, the method in the above method embodiment should be understood that the process of the thick and thin contour line generation method can be implemented by computer program instructions. These computer program instructions can be provided to a processor (such as a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device, etc.), so that the processor executes these instructions to generate functions specified by the above method flow.
[0078] Specifically, Figure 5The thick and thin contour line generating device shown in the figure may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) and memories, and one or more storage media for storing applications or data. Among them, the memories and storage media may be temporary storage or permanent storage. The program stored in the storage medium may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the data processing device. Furthermore, the processor may be configured to communicate with the storage medium to execute a series of instruction operations in the storage medium on the thick and thin contour line generating device.
[0079] The thick and thin contour line generating device of this embodiment may also include one or more power supplies, one or more wired or wireless network interfaces; one or more input and output interfaces, wherein the input interface is used to obtain the original data of the contour line; the output interface is used to output the generated contour line; and / or one or more operating systems. For example, Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.
[0080] The processor referred to in this embodiment refers to a processing device such as a microprocessor MCU or a programmable logic device FPGA.
[0081] The memory referred to in this embodiment includes a physical device for storing information, which is usually a physical device for storing information after digitizing the information and then storing it in a medium using electrical, magnetic or optical means. For example: various memories that use electrical energy to store information, such as RAM, ROM, etc.; various memories that use magnetic energy to store information, such as hard disks, floppy disks, magnetic tapes, magnetic core memories, magnetic bubble memories, and USB flash drives; various memories that use optical means to store information, such as CDs or DVDs. Of course, there are other types of memories, such as quantum memories, graphene memories, and so on.
[0082] The thick and thin contour line generating device of this embodiment further includes a display, and the display is used to display the contour lines finally generated with richer three-dimensional sense.
[0083] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, ordinary technicians in the relevant field should understand that the specific implementation methods of the present invention can still be modified or replaced by equivalents. Any modification or equivalent replacement that does not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.
Claims
1. A method for generating thick and thin contour lines, characterized in that: The following steps are involved: (1) Obtain the original coordinate data of the contour line, determine a sub-segment between every two adjacent data points, calculate the slope of the sub-segment based on the data points at both ends of the sub-segment, and when the absolute value of the slope is less than or equal to 1, use the x-axis direction as the incremental step direction to determine the coordinates of each pixel point on the sub-segment in turn; when the absolute value of the slope is greater than 1, use the y-axis direction as the incremental step direction to determine the coordinates of each pixel point on the sub-segment in turn; (2) The coordinates of each pixel point are converted into the coordinates under the spatial reference of the aspect raster data. The inverse distance weighted average of the four adjacent aspect pixel values around the pixel point is performed to obtain the aspect value at the pixel point. The calculation formula is as follows: = = In the formula, is the slope value at the pixel point, is the inverse distance weight, is the adjacent pixel value of the pixel, i=1,2,3,4, Indicates the distance between adjacent pixels and pixels; (3) According to the slope value at the pixel point in each sub-segment, the determined illumination direction angle, and the set minimum width and maximum width of the contour line, the width of each pixel point on each sub-segment is determined; according to the width of each pixel point on each sub-segment, each sub-segment is drawn to generate contour lines. The calculation formula of the pixel point width is as follows: = In the formula, is the width of the pixel, is the minimum width of the contour line. is the maximum width of the contour line. is the slope value at the pixel point, is the lighting direction angle.
2. The method for generating thick and thin contour lines according to claim 1, characterized in that: In step (1), the original coordinate data of the contour line is updated to obtain updated coordinate data of the contour line, and each sub-line segment is determined according to the updated coordinate data of the contour line; the step of updating the original coordinate data includes: The original coordinate data of the contour lines are interpolated to obtain a plurality of interpolation points; the original coordinate data of the contour lines are updated using the interpolation points.
3. The method for generating thick and thin contour lines according to claim 2, characterized in that: In step (1), the original coordinate data of the contour line is interpolated using the smoothing method.
4. The method for generating thick and thin contour lines according to claim 1, characterized in that: In step (3), the widths of N consecutive adjacent pixels on each sub-segment are equal, N>1, and the width of one of the pixels is used to replace the width of the remaining (N-1) pixels.
5. A device for generating thick and thin contour lines, comprising a memory and a processor, and a computer program stored in the memory and running on the processor, wherein the processor is coupled to the memory, and characterized in that: When the processor executes the computer program, the method for generating thick and thin contour lines according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Contour-based depth image recognizing method
CN107392953A
Digital terrain model generation method and device, equipment and storage medium
CN110163970A