CN-121999501-A - Handwriting stroke feature extraction method and system based on fixed-size grids
Abstract
The invention discloses a handwriting stroke feature extraction method and system based on a fixed-size grid. The method relates to the technical field of stroke feature extraction and comprises the following steps of handwriting stroke image preprocessing and grid division, grid-based stroke space distribution feature extraction, size feature extraction, grid-based stroke direction feature extraction, feature fusion and output. The invention normalizes a handwriting stroke binary image to a fixed canvas and divides the fixed canvas into grids through S1, calculates the stroke density of each grid through S2 and constructs a density characteristic vector, refines an image to obtain a framework, calculates a direction field and generates a direction characteristic vector, finally, fuses the two vectors in series and outputs a combined characteristic vector for a subsequent task, thereby improving the accuracy of extracting the handwriting stroke characteristics and solving the problem of low accuracy of extracting the handwriting stroke characteristics in the prior art due to insufficient understanding of the dynamic nature, complex morphology and high-level semantics of the handwriting art.
Inventors
- CHEN YIXIN
- CHEN QUAN
Assignees
- 北京艺心尚品科技有限公司
Dates
- Publication Date
- 20260508
- Application Date
- 20260107
Claims (10)
- 1. The handwriting stroke feature extraction method based on the fixed-size grid is characterized by comprising the following steps of: s1, acquiring a binary image of a handwriting stroke to be processed, and carrying out normalization processing on the image to enable the image to be adapted to a canvas with a preset fixed size; S2, aiming at each rectangular cell divided in the step S1, calculating the ratio of the number of stroke pixels in the cell to the total number of the pixel in the cell as the stroke density characteristic of the cell; S3, carrying out refinement treatment on the handwriting stroke binarization image to obtain a single-pixel width skeleton image of the stroke, aiming at the part of the skeleton image in each rectangular cell, calculating the direction field of the part of skeleton pixel points, wherein the direction field is obtained by calculating the tangential direction of each skeleton pixel point or using a gradient operator; S4, carrying out serial fusion on the stroke space density distribution feature vector obtained in the step S2 and the stroke direction distribution feature vector obtained in the step S3 to form a joint feature vector with a total dimension, and outputting the joint feature vector as a final digital feature expression of the handwriting stroke for subsequent recognition, classification or retrieval tasks.
- 2. The method for extracting handwriting stroke features based on fixed-size grids according to claim 1, wherein in the step S1, the normalizing the image specifically comprises: Calculating a minimum circumscribed rectangle of the handwriting stroke binarization image, and extracting a stroke area surrounded by the minimum circumscribed rectangle; scaling the extracted stroke area image to a preset standard size through a linear interpolation algorithm, wherein the standard size is smaller than the canvas with the fixed size so as to ensure that the stroke main body has a fixed relative proportion in the canvas; placing the stroke image subjected to size normalization in the center position of the canvas with fixed size, specifically calculating the offset of the center point coordinates of the canvas with fixed size and the center point coordinates of the stroke image, and integrally translating all pixel points of the stroke image to enable the two center points to coincide; And uniformly filling the areas, which are not covered by the stroke images, in the canvas with the fixed size into background color values, and normalizing the original stroke images with any size and position to the central area of the canvas with the fixed size.
- 3. The method for extracting handwriting stroke features based on fixed-size grid according to claim 2, wherein in step S1, after the canvas of fixed size is uniformly divided into rectangular cells, the method further comprises the step of performing standardized coding on grid cells: taking the left upper corner of the canvas with the fixed size as an origin (0, 0), taking the horizontal right direction as the positive X-axis direction, and taking the vertical downward direction as the positive Y-axis direction, and establishing a two-dimensional coordinate system; According to the sequence from left to right and from top to bottom, each rectangular cell is assigned a unique position index code (i, j), wherein i is a row index and j is a column index, so that the position of each cell can be uniquely identified and accessed through the index code (i, j); And predefining a feature storage structure in the memory according to the sequence of the position index codes (i, j) for sequentially storing and associating the stroke density features and the direction distribution features calculated by each cell in a subsequent step so as to ensure that the feature vectors keep an alignment relation with the space grid structure.
- 4. The method for extracting the calligraphy stroke features based on the fixed-size grid according to claim 1, wherein the calculating the ratio of the number of stroke pixels in the cell to the total number of pixels in the cell comprises the following specific steps: for a rectangular cell to be calculated currently, traversing each pixel point in the cell in sequence; judging whether the pixel value of the current pixel point is a foreground stroke pixel value according to the definition of the handwriting stroke binarized image, if so, adding 1 to a stroke pixel point counting variable; the total pixel point number of the cells is a fixed value, the pixel value of the width of the canvas with the fixed size is divided by the column number and is rounded downwards to obtain the pixel value of the width of the cells, the pixel value of the height of the canvas with the fixed size is divided by the column number and is rounded downwards to obtain the pixel value of the height of the cells, and the pixel value of the width of the cells is multiplied by the pixel value of the height of the cells to obtain the pixel value of the height of the cells in advance; After the traversing judgment of all the pixel points in the current cell is completed, the obtained final value of the stroke pixel point counting variable and the obtained fixed value of the total pixel point number of the cell are subjected to duty ratio processing to obtain the stroke density characteristic value of the cell.
- 5. The method for extracting handwriting stroke features based on fixed-size grids according to claim 1, wherein the specific steps for forming a stroke space density distribution feature vector are as follows: according to the established cell coordinate coding sequence, namely the sequence of preceding and following columns, the stroke density characteristic value of each rectangular cell with row index i from 0 to M-1 and column index j from 0 to N-1 is sequentially read; Sequentially adding each stroke density characteristic value read in sequence to the tail end of one-dimensional array until all M multiplied by N cells are processed; And carrying out standardization processing on the constructed one-dimensional array, specifically adopting a maximum-minimum normalization method, namely traversing the array to find the maximum value and the minimum value in all density characteristic values, subtracting the minimum value from each value in the array, dividing the minimum value by the difference between the maximum value and the minimum value, mapping the characteristic values into the interval of [0, 1], and finally outputting the standardized M multiplied by N dimension stroke space density distribution characteristic vector.
- 6. The method for extracting the characteristics of the calligraphic strokes based on the fixed-size grids according to claim 1, wherein the specific flow of acquiring the single-pixel-width skeleton image of the strokes is as follows: Inputting a handwriting stroke binarized image which is subjected to normalization processing and placed on the canvas with the fixed size in the step S1; Adopting an iterative morphological refinement algorithm, and repeatedly corroding and operating a stroke foreground region in the binary image by using a group of predefined structural elements; in each iteration, deleting boundary pixel points meeting specific neighborhood configuration conditions, and keeping the topological connectivity and basic form of strokes unchanged; the iterative process is continuously carried out until the stroke area is not changed any more, and finally a single-pixel width skeleton image only retaining the stroke center line is output; And carrying out post-processing on the obtained skeleton image, and removing short branches with the length smaller than a preset threshold value, wherein the short branches are regarded as noise burrs generated in the thinning process so as to obtain smooth and coherent stroke skeleton trunks.
- 7. The method for extracting the characteristic of the calligraphic strokes based on the fixed-size grid according to claim 1, wherein the specific step of calculating the direction field of the part of skeleton pixel points is as follows: For each skeleton pixel point in the current rectangular unit lattice, extracting a neighborhood pixel in a preset window size, respectively convoluting the neighborhood by using a pair of gradient operators in the horizontal direction and the vertical direction, and calculating the gradient component of the pixel point in the horizontal direction and the gradient component in the vertical direction; The calculated gradient components in the horizontal direction and gradient components in the vertical direction calculate the local direction angle of the skeleton pixel point, and uniformly convert the local direction angle into a [0, pi ] interval to eliminate ambiguity in the direction representation, ensure that the horizontal right and horizontal left directions are uniformly represented, for example, and obtain the final tangential direction of the skeleton pixel point.
- 8. The method for extracting the characteristic of the calligraphic strokes based on the fixed-size grid according to claim 1, wherein the specific steps for obtaining the directional distribution characteristic of the cell are as follows: Uniformly dividing the angle range of [0, pi) into K direction intervals, wherein the angle span of each direction interval is pi/K, the angle range of the kth direction interval is [ (K-1) pi/K, K pi/K), and the value range of K is 1 to K; Traversing all framework pixel points in the current rectangular unit grid, classifying the current rectangular unit grid into a corresponding one of the K direction intervals according to the obtained direction angle of each pixel point; And carrying out L1 norm normalization on the original histogram vector, namely dividing the number of the pixels in each interval by the total number of all skeleton pixels in the cell to obtain a group of K-dimensional probability distribution vectors with the sum of 1 as the final direction distribution characteristic of the cell.
- 9. The method for extracting the characteristic of the calligraphic strokes based on the fixed-size grid according to claim 1, wherein the specific steps of performing series fusion are as follows: The method comprises the steps of pre-distributing a continuous one-dimensional array space in a memory according to the total dimension, copying all elements of the M multiplied by N dimension stroke space density distribution feature vector to the first M multiplied by N positions of the pre-distributed one-dimensional array space according to the inherent sequence of the elements, and copying all elements of the (M multiplied by N multiplied by K) dimension stroke direction distribution feature vector to the rest positions of the one-dimensional array space according to the inherent sequence of the elements, so that the head and tail sequential series connection of two vectors is completed.
- 10. A system for applying the fixed-size grid-based handwriting stroke feature extraction method according to any one of claims 1-9, comprising a handwriting stroke image preprocessing and grid dividing module, a grid-based stroke spatial distribution feature extraction module, a grid-based stroke direction feature extraction module and a feature fusion and output module; The handwriting stroke image preprocessing and grid dividing module is used for acquiring a handwriting stroke binarization image to be processed, normalizing the image to enable the image to be adapted to a preset canvas with fixed size; The grid-based stroke space distribution feature extraction module is used for calculating the ratio of the number of stroke pixels in each rectangular cell divided in the step S1 to the total number of the pixel points in each cell to be used as the stroke density feature of the cell; The grid-based stroke direction feature extraction module is used for carrying out refinement treatment on the handwriting stroke binarization image to obtain a single-pixel width skeleton image of the stroke, calculating a direction field of a part of skeleton pixel points aiming at the part of the skeleton image in each rectangular cell, wherein the direction field is obtained by calculating the tangential direction of each skeleton pixel point or using a gradient operator; The feature fusion and output module is used for carrying out serial fusion on the stroke space density distribution feature vector obtained in the step S2 and the stroke direction distribution feature vector obtained in the step S3 to form a joint feature vector with a total dimension, and the joint feature vector is used as a final digital feature expression of the handwriting stroke and is output for subsequent recognition, classification or retrieval tasks.
Description
Handwriting stroke feature extraction method and system based on fixed-size grids Technical Field The invention relates to the technical field of stroke feature extraction, in particular to a handwriting stroke feature extraction method and system based on fixed-size grids. Background Firstly, preprocessing and stroke segmentation are carried out, after high-definition scanning or dynamic writing track data are obtained, graying, binarization and median filtering are adopted to eliminate noise points, and the comparison of strokes and the background is enhanced through a self-adaptive threshold algorithm. For static copybooks, a skeleton refinement algorithm is often used to extract a center line of single pixel width, and for dynamic data (such as a digital pen track), a time sequence coordinate point is directly acquired. In static images, segmentation is typically performed at skeleton intersections depending on the topology of the strokes, or continuous strokes are directly identified and separated using a semantic segmentation model (e.g., U-Net) based on convolutional neural networks. And then entering a key point detection and parameterization modeling stage, and positioning key points such as pen starting, pen receiving, turning and the like on the segmented stroke skeleton according to a curvature extreme point or inflection point detection algorithm (such as a chord length-based method). The common method includes fitting the stroke center line by Bezier curve or B-spline curve to control point parameters to describe its smooth form, or modeling by contour line segment to decompose the stroke edge into basic geometric units such as straight line and arc line. This step converts the simulated strokes into a set of geometrically significant parameters. Then, multi-level feature vector construction is carried out, features are required to be combined from different dimensions, including stroke length, aspect ratio, direction histogram, curvature (cumulative rotation angle and chord length ratio) and the like, texture directivity of strokes (starting and receiving modes) is extracted through a Gabor filter bank, or fluctuation complexity of the contours is calculated to reflect wither and fly-white effects, speed and acceleration curves are extracted from writing tracks, and the lifting force changes, and the features are particularly sensitive to distinguishing personal styles, and relative positions, crossing angles, gravity center distribution and the like among strokes are calculated. Finally, in the feature selection and dimension reduction stage, the initially generated feature vector is high in dimension and redundant, the dimension reduction is carried out by adopting methods such as principal component analysis or linear discriminant analysis, the information with the most discriminant is reserved, and algorithms such as recursive feature elimination can be applied to screen the optimal feature subset according to the requirements of the subsequent classification task. A Chinese handwriting data construction method based on stroke extraction and stroke parameterization is disclosed in Chinese patent application with bulletin number of CN120356224B, and comprises the steps of obtaining a target handwriting character image, preprocessing an input target handwriting character image to obtain a preprocessed image, extracting stroke characteristics of the preprocessed image through a stroke extraction model, extracting stroke characteristics with single stroke with high precision to obtain a high-precision single stroke, labeling the single stroke, inputting a series of single strokes with label labeling into a stroke parameterization model to generate track data, and storing the generated track data as structured data according to a preset format. A multi-level depth feature fusion stroke extraction method disclosed in the Chinese patent application with the bulletin number of CN116994255B comprises the steps of obtaining a Chinese character image, constructing a Chinese character stroke segmentation data set, carrying out stroke marking on strokes on the Chinese character image, taking a stroke mask, a stroke length and a rectangular frame of the stroke mask as label information, constructing a stroke segmentation model, wherein the stroke segmentation model comprises a Chinese character image preprocessing module, a global feature extraction network, a main visual feature extraction network, a time sequence feature extraction network and a spatial feature extraction network, training and testing the stroke segmentation model, and inputting the Chinese character image to be detected into the stroke segmentation model to obtain a stroke segmentation extraction result. However, in the process of implementing the technical scheme of the embodiment of the application, the application discovers that the above technology has at least the following technical problems: In the prior art, firstly, there a