Stroke repairing method of character image, electronic device and storage medium
By obtaining the pixel matrix of the text image, stroke defects were identified and repaired, solving the problem of strokes floating or sinking after the text image was stretched at a 4:1 ratio, thus achieving better printing results and experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- JIANGMEN DASCOM COMP PERIPHERAL
- Filing Date
- 2022-10-09
- Publication Date
- 2026-04-24
AI Technical Summary
In existing technologies, text images stretched to a 4:1 ratio have defects such as strokes floating or sinking, resulting in poor printing quality. Although thickening the text covers up the defects, it also makes the strokes thicker.
By acquiring the pixel matrix of the image, the location and type of stroke defects can be determined, and the position of the pixel segments can be adjusted accordingly to repair stroke defects such as floating or sinking, for example by moving the defective pixel segments down or up.
It restores the strokes and lines of the text, improves the printing effect, makes the text smoother, and enhances the printing experience.
Smart Images

Figure CN115829856B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of text image restoration technology, and in particular to a method for restoring strokes of a text image, an electronic device, and a storage medium. Background Technology
[0002] Currently, in the printing industry, text images stretched to a 4:1 ratio often suffer from strokes that appear to float or sink, resulting in poor print quality. Typically, the text needs to be thickened before the stretching is performed to mask these stroke defects. However, this often results in noticeably thicker strokes and poor print quality. Summary of the Invention
[0003] The purpose of this application is to at least solve one of the technical problems existing in the prior art, and to provide a method for repairing the strokes of text images, an electronic device, a computer-readable storage medium, and a computer program product, which can repair the stroke defects of text images, restore the stroke lines of the text, and thus make the printing effect better.
[0004] In a first aspect, embodiments of this application provide a method for repairing strokes in a text image, wherein the text in the image has stroke defects. The method includes: obtaining a pixel matrix of the image; determining, based on the pixel matrix, pixel segments with the stroke defects and corresponding defect types; and repairing the pixel segments according to the defect types.
[0005] According to the first aspect of the present application, a method for repairing the strokes of a text image has at least the following beneficial effects: obtaining the pixel matrix of the image, determining the location and corresponding defect type of the stroke defects based on the pixel matrix, and repairing the stroke defects in a targeted manner according to the defect type to restore the stroke lines of the text, thereby improving the printing effect.
[0006] In one embodiment of this application, the stroke defects include stroke upward defects and stroke downward defects; the step of repairing the pixel segment according to the defect type includes: when the pixel segment is detected to have the stroke upward defect, moving the pixel segment downward; when the pixel segment is detected to have the stroke downward defect, moving the pixel segment upward.
[0007] In one embodiment of this application, determining the pixel segment with the stroke defect and the corresponding defect type based on the pixel matrix includes: scanning the pixel matrix line by line to obtain a line segment for determining the stroke defect, the line segment being composed of a plurality of horizontal pixels; and determining the pixel segment with the stroke defect and the corresponding defect type based on the position information and length information of the line segment.
[0008] In one embodiment of this application, the pixels in the pixel matrix include white points and non-white points, and the text is composed of the non-white points; obtaining the line segment used to determine the stroke defect includes: when a non-white point is detected, recording the consecutive number of non-white points to obtain a first line segment, and setting the white point horizontally adjacent to the endpoint of the first line segment as a first judgment point; when one of the upper or lower neighbor points of the first judgment point is detected as a non-white point, and a white point is detected horizontally connected to the non-white point, then the non-white point is set as a second judgment point, and the consecutive number of non-white points is recorded starting from the second judgment point to obtain a second line segment.
[0009] In one embodiment of this application, determining the pixel segment with the stroke defect and the corresponding defect type based on the position information and length information of the line segment includes: when it is detected that the number of pixels included in the first line segment or the second line segment is greater than a preset number, comparing the lengths of the first line segment and the second line segment; when it is detected that the ratio of the lengths of the first line segment and the second line segment is greater than a preset value, determining that the pixel segment where the second line segment is located has the stroke defect; when it is detected that the ratio of the lengths of the second line segment and the first line segment is greater than the preset value, determining that the pixel segment where the first line segment is located has the stroke defect; when it is detected that the second judgment point is an upper neighbor of the first judgment point, determining that the stroke defect is the stroke floating defect; when it is detected that the second judgment point is a lower neighbor of the first judgment point, determining that the stroke defect is the stroke sinking defect.
[0010] In one embodiment of this application, obtaining the line segment used to determine the stroke defect further includes: starting from the first judgment point, recording the consecutive number of white dots to obtain a third line segment; when it is detected that the length of the second line segment is equal to that of the third line segment, and a consecutive non-white dot is detected after the first judgment point, the first non-white dot after the first judgment point is set as the third judgment point, and starting from the third judgment point, the consecutive number of non-white dots is recorded to obtain a fourth line segment.
[0011] In one embodiment of this application, determining the pixel segment with the stroke defect and the corresponding defect type based on the position and length information of the line segment includes: when it is detected that the number of pixels included in the first line segment or the fourth line segment is greater than a preset number, and when it is detected that the ratio of the length of the first line segment or the fourth line segment to the length of the third line segment is greater than a preset value, then it is determined that the pixel segment where the second line segment is located has the stroke defect; when it is detected that the second judgment point is the upper neighbor of the first judgment point, the stroke defect is determined to be the stroke floating defect; when it is detected that the second judgment point is the lower neighbor of the first judgment point, the stroke defect is determined to be the stroke sinking defect.
[0012] Secondly, embodiments of this application provide an electronic device, including at least one control processor and a memory for communicatively connecting to the at least one control processor; the memory stores instructions executable by the at least one control processor, which, when executed by the at least one control processor, enables the at least one control processor to perform the stroke repair method for text images provided in the first aspect of this application.
[0013] An electronic device according to the second aspect of this application has at least the following beneficial effects: it can acquire the pixel matrix of an image, determine the location and corresponding defect type of stroke defects based on the pixel matrix, and perform targeted repair of stroke defects according to the defect type to restore the stroke lines of the text, thereby making the printing effect better.
[0014] Thirdly, embodiments of this application provide a computer-readable storage medium storing computer-executable instructions for causing a computer to execute the stroke repair method for text images provided in the first aspect of this application.
[0015] According to the computer-readable storage medium provided in the third aspect of this application, it has at least the following beneficial effects: it can acquire the pixel matrix of an image, determine the location and corresponding defect type of the stroke defect based on the pixel matrix, and perform targeted repair of the stroke defect according to the defect type to restore the stroke lines of the text, thereby making the printing effect better.
[0016] Fourthly, embodiments of this application provide a computer program product, including a computer program or computer instructions, characterized in that the computer program or computer instructions are stored in a computer-readable storage medium, a processor of a computer device reads the computer program or computer instructions from the computer-readable storage medium, and the processor executes the computer program or computer instructions, causing the computer device to execute the stroke repair method for text images provided in the first aspect of this application.
[0017] According to the fourth aspect of this application, a computer program product has at least the following beneficial effects: it can acquire the pixel matrix of an image, determine the location and corresponding defect type of stroke defects based on the pixel matrix, perform targeted repair of stroke defects based on the defect type, restore the stroke lines of the text, and thus make the printing effect better. Attached Figure Description
[0018] Figure 1 This is a flowchart illustrating the steps of a method for repairing strokes in a text image according to an embodiment of this application.
[0019] Figure 2 This is a detailed flowchart of the stroke restoration method for a text image provided in an embodiment of this application;
[0020] Figure 3 This is a detailed flowchart of the stroke restoration method for a text image provided in an embodiment of this application;
[0021] Figure 4 This is an example diagram of a text image provided in an embodiment of this application;
[0022] Figure 5 yes Figure 4 Enlarged view of point A in the middle;
[0023] Figure 6 This is a detailed flowchart of the stroke restoration method for a text image provided in an embodiment of this application;
[0024] Figure 7 This is a detailed flowchart of the stroke restoration method for a text image provided in an embodiment of this application;
[0025] Figure 8 yes Figure 4 Enlarged view of point B in the middle;
[0026] Figure 9 This is a detailed flowchart of a stroke restoration method for text images provided in an embodiment of this application;
[0027] Figure 10 This is a flowchart of another detailed step in a method for repairing strokes in a text image provided in an embodiment of this application;
[0028] Figure 11 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0029] This section will describe in detail the specific embodiments of this application. Preferred embodiments of this application are shown in the accompanying drawings. The purpose of the drawings is to supplement the textual description with graphics, so that people can intuitively and vividly understand each technical feature and the overall technical solution of this application, but they should not be construed as limiting the scope of protection of this application.
[0030] In the description of this application, "several" means one or more, "more than" means two or more, "greater than," "less than," and "exceeding" are understood to exclude the stated number, while "above," "below," and "within" are understood to include the stated number. If "first," "second," or "third" is used, it is only for the purpose of distinguishing technical features and should not be construed as indicating or implying relative importance or implicitly indicating the number of indicated technical features or the order of the indicated technical features.
[0031] In the description of this application, unless otherwise expressly defined, terms such as "setup," "installation," and "connection" should be interpreted broadly, and those skilled in the art can reasonably determine the specific meaning of the above terms in this application in conjunction with the specific content of the technical solution.
[0032] This application provides a method for repairing the strokes of text images, an electronic device, a computer-readable storage medium, and a computer program product, which can repair the stroke defects of text images, restore the stroke lines of the text, and thus improve the printing effect.
[0033] The embodiments of this application will be further described below with reference to the accompanying drawings.
[0034] Reference Figure 1 , Figure 1 This is a flowchart illustrating the steps of a stroke restoration method for text images provided in an embodiment of this application, as follows: Figure 1 As shown, an embodiment of this application provides a method for repairing strokes in a text image, the method including steps S100, S200 and S300.
[0035] Step S100: Obtain the pixel matrix of the image;
[0036] Step S200: Based on the pixel matrix, determine the pixel segments with stroke defects and the corresponding defect types;
[0037] Step S300: Repair the pixel segment according to the defect type.
[0038] In an exemplary embodiment, the text in the image has stroke defects. By obtaining the pixel matrix of the image, the pixel segments with stroke defects and the corresponding defect types can be determined based on the pixel matrix. After determining the location and type of the stroke defects, the stroke defects are repaired in a targeted manner, restoring the stroke lines of the text to a certain extent, thereby making the printing effect of the text image better and improving the user's printing experience.
[0039] As will be understood by those skilled in the art, an image is based on pixels as the smallest unit, and pixel information of an image can be obtained by converting the pixels of the image into a horizontal array to obtain a pixel matrix.
[0040] In the printing industry, after text images are horizontally stretched at a 4:1 ratio, defects such as some strokes rising or falling at the points where the strokes pause can occur, causing font distortion and affecting print quality. While thickening the text can cover up these defects, it makes the strokes noticeably thicker and fails to restore the original font shape. In this embodiment, the defects of rising or falling strokes at the points where the strokes pause can be repaired. This involves reasonably adjusting the position of the pixel segments with stroke defects without changing the font thickness, restoring the font strokes as much as possible, resulting in better print quality and an improved user printing experience.
[0041] In one exemplary embodiment, such as Figure 2 As shown, Figure 2 yes Figure 1 The detailed flowchart of step S300 includes stroke defects including stroke floating defects and stroke sinking defects. Step 300 may include step S310.
[0042] Step S310: When a pixel segment is detected to have a stroke floating defect, the pixel segment is moved down; when a pixel segment is detected to have a stroke sinking defect, the pixel segment is moved up.
[0043] In this embodiment, stroke defects include stroke floating defects and stroke sinking defects. When a pixel segment is detected to have a stroke floating defect, the pixel segment can be moved down, and the distance moved down can be a row in the pixel matrix, that is, the height of a pixel. When a pixel segment is detected to have a stroke sinking defect, the pixel segment can be moved up, and the distance moved up can be a row in the pixel matrix, that is, the height of a pixel.
[0044] In a feasible embodiment, this embodiment does not specifically limit the distance of the pixel segment moving up or down, and reasonable adjustments can be made, such as moving two or three lines. As long as the stroke defects can be repaired to a certain extent and the printed text strokes are smooth, it is within the protection scope of this embodiment.
[0045] In one exemplary embodiment, such as Figure 3 As shown Figure 3 is Figure 1 a detailed flowchart of step S200 in [description], where step 200 may include step S210 and step S220.
[0046] Step S210, scanning the pixel point matrix row by row to obtain line segments for determining stroke defects;
[0047] Step S220, determining pixel fragments with stroke defects and corresponding defect types according to the position information and length information of the line segments.
[0048] In an exemplary embodiment, scanning the pixel point matrix row by row from left to right, line segments for determining stroke defects can be obtained according to pixel point information. These line segments are composed of several horizontal pixel points. Pixel fragments with stroke defects and corresponding defect types can be determined according to the position information and length information of the line segments, where the position information refers to the positional relationship between line segments, and the length information refers to the number of pixel points included in the line segments.
[0049] In the embodiments of the present application, Figure 4 is an exemplary diagram of the character "障" after 4:1 horizontal stretching provided by the embodiments of the present application, which is used to illustrate the stroke repair method for text images provided by the embodiments of the present application later.
[0050] In an exemplary embodiment, as Figure 5 and Figure 6 shown, Figure 5 is Figure 4 an enlarged view of part A in [description], Figure 5 the second line segment in [description] is not fully shown; Figure 6 is Figure 3 a detailed flowchart of step S210 in [description], where the pixel point matrix of the image includes white points and non - white points, and step 210 may include step S211 and step S212.
[0051] Step S211, when detecting a non - white point, recording the continuous number of non - white points to obtain the first line segment, and setting the white point horizontally adjacent to the end point of the first line segment as the first judgment point;
[0052] Step S212, when detecting that one of the upper adjacent point or the lower adjacent point of the first judgment point is a non - white point, and detecting that there is a white point horizontally adjacent to the non - white point, setting the non - white point as the second judgment point, and starting from the second judgment point, recording the continuous number of non - white points to obtain the second line segment.
[0053] In this embodiment, the pixel matrix of the image includes white points and non-white points. The pixel matrix is scanned from top to bottom and left to right. When a non-white point is detected, the number of consecutive non-white points in the horizontal direction is recorded to obtain a first line segment. The white point horizontally connected to the endpoint of the first line segment is set as a first judgment point. When the upper or lower neighbor of the first judgment point is detected as a non-white point, the non-white point vertically adjacent to the first judgment point is set as a second judgment point. Starting from the second judgment point, the number of consecutive non-white points in the horizontal direction is recorded to obtain a second line segment. For example, it can be... Figure 4 Point A in the middle, i.e. Figure 5 In the process, the corresponding first and second line segments are found. Subsequently, the location and type of some stroke defects can be determined based on the first and second line segments, so as to move the pixel segments to repair the deformed strokes.
[0054] Reference Figure 5 and Figure 7 In one exemplary embodiment, Figure 7 yes Figure 3 The detailed flowchart of step S220 is provided, wherein step S220 includes steps S221, S222 and S223.
[0055] Step S221: When it is detected that the number of pixels included in the first line segment or the second line segment is greater than a preset number, the lengths of the first line segment and the second line segment are compared.
[0056] Step S222: When the ratio of the length of the first line segment to the length of the second line segment is detected to be greater than a preset value, it is determined that the pixel segment where the second line segment is located has a stroke defect; when the ratio of the length of the second line segment to the length of the first line segment is detected to be greater than a preset value, it is determined that the pixel segment where the first line segment is located has a stroke defect.
[0057] Step S223: When the second judgment point is detected as the upper neighbor of the first judgment point, the stroke defect is determined to be a stroke floating defect; when the second judgment point is detected as the lower neighbor of the first judgment point, the stroke defect is determined to be a stroke sinking defect.
[0058] After scanning the pixel matrix and obtaining the first and second line segments, if the number of pixels included in the first or second line segment is greater than a preset number, the lengths of the first and second line segments are compared. In this embodiment, the stroke defect appears at the stroke pause, so the length of the pixel segment with the stroke defect will not be too long. If the ratio of the length of the first line segment to the length of the second line segment is greater than a preset value, it indicates that the first line segment is longer and the second line segment is shorter, and the pixel segment containing the second line segment is determined to have a stroke defect. If the ratio of the length of the second line segment to the length of the first line segment is greater than a preset value, it indicates that the first line segment is shorter and the second line segment is longer, and the pixel segment containing the first line segment is determined to have a stroke defect. Since strokes such as left-falling strokes and right-falling strokes can form layered line segments, but the line segment length is relatively short, filtering based on the lengths of the first and second line segments can avoid misjudging normal layered line segments formed by strokes such as left-falling strokes and right-falling strokes as stroke defects. When the second judgment point is detected as the upper neighbor of the first judgment point, the stroke defect can be determined to be an upward floating defect; when the second judgment point is detected as the lower neighbor of the first judgment point, the stroke defect can be determined to be a downward sinking defect. For example Figure 4 Point A in the image represents a stroke defect, which can be identified from... Figure 4 Point A in the middle, i.e. Figure 5 Find the corresponding first and second line segments, and determine that there is a stroke floating defect at point A based on the first and second line segments. Subsequently, the pixel fragment with the stroke defect can be moved according to the defect type to achieve stroke repair, restore the stroke lines, and obtain a better printing effect.
[0059] In one feasible embodiment, the preset quantity can be 20, but this embodiment does not specifically limit the preset quantity. As long as it helps to avoid misjudging strokes such as left-falling strokes and right-falling strokes as stroke defects, it is within the protection scope of this embodiment.
[0060] In another feasible embodiment, the preset value can be 8, but this embodiment does not specifically limit the preset value. As long as it helps to avoid misjudging strokes such as left-falling strokes and right-falling strokes as stroke defects, it is within the protection scope of this embodiment.
[0061] Reference Figure 8 and 9 In one exemplary embodiment, Figure 8 yes Figure 4 Enlarged view at point B in the middle. Figure 8 The first line segment is not fully shown. Figure 9 yes Figure 3 The flowchart of a detailed step S210 is provided. Step S210 may also include steps S213 and S214.
[0062] Step S213: Starting from the first judgment point, record the number of consecutive white dots to obtain the third line segment;
[0063] Step S214: When the length of the second line segment is equal to that of the third line segment, and a series of non-white points are detected after the first judgment point, the first non-white point after the first judgment point is set as the third judgment point. Starting from the third judgment point, the number of consecutive non-white points is recorded to obtain the fourth line segment.
[0064] In this embodiment, after obtaining the first and second line segments, the number of consecutive white dots is recorded starting from the first judgment point to obtain the third line segment. When it is detected that the length of the second line segment is equal to the length of the third line segment, and consecutive horizontal non-white dots are detected after the first judgment point, the first non-white dot after the first judgment point is set as the third judgment point, and the number of consecutive horizontal non-white dots is recorded starting from the third judgment point to obtain the fourth line segment. For example... Figure 4 Point B in the diagram represents a stroke defect. According to this method, it can be... Figure 4 Point B in the middle, i.e. Figure 8 In the process, the corresponding first, second, third, and fourth line segments were detected. The location and type of stroke defects can then be determined based on these first, second, third, and fourth line segments.
[0065] Reference Figure 8 and Figure 10 In another exemplary embodiment, Figure 10 yes Figure 3 Another detailed flowchart of step S220 is shown below. Figure 10 As shown, step S220 may further include steps S224 and S225.
[0066] Step S224: When the number of pixels included in the first line segment or the fourth line segment is greater than a preset number, and the ratio of the length of the first line segment or the fourth line segment to the length of the third line segment is greater than a preset value, it is determined that the pixel segment in which the second line segment is located has a stroke defect.
[0067] Step S225: When the second judgment point is detected as the upper neighbor of the first judgment point, the stroke defect is determined to be a stroke floating defect; when the second judgment point is detected as the lower neighbor of the first judgment point, the stroke defect is determined to be a stroke sinking defect.
[0068] In this embodiment, after scanning the pixel matrix of the image to obtain the first, second, third, and fourth line segments, if the number of pixels included in the first or fourth line segment is greater than a preset number, and the ratio of the length of the first or fourth line segment to the length of the third line segment is greater than a preset value (i.e., the ratio of the length of the longer line segment in the first or fourth line segment to the length of the third line segment is greater than a preset value), then it is determined that the pixel segment containing the second line segment has a stroke defect. The reason for the stroke defect in the pixel segment containing the second line segment is that the stroke has a pause, so the second line segment will not be too long. The length of the third line segment is equal to that of the second line segment. The lengths of the first, second, third, and fourth line segments can be combined for screening and judgment to avoid misjudging strokes such as left-falling strokes and right-falling strokes as stroke defects. When the second judgment point is detected as the upper neighbor of the first judgment point, it can be determined that the stroke defect is an upward floating defect, and the pixel segment containing the second line segment can be moved down one row. When the second judgment point is detected as the lower neighbor of the first judgment point, it can be determined that the stroke defect is a downward sinking defect. For example, it can be determined that the second line segment is a downward sinking defect. Figure 4 Point B in the middle, i.e. Figure 8 The first, second, third, and fourth line segments are found, and the method provided in this embodiment determines that there is a stroke floating defect at point B. Subsequently, the pixel segment where the second line segment is located can be moved up to achieve stroke repair, restore the stroke lines, and obtain a better printing effect.
[0069] In one feasible embodiment, the preset quantity can be 20, but this embodiment does not specifically limit the preset quantity. As long as it helps to avoid misjudging strokes such as left-falling strokes and right-falling strokes as stroke defects, it is within the protection scope of this embodiment.
[0070] In another feasible embodiment, the preset value can be 8, but this embodiment does not specifically limit the preset value. As long as it helps to avoid misjudging strokes such as left-falling strokes and right-falling strokes as stroke defects, it is within the protection scope of this embodiment.
[0071] Reference Figure 11 , Figure 11This is a schematic diagram of the structure of an electronic device 1100 provided in an embodiment of this application. The electronic device 1100 includes at least one control processor 1110 and a memory 1120 for communicative connection with the at least one control processor 1110. The memory 1120 stores instructions executable by the at least one control processor 1110. The instructions are executed by the at least one control processor 1110 to enable the at least one control processor 1110 to perform the stroke repair method for text images provided in any of the above method embodiments. According to the electronic device 1100 provided in this application, it can perform the stroke repair method for text images. Based on the pixel matrix of the text image, it can determine pixel segments with stroke defects and their corresponding defect types. After determining the location and type of the stroke defects, it performs targeted repairs on the stroke defects, restoring the stroke lines of the text to a certain extent, thereby improving the printing effect of the text image and enhancing the user's printing experience.
[0072] This application also provides a computer-readable storage medium storing computer-executable instructions for causing a computer to execute the stroke repair method for text images provided in any of the above method embodiments. According to this stroke repair method for text images, pixel segments with stroke defects and their corresponding defect types can be determined based on the pixel matrix of the text image. After determining the location and type of the stroke defects, targeted repairs are performed on the stroke defects, restoring the stroke lines of the text to a certain extent, thereby improving the printing effect of the text image and enhancing the user's printing experience.
[0073] This application also provides a computer program product, including a computer program or computer instructions. The computer program or computer instructions are stored in a computer-readable storage medium. The processor of a computer device reads the computer program or computer instructions from the computer-readable storage medium and executes the computer program or computer instructions, causing the computer device to perform the stroke repair method for text images provided in any of the above method embodiments. According to this stroke repair method for text images, pixel segments with stroke defects and corresponding defect types can be determined based on the pixel matrix of the text image. After determining the location and type of the stroke defects, targeted repairs are performed on the stroke defects, restoring the stroke lines of the text to a certain extent, thereby improving the printing effect of the text image and enhancing the user's printing experience.
[0074] It will be understood by those skilled in the art that all or some of the steps and systems in the methods disclosed above can be implemented as software, firmware, hardware, and suitable combinations thereof. Some or all of the physical components can be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit. Such software can be distributed on a computer-readable medium, which may include computer storage media or non-transitory media and communication media or transient media. As is known to those skilled in the art, the term computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information such as computer-readable instructions, data structures, program modules, or other data. Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disc DVD or other optical disc storage, magnetic cartridges, magnetic tape, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and is accessible to a computer. Furthermore, as is known to those skilled in the art, communication media typically contain computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium.
Claims
1. A method for restoring strokes in a text image, characterized in that, The text in the image has stroke defects, and the method includes: Obtain the pixel matrix of the image; Based on the pixel matrix, determine the pixel segments with the stroke defects and the corresponding defect types; Repair the pixel segment according to the defect type; The stroke defects include stroke elevation defects and stroke depression defects; the step of repairing the pixel segment according to the defect type includes: When the pixel segment is detected to have the stroke floating defect, the pixel segment is moved down; When the pixel segment is detected to have the stroke sinking defect, the pixel segment is moved upward; The step of determining the pixel segment with the stroke defect and the corresponding defect type based on the pixel matrix includes: The pixel matrix is scanned line by line to obtain line segments used to determine the stroke defects, and the line segments are composed of several horizontal pixels; Based on the position and length information of the line segment, determine the pixel segment with the stroke defect and the corresponding defect type; The pixels in the pixel matrix include white pixels and non-white pixels, and the text is composed of the non-white pixels; obtaining the line segment used to determine the stroke defect includes: When the non-white point is detected, the number of consecutive non-white points is recorded to obtain the first line segment, and the white point that is horizontally adjacent to the end point of the first line segment is set as the first judgment point. When a non-white point is detected as either the upper or lower neighbor of the first judgment point, and a white point is detected as being horizontally connected to the non-white point, the non-white point is set as the second judgment point. Starting from the second judgment point, the number of consecutive non-white points is recorded to obtain the second line segment.
2. The method for stroke restoration of text images according to claim 1, characterized in that, The step of determining the pixel segment with the stroke defect and the corresponding defect type based on the position and length information of the line segment includes: When it is detected that the number of pixels included in the first line segment or the second line segment is greater than a preset number, the lengths of the first line segment and the second line segment are compared. If the ratio of the length of the first line segment to the length of the second line segment is detected to be greater than a preset value, then it is determined that the pixel segment in which the second line segment is located has the stroke defect; if the ratio of the length of the second line segment to the length of the first line segment is detected to be greater than the preset value, then it is determined that the pixel segment in which the first line segment is located has the stroke defect. When the second judgment point is detected to be the upper neighbor of the first judgment point, the stroke defect is determined to be the stroke floating defect; when the second judgment point is detected to be the lower neighbor of the first judgment point, the stroke defect is determined to be the stroke sinking defect.
3. The method for stroke restoration of text images according to claim 1, characterized in that, The method of obtaining the line segment used to determine the stroke defect further includes: Starting from the first judgment point, record the number of consecutive white dots to obtain the third line segment; When it is detected that the length of the second line segment is equal to that of the third line segment, and a series of non-white dots are detected after the first judgment point, the first non-white dot after the first judgment point is set as the third judgment point, and the number of consecutive non-white dots is recorded starting from the third judgment point to obtain the fourth line segment.
4. The method for stroke restoration of text images according to claim 3, characterized in that, The step of determining the pixel segment with the stroke defect and the corresponding defect type based on the position and length information of the line segment includes: When it is detected that the number of pixels included in the first line segment or the fourth line segment is greater than a preset number, and the ratio of the length of the first line segment or the fourth line segment to the length of the third line segment is greater than a preset value, it is determined that the pixel segment in which the second line segment is located has the stroke defect. When the second judgment point is detected to be the upper neighbor of the first judgment point, the stroke defect is determined to be the stroke floating defect; when the second judgment point is detected to be the lower neighbor of the first judgment point, the stroke defect is determined to be the stroke sinking defect.
5. An electronic device, characterized in that, It includes at least one control processor and a memory for communicatively connecting to at least one of the control processors; the memory stores instructions executable by at least one of the control processors, which, when executed by at least one of the control processors, enable at least one of the control processors to perform the stroke restoration method for text images as described in any one of claims 1 to 4.
6. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions for causing a computer to perform the stroke restoration method for a text image as described in any one of claims 1 to 4.
7. A computer program product, comprising a computer program or computer instructions, characterized in that, The computer program or the computer instructions are stored in a computer-readable storage medium. The processor of the computer device reads the computer program or the computer instructions from the computer-readable storage medium and executes the computer program or the computer instructions, causing the computer device to perform the stroke restoration method for text images as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Chinese character image inpainting method based on strokes
CN102968764A
Inscription restoration method based on contour feature description of Chinese character image
CN105069766A
Character defect detection method, device and equipment
CN110197180A