Method, system, device and medium for obtaining foreground contour and watermark of text
By performing grayscale conversion, histogram statistics, edge extraction and fusion processing on handwritten text images, the foreground outline diagram of the text image is obtained and a watermark diagram is generated, which solves the problem of lack of effective handwritten text foreground outline extraction and watermark diagram generation in the prior art, and achieves more accurate and reliable text outline extraction and watermark diagram generation.
Patent Information
- Application Number
- CN202211585584.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-09
- Publication Date
- 2025-04-08
- Estimated Expiration
- 2042-12-09
AI Technical Summary
The prior art lacks effective methods for extracting foreground contours and generating watermark images by handwritten text.
By converting the original text image to be processed into a grayscale image, histogram statistics and binary segmentation are performed, the edge gradient results are obtained, and the binary image and edge gradient results are fused to obtain the foreground outline of the text image. Then, set the pixel transparency without the outline in the foreground outline diagram to transparent to obtain the watermark image.
It realizes more accurate text outline extraction and watermark image generation, improves the accuracy of image segmentation and edge extraction, and ensures the accuracy and reliability of watermark images.
Smart Images

Figure CN118172377B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and specifically provides a method, system, device and medium for obtaining a foreground contour and a watermark image of a text. Background Art
[0002] Currently, existing commercially available mobile phones lack a method for extracting the foreground contour of handwritten text and a method for generating a watermark image.
[0003] Accordingly, the art needs a new solution for extracting foreground contours of handwritten texts and obtaining watermark images to solve the above problems. Summary of the invention
[0004] In order to overcome the above-mentioned defects, the present invention is proposed to provide a solution or at least partially solve the problem of how to obtain the foreground contour and watermark image of a text image based on the text image.
[0005] In a first aspect, the present invention provides a method for obtaining a foreground contour of a text, the method comprising:
[0006] Convert the original text image to be processed into a grayscale image;
[0007] Performing histogram statistics on the grayscale image, and performing binary segmentation on the grayscale image according to the histogram statistics result to obtain a binary image of the grayscale image;
[0008] Performing edge extraction on the grayscale image to obtain an edge gradient result of the grayscale image;
[0009] According to the edge gradient result and the binary image, a foreground contour image of the text image is obtained.
[0010] In a technical solution of the method for obtaining the foreground contour of the above text, the step of "performing histogram statistics on the grayscale image, and performing binary segmentation on the grayscale image according to the histogram statistics result to obtain a binary image of the grayscale image" includes:
[0011] Performing filtering preprocessing on the grayscale image to obtain a preprocessing result image;
[0012] Performing histogram statistics on the preprocessing result image to obtain a histogram of the preprocessing result image; wherein the histogram counts the number of each grayscale value in the preprocessing result image;
[0013] Obtaining an image segmentation threshold according to a peak value of the histogram;
[0014] The grayscale image is segmented according to the image segmentation threshold to obtain the binary image.
[0015] In a technical solution of the method for obtaining the foreground contour of the text, the peak value includes a maximum peak value and a secondary peak value, and the step of "obtaining an image segmentation threshold value according to the peak value of the histogram" includes:
[0016] Obtaining the maximum peak value of the histogram and the grayscale value corresponding to the maximum peak value;
[0017] According to the maximum peak value, obtaining the secondary peak value of the histogram and the grayscale value corresponding to the secondary peak value;
[0018] The image segmentation threshold is obtained according to the maximum peak value, the sub-peak value and the grayscale values corresponding to each of them.
[0019] In a technical solution of the method for obtaining the foreground contour of the text, the step of "obtaining the image segmentation threshold according to the maximum peak value, the secondary peak value and the grayscale values corresponding to each of them" includes:
[0020] Determine whether the difference between the grayscale value corresponding to the maximum peak value and the grayscale value corresponding to the secondary peak value is greater than a preset grayscale threshold;
[0021] If yes, obtaining the image segmentation threshold according to the median of the maximum peak value and the secondary peak value;
[0022] If not, the image segmentation threshold is obtained according to the following formula:
[0023] Thr = H max –bias
[0024] Wherein, Thre is the image segmentation threshold, H max is the maximum peak value, and bias is the preset bias value.
[0025] In a technical solution of the method for obtaining the foreground contour of the above text, the step of "obtaining the secondary peak value of the histogram and the grayscale value corresponding to the secondary peak value according to the maximum peak value" includes obtaining the secondary peak value according to the following formula:
[0026] H max2 =max[(xH max ) 2 *I hist (x)]
[0027] Among them, H max2 is the secondary peak value, x is the grayscale value of the histogram, and its value range is [0, 255], H max is the maximum peak value, I hist (x) is the number of each gray value.
[0028] In a technical solution of the method for obtaining the foreground contour of the above text, the step of "pre-processing the grayscale image by filtering to obtain the pre-processing result image" includes:
[0029] The grayscale image is filtered and preprocessed by Gaussian filtering or median filtering to obtain the preprocessing result image.
[0030] In a technical solution of the method for obtaining the foreground contour of the above text, the step of "extracting the edge of the grayscale image to obtain the edge gradient result of the grayscale image" includes:
[0031] Applying the Schaar operator to extract edges in the horizontal and vertical directions of the grayscale image respectively;
[0032] The extracted horizontal edges and vertical edges are weighted to obtain edge gradient results.
[0033] In a technical solution of the above-mentioned method for obtaining the foreground contour of the text, the step of "obtaining the foreground contour map of the text image according to the edge gradient result and the binary image" includes:
[0034] For each pixel, comparing the edge gradient result with the brightness value of the pixel in the binary image;
[0035] The brightness value of the pixel with high brightness value is used as the brightness value of the corresponding pixel in the foreground contour image to obtain the foreground contour image of the text image.
[0036] In a second aspect, the present invention provides a method for obtaining a watermark image of a text, the method comprising:
[0037] Acquire a foreground contour map of the text, wherein the foreground contour map is acquired according to the foreground contour acquisition method of the text described in any one of the technical solutions of the foreground contour acquisition method of the text;
[0038] The transparency of pixels without contours in the foreground contour image of the text is set to transparent to obtain a watermark image of the text.
[0039] In a third aspect, a system for acquiring a foreground contour of a text is provided, the system comprising:
[0040] A grayscale image conversion module, configured to convert the original text image to be processed into a grayscale image;
[0041] A binary image acquisition module is configured to perform histogram statistics on the grayscale image, and perform binary segmentation on the grayscale image according to the histogram statistics result to obtain a binary image of the grayscale image;
[0042] An edge gradient result acquisition module, configured to perform edge extraction on the grayscale image to obtain an edge gradient result of the grayscale image;
[0043] A foreground contour map acquisition module is configured to obtain a foreground contour map of the text image according to the edge gradient result and the binary image.
[0044] In a fourth aspect, a system for obtaining a watermark image of a text is provided, the system comprising:
[0045] A foreground contour image acquisition module, which is configured to acquire a foreground contour image of the text, wherein the foreground contour image is acquired according to the text foreground contour acquisition system described in the technical solution of the text foreground contour acquisition system;
[0046] The text watermark image acquisition module is configured to set the transparency of pixels without contours in the foreground contour image of the text to be transparent, so as to acquire the watermark image of the text.
[0047] In a fifth aspect, a control device is provided, which includes a processor and a storage device, wherein the storage device is suitable for storing multiple program codes, and the program codes are suitable for being loaded and run by the processor to execute the method for acquiring the foreground contour of the text described in any one of the technical solutions of the above-mentioned method for acquiring the foreground contour of the text or the method for acquiring the watermark image of the text described in any one of the technical solutions of the above-mentioned method for acquiring the watermark image of the text.
[0048] In a sixth aspect, a computer-readable storage medium is provided, wherein a plurality of program codes are stored therein, and the program codes are suitable for being loaded and run by a processor to execute the method for obtaining the foreground contour of a text as described in any one of the technical solutions of the method for obtaining the foreground contour of the text or the method for obtaining the watermark image of a text as described in any one of the technical solutions of the method for obtaining the watermark image of the text.
[0049] The above one or more technical solutions of the present invention have at least one or more of the following
[0050] Beneficial effects:
[0051] In the technical solution of the present invention, the present invention converts the original text image to be processed into a grayscale image, and performs histogram statistics and edge extraction on the grayscale image, thereby obtaining a binary image and edge gradient result of the grayscale image, fuses the binary image and the edge gradient, and obtains a watermark image based on the foreground contour map. Through the above configuration, the present invention performs image segmentation based on the statistical histogram to obtain a binary image, which can make the segmentation result more accurate; at the same time, the edge extraction of the grayscale image can make the edge gradient result more accurately reflect the edge contour; the foreground contour map obtained based on the edge gradient result and the fusion of the binary image can more accurately extract the text contour, and further obtain the watermark image.
[0052] Solution 1. A method for obtaining a foreground contour of a text, characterized in that the method comprises:
[0053] Convert the original text image to be processed into a grayscale image;
[0054] Performing histogram statistics on the grayscale image, and performing binary segmentation on the grayscale image according to the histogram statistics result to obtain a binary image of the grayscale image;
[0055] Performing edge extraction on the grayscale image to obtain an edge gradient result of the grayscale image;
[0056] A foreground contour image of the text image is obtained according to the edge gradient result and the binary image.
[0057] Solution 2. The method for obtaining the foreground contour of a text according to Solution 1 is characterized in that the step of "performing histogram statistics on the grayscale image, and performing binary segmentation on the grayscale image according to the histogram statistics result to obtain a binary image of the grayscale image" comprises:
[0058] Performing filtering preprocessing on the grayscale image to obtain a preprocessing result image;
[0059] Performing histogram statistics on the preprocessing result image to obtain a histogram of the preprocessing result image; wherein the histogram counts the number of each grayscale value in the preprocessing result image;
[0060] Obtaining an image segmentation threshold according to a peak value of the histogram;
[0061] The grayscale image is segmented according to the image segmentation threshold to obtain the binary image.
[0062] Solution 3. The method for obtaining the foreground contour of a text according to Solution 2 is characterized in that the peak value includes a maximum peak value and a secondary peak value, and the step of "obtaining an image segmentation threshold value according to the peak value of the histogram" includes:
[0063] Obtaining the maximum peak value of the histogram and the grayscale value corresponding to the maximum peak value;
[0064] According to the maximum peak value, obtaining the secondary peak value of the histogram and the grayscale value corresponding to the secondary peak value;
[0065] The image segmentation threshold is obtained according to the maximum peak value, the sub-peak value and the grayscale values corresponding to each of them.
[0066] Solution 4. The method for obtaining the foreground contour of a text according to Solution 3 is characterized in that the step of "obtaining the image segmentation threshold according to the maximum peak value, the secondary peak value and the grayscale values corresponding to each of them" comprises:
[0067] Determine whether the difference between the grayscale value corresponding to the maximum peak value and the grayscale value corresponding to the secondary peak value is greater than a preset grayscale threshold;
[0068] If yes, obtaining the image segmentation threshold according to the median of the maximum peak value and the secondary peak value;
[0069] If not, the image segmentation threshold is obtained according to the following formula:
[0070] Thr = H max –bias
[0071] Wherein, Thre is the image segmentation threshold, H max is the maximum peak value, and bias is the preset bias value.
[0072] Solution 5. The method for obtaining the foreground contour of a text according to Solution 3 is characterized in that the step of "obtaining the secondary peak value of the histogram and the grayscale value corresponding to the secondary peak value according to the maximum peak value" includes obtaining the secondary peak value according to the following formula:
[0073] H max2 =max[(xH max ) 2 *I hist (x)]
[0074] Among them, H max2 is the secondary peak value, x is the grayscale value of the histogram, and its value range is [0, 255], H max is the maximum peak value, I hist (x) is the number of each gray value.
[0075] Solution 6. The method for obtaining the foreground contour of a text according to any one of Solutions 2 to 5 is characterized in that the step of "pre-processing the grayscale image by filtering to obtain a pre-processing result image" comprises:
[0076] The grayscale image is filtered and preprocessed by Gaussian filtering or median filtering to obtain the preprocessing result image.
[0077] Solution 7. The method for obtaining the foreground contour of a text according to Solution 1 is characterized in that the step of "extracting the edge of the grayscale image to obtain the edge gradient result of the grayscale image" comprises:
[0078] Applying the Schaar operator to extract edges in the horizontal and vertical directions of the grayscale image respectively;
[0079] The extracted horizontal edges and vertical edges are weighted to obtain edge gradient results.
[0080] Solution 8. The method for obtaining the foreground contour of a text according to Solution 1 is characterized in that the step of "obtaining a foreground contour map of the text image according to the edge gradient result and the binary image" comprises:
[0081] For each pixel, comparing the edge gradient result with the brightness value of the pixel in the binary image;
[0082] The brightness value of the pixel with high brightness value is used as the brightness value of the corresponding pixel in the foreground contour image to obtain the foreground contour image of the text image.
[0083] Solution 9. A method for obtaining a watermark image of a text, characterized in that the method comprises:
[0084] Acquire a foreground contour map of the text, wherein the foreground contour map is acquired according to the method for acquiring a foreground contour of a text described in any one of Schemes 1 to 8;
[0085] The transparency of pixels without contours in the foreground contour image of the text is set to transparent to obtain a watermark image of the text.
[0086] Solution 10. A system for acquiring a foreground contour of a text, characterized in that the system comprises:
[0087] A grayscale image conversion module, configured to convert the original text image to be processed into a grayscale image;
[0088] A binary image acquisition module is configured to perform histogram statistics on the grayscale image, and perform binary segmentation on the grayscale image according to the histogram statistics result to obtain a binary image of the grayscale image;
[0089] An edge gradient result acquisition module, configured to perform edge extraction on the grayscale image to obtain an edge gradient result of the grayscale image;
[0090] A foreground contour map acquisition module is configured to obtain a foreground contour map of the text image according to the edge gradient result and the binary image.
[0091] Solution 11. A text watermark acquisition system, characterized in that the system comprises:
[0092] A foreground contour image acquisition module, configured to acquire a foreground contour image of the text, wherein the foreground contour image is acquired by the text foreground contour acquisition system according to Solution 10;
[0093] The text watermark image acquisition module is configured to set the transparency of pixels without contours in the foreground contour image of the text to be transparent, so as to acquire the watermark image of the text.
[0094] Scheme 12. A control device, comprising a processor and a storage device, wherein the storage device is suitable for storing multiple program codes, and is characterized in that the program codes are suitable for being loaded and run by the processor to execute the foreground contour acquisition method of the text described in any one of Schemes 1 to 8 or the watermark image acquisition method of the text described in Scheme 9.
[0095] Scheme 13. A computer-readable storage medium storing a plurality of program codes, characterized in that the program codes are suitable for being loaded and run by a processor to execute the foreground contour acquisition method of a text described in any one of Schemes 1 to 8 or the watermark image acquisition method of a text described in Scheme 9. BRIEF DESCRIPTION OF THE DRAWINGS
[0096] The disclosure of the present invention will become more easily understood with reference to the accompanying drawings. It is easy for those skilled in the art to understand that these drawings are only for illustrative purposes and are not intended to limit the scope of protection of the present invention. Among them:
[0097] Figure 1 is a schematic flow chart of main steps of a method for obtaining a foreground contour of a text according to an embodiment of the present invention;
[0098] Figure 2 1 is a schematic flow chart of the main steps of a method for obtaining a watermark image of a text according to an embodiment of the present invention.
[0099] Figure 3 is a schematic diagram of comparison between an original text image, a grayscale image, and a preprocessing result image according to an example of an embodiment of the present invention;
[0100] Figure 4 is a schematic diagram of a histogram statistical result according to an example of an embodiment of the present invention;
[0101] Figure 5 is a schematic diagram of comparison between a grayscale image and a binary image according to an example of an embodiment of the present invention;
[0102] Figure 6 is a schematic diagram of Schaar's convolution kernel according to an implementation of an embodiment of the present invention;
[0103] Figure 7 is a schematic diagram comparing edges in the horizontal and vertical directions and edge gradient results obtained by applying the Schaar operator according to an example of an embodiment of the present invention;
[0104] Figure 8 is a schematic diagram for comparing a binary image, an edge gradient result, and a foreground contour image according to an example of an embodiment of the present invention;
[0105] Fig. 9 is a schematic diagram of comparison between a foreground contour image and a watermark image according to an example of an embodiment of the present invention;
[0106] Fig.10 It is a schematic flow chart of the main steps of a method for obtaining a watermark image of a text according to an implementation of an embodiment of the present invention;
[0107] Fig.11 is a main structural block diagram of a system for acquiring a foreground contour of a text according to an embodiment of the present invention;
[0108] Fig.12 It is a main structural block diagram of a text watermark acquisition system according to an embodiment of the present invention. DETAILED DESCRIPTION
[0109] Some embodiments of the present invention are described below with reference to the accompanying drawings. It should be understood by those skilled in the art that these embodiments are only used to explain the technical principles of the present invention and are not intended to limit the protection scope of the present invention.
[0110] In the description of the present invention, "module" and "processor" may include hardware, software or a combination of the two. A module may include hardware circuits, various suitable sensors, communication ports, and memories, and may also include software parts, such as program codes, or a combination of software and hardware. The processor may be a central processing unit, a microprocessor, an image processor, a digital signal processor, or any other suitable processor. The processor has data and / or signal processing functions. The processor may be implemented in software, hardware, or a combination of the two. Non-temporary computer-readable storage media include any suitable medium that can store program codes, such as a magnetic disk, a hard disk, an optical disk, a flash memory, a read-only memory, a random access memory, and the like. The term "A and / or B" means all possible combinations of A and B, such as only A, only B, or A and B. The term "at least one A or B" or "at least one of A and B" has a similar meaning to "A and / or B", and may include only A, only B, or A and B. The singular terms "one" and "the" may also include plural forms.
[0111] See attached Figure 1 , Figure 1 FIG. 1 is a flow chart showing the main steps of a method for obtaining a foreground contour of a text according to an embodiment of the present invention. Figure 1 As shown, the method for obtaining the foreground contour of text in the embodiment of the present invention mainly includes the following steps S101 to S104.
[0112] Step S101: converting the original text image to be processed into a grayscale image.
[0113] In this embodiment, the original text image to be processed may be converted into a grayscale image.
[0114] In one implementation, the original text image may be a photo of handwritten text. The camera may be started, the document watermark mode may be entered, and a shooting key may be clicked to trigger a photo, thereby obtaining a photo of the handwritten text as the original text image.
[0115] Step S102: performing histogram statistics on the grayscale image, and performing binary segmentation on the grayscale image according to the histogram statistics result to obtain a binary image of the grayscale image.
[0116] In this embodiment, the grayscale image can be subjected to histogram statistics, and the grayscale image can be binary segmented according to the histogram statistics result, so as to obtain a binary image. A binary image refers to an image in which each pixel has only two possible values or grayscale levels. People often use black and white, B&W (Black&White), and monochrome images to represent binary images.
[0117] In one implementation, the histogram may count the number of each grayscale value in the image.
[0118] Step S103: extracting the edge of the grayscale image to obtain the edge gradient result of the grayscale image.
[0119] In this embodiment, edge extraction can be performed on the grayscale image to obtain the edge gradient result of the grayscale image. The edge is the boundary between different regions and is a collection of pixels with significant changes in surrounding (local) pixels; the edge gradient has a direction and is always orthogonal (perpendicular) to the direction of the edge.
[0120] In one implementation, the edge of the grayscale image may be detected using commonly used edge detection operators, such as Roberts, Sobel, Prewitt, Laplacian, Log / Marr, Canny, Kirsch, Nevitia, and the like.
[0121] Step S104: fusing the edge gradient result with the binary image to obtain a foreground contour map of the text image.
[0122] In this embodiment, the foreground contour image of the text image can be obtained according to the edge gradient result and the binary image.
[0123] In one implementation, a superposition operation may be performed based on the edge gradient result and the value of each pixel of the binary image to obtain a foreground contour map of the text image.
[0124] In one implementation, after the watermark image is acquired, the relevant information may be updated and the current shooting may be terminated.
[0125] Based on the above steps S101 to S104, the embodiment of the present invention converts the original text image to be processed into a grayscale image, and performs histogram statistics and edge extraction on the grayscale image, thereby obtaining a binary image and edge gradient result of the grayscale image, and fuses the binary image and the edge gradient to obtain a foreground contour map of the text image, and obtains a watermark image based on the foreground contour map. Through the above configuration, the embodiment of the present invention performs image segmentation based on the statistical histogram to obtain a binary image, which can make the segmentation result more accurate; at the same time, the edge extraction of the grayscale image can make the edge gradient result more accurately reflect the edge contour; the foreground contour map obtained based on the edge gradient result and the fusion of the binary image can more accurately extract the text contour to further obtain the watermark image.
[0126] Step S102, step S103 and step S104 are further described below.
[0127] In one implementation of the embodiment of the present invention, step S102 may further include the following steps S1021 to S1024:
[0128] Step S1021: Perform filtering preprocessing on the grayscale image to obtain a preprocessing result image.
[0129] In this embodiment, the grayscale image can be pre-processed by filtering to effectively filter out the noise in the grayscale image to obtain a pre-processed result image. Figure 3 , Figure 3 It is a schematic diagram of comparison among an original text image, a grayscale image and a preprocessing result image according to an example of an embodiment of the present invention. Figure 3 The left side is the original text image, the middle side is the grayscale image, and the right side is the preprocessing result image.
[0130] In one implementation, the grayscale image may be pre-processed by applying Gaussian filtering or median filtering.
[0131] Step S1022: performing histogram statistics on the preprocessing result image to obtain a histogram of the preprocessing result image.
[0132] In this embodiment, the preprocessing result image can be subjected to histogram statistics, and the number of each gray value in the preprocessing result image can be counted to obtain a histogram. Figure 4 , Figure 4 1 is a schematic diagram of a histogram statistical result of an example according to an embodiment of the present invention. The figure shows the statistical result of the histogram, wherein the horizontal axis is the gray value and the vertical axis is the number of gray values.
[0133] Step S1023: Obtain the image segmentation threshold according to the peak value of the histogram.
[0134] In this embodiment, the peak value may include a maximum peak value and a secondary peak value, and step S1023 may further include steps S10231 to S10233:
[0135] Step S10231: Obtain the maximum peak value of the histogram and the grayscale value corresponding to the maximum peak value.
[0136] In this implementation, the maximum peak value of the histogram and the grayscale value corresponding to the maximum peak value may be acquired according to the histogram.
[0137] Step S10232: According to the maximum peak value, obtain the secondary peak value of the histogram and the grayscale value corresponding to the secondary peak value.
[0138] In this embodiment, the secondary peak value can be obtained according to the following formula (1):
[0139] Hmax2 =max[(xH max ) 2 ×I hist (x)]. (1)
[0140] Among them, H max2 is the secondary peak value, x is the grayscale value of the histogram, the value range is [0, 255], Hmax is the maximum peak value, I hist (x) is the number of grayscale values x.
[0141] Step S10233: Obtain the image segmentation threshold according to the maximum peak value, the sub-peak value and their corresponding grayscale values.
[0142] In this implementation, step S10233 may include the following steps S102331 to S102333:
[0143] Step S102331: Determine whether the difference between the grayscale value corresponding to the maximum peak and the grayscale value corresponding to the secondary peak is greater than a preset grayscale threshold; if so, jump to step S102332; if not, jump to step S102333.
[0144] In this embodiment, the difference between the grayscale values corresponding to the maximum peak value and the secondary peak value can be compared with a preset grayscale threshold. Those skilled in the art can set the grayscale threshold value according to the needs of actual applications.
[0145] Step S102332: Obtain the image segmentation threshold according to the median of the maximum peak and the secondary peak.
[0146] In this embodiment, if the difference between the gray values is greater than the gray threshold, it can be considered that there are at least two peaks in the histogram, and the median of the maximum peak and the secondary peak can be taken as the image segmentation threshold, as shown in the following formula (2):
[0147] Thr = (H max +H max2 ) / twenty two)
[0148] Among them, Thre is the image segmentation threshold, H max is the maximum peak value, H max2 is the sub-peak value.
[0149] Step S102333: Obtain the image segmentation threshold according to the following formula (3):
[0150] Thr = H max –bias (3)
[0151] Among them, bias is the preset bias value.
[0152] In this embodiment, if the difference between the gray values is less than or equal to the gray threshold, it means that the distance between the maximum peak and the secondary peak is very close, and it can be considered that the histogram has only one peak, and a value on the left side of the maximum peak can be taken as the image segmentation threshold. Those skilled in the art can set the value of the bias value according to the needs of the actual application.
[0153] In one implementation, the offset value may be a value between 5 and 20.
[0154] Step S1024: performing image segmentation on the grayscale image according to the image segmentation threshold to obtain a binary image.
[0155] In this embodiment, the grayscale image can be segmented according to the image segmentation method to obtain a binary image. Specifically, the binary image can be obtained according to the following formula (4):
[0156]
[0157] Where f(x) is the grayscale value of pixel x in the binary image, I gray (x) is the grayscale value of pixel x in the grayscale image.
[0158] Please refer to the attached Figure 5 , Figure 5 3 is a schematic diagram of comparing a grayscale image and a binary image according to an example of an embodiment of the present invention. Figure 5 The left side is a grayscale image and the right side is a binary image.
[0159] In one implementation of the embodiment of the present invention, step S103 may further include the following steps S1031 and S1032:
[0160] Step S1031: Apply the Schaar operator to extract edges in the horizontal and vertical directions of the grayscale image.
[0161] In this embodiment, the Schaar operator is applied to better reflect the details of edge extraction. Figure 6 , Figure 6 FIG. 1 is a schematic diagram of Schaar's convolution kernel according to an implementation of an embodiment of the present invention. Figure 6 The convolution kernel on the left side of the image is used to extract the horizontal edge, denoted as Schaar_x; it can be applied Figure 6 The convolution kernel on the right side of the image is used to extract the vertical edge, which is denoted as Schaar_y.
[0162] Step S1032: performing weighted calculation on the extracted horizontal edges and vertical edges to obtain edge gradient results.
[0163] In this embodiment, the extracted horizontal edges and vertical edges may be weighted to obtain edge gradient results. Specifically, the edge gradient results may be obtained according to the following formula (5):
[0164] Schaar_xy=Schaar_x*wight_x+Schaar_y*wight_y(5)
[0165] Among them, Schaar_xy is the edge gradient result, wight_x and wight_y are the weights of Schaar_x and Schaar_y respectively.
[0166] Please refer to the attached Figure 7 , Figure 7 It is a schematic diagram comparing the edges in the horizontal and vertical directions and the edge gradient results obtained by applying the Schaar operator according to an example of an embodiment of the present invention. Figure 7 The left side is the horizontal edge, the middle is the vertical edge, and the right side is the edge gradient result.
[0167] In one implementation of the embodiment of the present invention, step S104 may further include the following steps S1041 and S1042:
[0168] Step S1041: for each pixel, compare the edge gradient result with the brightness value of the pixel in the binary image.
[0169] Step S1042: Using the brightness value of the pixel with high brightness value as the brightness value of the corresponding pixel in the foreground contour image to obtain the foreground contour image of the text image.
[0170] In this embodiment, the edge gradient result and the brightness value of each pixel in the binary image may be compared, and the brightness value of the pixel with high brightness is taken as the final result.
[0171] In one implementation, step S104 may be implemented according to the following program segment:
[0172] for(int i=0; i <H;++i)
[0173] for(int j = 0; j <W;++j)
[0174] {
[0175] Iout[i,j]=max(Schaar_xy[i,j],Ithre[i,j]);
[0176] }
[0177] Among them, H is the image height, W is the image width, and Iout[i,j] is the foreground contour map.
[0178] Please refer to the attached Figure 8 , Figure 8 The figure is a schematic diagram for comparing a binary image, an edge gradient result and a foreground contour image according to an example of an embodiment of the present invention. Figure 8 The left side is a binary image, the middle is the edge gradient result, and the right side is the foreground contour image.
[0179] Furthermore, the present invention also provides a method for obtaining a watermark image of a text.
[0180] See attached Figure 2 , Figure 2 FIG. 1 is a flow chart showing the main steps of a method for obtaining a watermark image of a text according to an embodiment of the present invention. Figure 2 As shown, the method for obtaining the foreground contour of text in the embodiment of the present invention mainly includes the following steps S201 to S202.
[0181] Step S201: obtaining a foreground contour map of the text, wherein the foreground contour map is obtained according to an embodiment of the method for obtaining the foreground contour of the text.
[0182] Step S202: setting the transparency of pixels without contours in the foreground contour image of the text to transparent, so as to obtain a watermark image of the text.
[0183] In one implementation, the watermark image of the text can be obtained by the following program segment:
[0184] uint_8* idst = new [w*h*4];
[0185] memset(Idst,0,sizeof(uint_8)*W*H*4);
[0186] for(int i=0; i <H;++i)
[0187] for(int j = 0; j <W;++j)
[0188] {
[0189] int t = 4*i*W+j;
[0190] Idst[t+0]=Iout[i,j]; Idst[t+1]=Iout[i,j];
[0191] Idst[t+2]=Iout[i,j]; Idst[t+3]=Iout[i,j];
[0192] }
[0193] Among them, Idst[i,j] is the watermark image.
[0194] Please refer to the attached Fig. 9 , Fig. 9 4 is a schematic diagram of the comparison between a foreground contour image and a watermark image according to an example of an embodiment of the present invention. Fig. 9 The comparison between the foreground contour image and the watermark image is shown in FIG.
[0195] In one embodiment, please refer to the attached Fig.10 , Fig.10 FIG. 1 is a flow chart showing the main steps of a method for obtaining a watermark image of a text according to an implementation of an embodiment of the present invention. Fig.10 As shown, the method for obtaining a watermark image of a text may include the following steps S301 to S316:
[0196] Step S301: Start the camera and enter the watermark mode.
[0197] Step S302: Click the capture button to trigger a photo taking.
[0198] In this embodiment, the camera can be started to enter the watermark mode to take a photo of the handwritten text.
[0199] Step S303: Acquire the currently captured original text image.
[0200] Step S304: converting the original text image into a grayscale image, performing filtering preprocessing on the grayscale image, and obtaining a preprocessing result image;
[0201] In this embodiment, the method described in step S304 is similar to the method described in the aforementioned step S1021, and for the sake of simplicity, it will not be repeated here.
[0202] Step S305: Perform histogram statistics on the pre-processed image to obtain a histogram.
[0203] In this embodiment, the method described in step S305 is similar to the method described in the aforementioned step S1022, and for the sake of simplicity, it will not be repeated here.
[0204] Step S306: Find the maximum peak value of the histogram and its corresponding grayscale value; find the secondary peak value of the histogram and its corresponding grayscale value.
[0205] In this embodiment, the method described in step S306 is similar to the method described in the aforementioned steps S10231 and S10232, and will not be repeated here for the sake of simplicity.
[0206] Step S307: Calculate the difference between the grayscale values corresponding to the maximum peak value and the secondary peak value.
[0207] Step S308: Determine whether the difference is greater than the grayscale threshold; if so, jump to step S309; if not, jump to step S310.
[0208] In this embodiment, the methods described in step S307 and step S308 are similar to the method described in the aforementioned step S102331, and for the sake of simplicity, they are not repeated here.
[0209] Step S309: If there are multiple peaks in the histogram, the median of the maximum peak and the secondary peak is taken as the image segmentation threshold, and then jump to step S311.
[0210] In this embodiment, the method described in step S309 is similar to the method described in the aforementioned step S10232, and for the sake of simplicity, it will not be repeated here.
[0211] Step S310: If the histogram has only one peak, the left side of the maximum peak is taken as the image segmentation threshold, and then jump to step S311.
[0212] In this embodiment, the method described in step S310 is similar to the method described in the aforementioned step S10233, and for the sake of simplicity, it will not be repeated here.
[0213] Step S311: performing threshold segmentation on the grayscale image according to the image segmentation threshold to obtain a binary image.
[0214] In this embodiment, the method described in step S311 is similar to the method described in the aforementioned step S1024, and for the sake of simplicity, it will not be repeated here.
[0215] Step S312: Perform Schaar edge extraction on the grayscale image in the horizontal and vertical directions, denoted as Schaar_x and Schaar_y.
[0216] In this embodiment, the method described in step S312 is similar to the method described in the aforementioned step S1031, and for the sake of simplicity, it will not be repeated here.
[0217] Step S313: Perform weighted mixing on Schaar_x and Schaar_y to obtain the edge gradient result Schaar_xy.
[0218] In this embodiment, the method described in step S313 is similar to the method described in the aforementioned step S1032, and for the sake of simplicity, it will not be repeated here.
[0219] Step S314: Fusing the binary image and the edge gradient result to obtain a foreground contour image of the text.
[0220] In this embodiment, the method described in step S314 is similar to the method described in the aforementioned step S104, and for the sake of simplicity, it will not be repeated here.
[0221] Step S315: Generate a watermark image based on the foreground contour image.
[0222] In this embodiment, the method described in step S315 is similar to the method described in the aforementioned step S202, and for the sake of simplicity, it will not be repeated here.
[0223] Step S316: Update relevant information and end the current shooting.
[0224] It should be pointed out that although the various steps in the above embodiments are described in a specific order, those skilled in the art can understand that in order to achieve the effects of the present invention, different steps do not have to be performed in such an order. They can be performed simultaneously (in parallel) or in other orders. These changes are within the scope of protection of the present invention.
[0225] Furthermore, the present invention also provides a system for acquiring a foreground contour of a text.
[0226] See attached Fig.11 , Fig.11 FIG. 1 is a main structural block diagram of a text foreground contour acquisition system according to an embodiment of the present invention. Fig.11 As shown, the foreground contour acquisition system of the text in the embodiment of the present invention may include a grayscale image conversion module, a binary image acquisition module, an edge gradient result acquisition module and a foreground contour map acquisition module. In this embodiment, the grayscale image conversion module can be configured to convert the original text image to be processed into a grayscale image. The binary image acquisition module can be configured to perform histogram statistics on the grayscale image, and perform binary segmentation on the grayscale image according to the histogram statistics result to obtain a binary image of the grayscale image. The edge gradient result acquisition module can be configured to perform edge extraction on the grayscale image to obtain the edge gradient result of the grayscale image. The foreground contour map acquisition module can be configured to obtain the foreground contour map of the text image according to the edge gradient result and the binary image.
[0227] The foreground contour of the above text is obtained by the system for performing Figure 1 The embodiment of the method for acquiring the foreground contour of the text shown in the figure has similar technical principles, technical problems solved and technical effects produced. Technical personnel in this technical field can clearly understand that for the convenience and conciseness of description, the specific working process and related instructions of the text foreground contour acquisition system can refer to the contents described in the embodiment of the method for acquiring the foreground contour of the text, which will not be repeated here.
[0228] Furthermore, the present invention also provides a system for obtaining a watermark image of a text.
[0229] See attached Fig.12 , Fig.12 FIG. 1 is a main structural block diagram of a text watermark acquisition system according to an embodiment of the present invention. Fig.12 As shown, the watermark image acquisition system of the text in the embodiment of the present invention may include a foreground contour image acquisition module and a text watermark image acquisition module. In this embodiment, the foreground contour image acquisition module may be configured to acquire a foreground contour image of the text, wherein the foreground contour image is acquired according to the foreground contour acquisition system of the text in the embodiment of the foreground contour acquisition system of the text. The text watermark image acquisition module may be configured to set the transparency of the pixels without contours in the foreground contour image of the text to transparent, so as to acquire the watermark image of the text.
[0230] The watermark image acquisition system of the above text is used to perform Figure 2 The technical principles, technical problems solved and technical effects produced of the text watermark acquisition method embodiment shown in the two are similar. Technical personnel in this technical field can clearly understand that for the convenience and conciseness of description, the specific working process and related instructions of the text watermark acquisition system can refer to the contents described in the embodiment of the text watermark acquisition method, which will not be repeated here.
[0231] It is understood by those skilled in the art that the present invention implements all or part of the processes in the method of the above embodiment, and can also be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable storage medium may include: any entity or device, medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory, random access memory, electric carrier signal, telecommunication signal and software distribution medium that can carry the computer program code. It should be noted that the content contained in the computer-readable storage medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable storage media do not include electric carrier signals and telecommunication signals.
[0232] Furthermore, the present invention also provides a control device. In an embodiment of the control device according to the present invention, the control device includes a processor and a storage device, the storage device can be configured to store a program for executing the method for obtaining the foreground contour of the text of the above method embodiment, and the processor can be configured to execute the program in the storage device, which includes but is not limited to the program for executing the method for obtaining the foreground contour of the text of the above method embodiment. For ease of explanation, only the parts related to the embodiment of the present invention are shown. For specific technical details not disclosed, please refer to the method part of the embodiment of the present invention. The control device can be a control device device formed by various electronic devices.
[0233] Furthermore, the present invention also provides a computer-readable storage medium. In a computer-readable storage medium embodiment according to the present invention, the computer-readable storage medium can be configured to store a program for executing the method for obtaining the foreground contour of the text of the above-mentioned method embodiment, and the program can be loaded and run by the processor to implement the above-mentioned method for obtaining the foreground contour of the text. For ease of explanation, only the parts related to the embodiment of the present invention are shown. For specific technical details not disclosed, please refer to the method part of the embodiment of the present invention. The computer-readable storage medium can be a storage device formed by various electronic devices. Optionally, the computer-readable storage medium in the embodiment of the present invention is a non-temporary computer-readable storage medium.
[0234] Furthermore, the present invention also provides a control device. In an embodiment of a control device according to the present invention, the control device includes a processor and a storage device, the storage device can be configured to store a program for executing the watermark image acquisition method of the text of the above method embodiment, and the processor can be configured to execute the program in the storage device, which includes but is not limited to the program for executing the watermark image acquisition method of the text of the above method embodiment. For ease of explanation, only the parts related to the embodiment of the present invention are shown. For specific technical details not disclosed, please refer to the method part of the embodiment of the present invention. The control device can be a control device device formed by various electronic devices.
[0235] Furthermore, the present invention also provides a computer-readable storage medium. In a computer-readable storage medium embodiment according to the present invention, the computer-readable storage medium can be configured to store a program for executing the watermark image acquisition method of the text of the above method embodiment, and the program can be loaded and run by the processor to implement the watermark image acquisition method of the above text. For ease of explanation, only the parts related to the embodiment of the present invention are shown. For specific technical details not disclosed, please refer to the method part of the embodiment of the present invention. The computer-readable storage medium can be a storage device formed by various electronic devices. Optionally, the computer-readable storage medium in the embodiment of the present invention is a non-temporary computer-readable storage medium.
[0236] Further, it should be understood that since the setting of each module is only for illustrating the functional units of the device of the present invention, the physical devices corresponding to these modules may be the processor itself, or a part of the software in the processor, a part of the hardware, or a part of the combination of software and hardware. Therefore, the number of each module in the figure is only schematic.
[0237] Those skilled in the art will appreciate that the modules in the device can be adaptively split or merged. Such splitting or merging of specific modules will not cause the technical solution to deviate from the principle of the present invention, and therefore, the technical solutions after splitting or merging will fall within the protection scope of the present invention.
[0238] So far, the technical solutions of the present invention have been described in conjunction with the preferred embodiments shown in the accompanying drawings. However, it is easy for those skilled in the art to understand that the protection scope of the present invention is obviously not limited to these specific embodiments. Without departing from the principle of the present invention, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after these changes or substitutions will fall within the protection scope of the present invention.
Claims
1. A method for obtaining a foreground contour of a text, characterized in that: The method comprises: Convert the original text image to be processed into a grayscale image; Performing histogram statistics on the grayscale image to obtain a histogram; the histogram counts the number of each grayscale value in the grayscale image; Obtaining the maximum peak value of the histogram and the grayscale value corresponding to the maximum peak value; According to the maximum peak value, obtaining the secondary peak value of the histogram and the grayscale value corresponding to the secondary peak value; Determine whether the difference between the grayscale value corresponding to the maximum peak value and the grayscale value corresponding to the secondary peak value is greater than a preset grayscale threshold; If yes, obtaining an image segmentation threshold according to the median of the maximum peak value and the secondary peak value; If not, the image segmentation threshold is obtained according to the following formula: Thre=H max –bias Wherein, Thre is the image segmentation threshold, H max is the maximum peak value, bias is the preset bias value; Performing image segmentation on the grayscale image according to the image segmentation threshold to obtain a binary image of the grayscale image; Performing edge extraction on the grayscale image to obtain an edge gradient result of the grayscale image; A foreground contour image of the text image is obtained according to the edge gradient result and the binary image.
2. The method for obtaining the foreground contour of a text according to claim 1, characterized in that: The step of "performing histogram statistics on the grayscale image to obtain a histogram" includes: Performing filtering preprocessing on the grayscale image to obtain a preprocessing result image; Performing histogram statistics on the preprocessing result image to obtain a histogram of the preprocessing result image; wherein the histogram is obtained by performing statistics on the number of each grayscale value in the preprocessing result image.
3. The method for obtaining the foreground contour of a text according to claim 1, characterized in that: The step of "obtaining the secondary peak value of the histogram and the grayscale value corresponding to the secondary peak value according to the maximum peak value" includes obtaining the secondary peak value according to the following formula: H max2 =max[(x-H max ) 2 *I hist (x)] Among them, H max2 is the secondary peak value, x is the grayscale value of the histogram, and its value range is [0, 255], H max is the maximum peak value, I his( (x) is the number of each gray value.
4. The method for obtaining the foreground contour of a text according to any one of claims 2 to 3, characterized in that: The step of "performing filtering preprocessing on the grayscale image to obtain a preprocessing result image" includes: The grayscale image is filtered and preprocessed by Gaussian filtering or median filtering to obtain the preprocessing result image.
5. The method for obtaining the foreground contour of a text according to claim 1, characterized in that: The step of "extracting the edge of the grayscale image to obtain the edge gradient result of the grayscale image" includes: Applying the Schaar operator to extract edges in the horizontal and vertical directions of the grayscale image respectively; The extracted horizontal edges and vertical edges are weighted to obtain edge gradient results.
6. The method for obtaining the foreground contour of a text according to claim 1, characterized in that: The step of "obtaining a foreground contour map of the text image according to the edge gradient result and the binary image" comprises: For each pixel, comparing the edge gradient result with the brightness value of the pixel in the binary image; The brightness value of the pixel with high brightness value is used as the brightness value of the corresponding pixel in the foreground contour image to obtain the foreground contour image of the text image.
7. A method for obtaining a watermark image of a text, characterized in that: The method comprises: Acquire a foreground contour image of the text, wherein the foreground contour image is acquired according to the method for acquiring a foreground contour of a text according to any one of claims 1 to 6; The transparency of pixels without contours in the foreground contour image of the text is set to transparent to obtain a watermark image of the text.
8. A text foreground contour acquisition system, characterized in that: The system comprises: A grayscale image conversion module, configured to convert the original text image to be processed into a grayscale image; The binary image acquisition module is configured to perform histogram statistics on the grayscale image to obtain a histogram; the histogram counts the number of each grayscale value in the grayscale image; obtains the maximum peak of the histogram and the grayscale value corresponding to the maximum peak; according to the maximum peak, obtains the secondary peak of the histogram and the grayscale value corresponding to the secondary peak; determines whether the difference between the grayscale value corresponding to the maximum peak and the grayscale value corresponding to the secondary peak is greater than a preset grayscale threshold; if so, obtains an image segmentation threshold according to the median of the maximum peak and the secondary peak; if not, obtains the image segmentation threshold according to the following formula: Thre=H max –bias Wherein, Thre is the image segmentation threshold, H max is the maximum peak value, and bias is a preset bias value; performing image segmentation on the grayscale image according to the image segmentation threshold to obtain a binary image of the grayscale image; An edge gradient result acquisition module, configured to perform edge extraction on the grayscale image to obtain an edge gradient result of the grayscale image; A foreground contour map acquisition module is configured to obtain a foreground contour map of the text image according to the edge gradient result and the binary image.
9. A text watermark acquisition system, characterized in that: The system comprises: a foreground contour image acquisition module, configured to acquire a foreground contour image of the text, wherein the foreground contour image is acquired according to the foreground contour acquisition system of the text according to claim 8; The text watermark image acquisition module is configured to set the transparency of pixels without contours in the foreground contour image of the text to be transparent, so as to acquire the watermark image of the text.
10. A control device, comprising a processor and a storage device, wherein the storage device is suitable for storing a plurality of program codes, characterized in that: The program code is suitable for being loaded and run by the processor to execute the method for acquiring the foreground contour of text according to any one of claims 1 to 6 or the method for acquiring the watermark image of text according to claim 7.
11. A computer-readable storage medium storing a plurality of program codes, characterized in that: The program code is suitable for being loaded and run by a processor to execute the method for acquiring a foreground contour of a text according to any one of claims 1 to 6 or the method for acquiring a watermark image of a text according to claim 7.
Citation Information
Patent Citations
Character image processing method and device
CN107609558A
Cited By
Method for acquiring foreground contour of text, method for acquiring watermark image, system, apparatus and medium
EP4632675A1