Ancient book image preprocessing method, computer device and readable storage medium
By slicing and color histogram clustering of ancient books images and determining the processing strategy based on pixel differences between background and text areas, the problem of mathematical symbol recognition problems and the impact of defilement is solved, and efficient pre-processing of ancient books images is achieved.
Patent Information
- Application Number
- CN202410961625.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-18
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2044-07-18
AI Technical Summary
The existing mathematical symbol recognition methods cannot recognize ancient mathematical symbols in ancient books, and the defilement on ancient books increases the difficulty of identification.
By slicing ancient books images, several sub-images are obtained, and then clustering based on the color histogram of the sub-images, sub-image clusters with categories not less than 6 are obtained. The image close to the center of the sub-image cluster is selected as the reference image, and the processing strategy of the sub-image cluster image is determined based on the pixel differences between the background area and the text area in the reference image, and the images in the cluster are processed, and the processed sub-images are finally stitched into pre-processed ancient book images.
Through this method, mathematical symbols in ancient books are easier to be identified, and the image quality after processing is improved, which can better adapt to the characteristics of ancient books and reduce the impact of defilement on recognition.
Smart Images

Figure CN119152513B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to a method for preprocessing ancient book images, a computer device and a readable storage medium. Background Art
[0002] China is an ancient country with a long history and a vast collection of ancient books and documents. These ancient books and documents are the precious spiritual wealth of the Chinese nation, an important source of our history and culture, an important way for the dissemination of Chinese knowledge, and an important part of Chinese culture. Ancient books are the treasures of Chinese civilization and the precious spiritual wealth of the Chinese nation.
[0003] Ancient books on mathematics contain a large number of ancient mathematical symbols. Existing mathematical symbol recognition methods can usually only recognize modern mathematical symbols. Since these ancient mathematical symbols are different from modern mathematical symbols, they cannot be recognized by existing mathematical symbol recognition methods. In addition, due to the influence of the preservation environment, there may be stains on the ancient books, which further increases the difficulty of recognition. Summary of the invention
[0004] At least one aspect or advantage of the invention will be set forth in part in the following description, or may be obvious from the description, or may be learned by practice of the disclosed subject matter.
[0005] According to a first aspect of the present invention, a method for preprocessing an ancient book image comprises:
[0006] Slice the ancient book image to obtain several sub-images;
[0007] Based on the color histogram of the sub-image, clustering is performed on several sub-images according to the color distribution of the color histogram to obtain sub-image clusters with no less than 6 categories;
[0008] Selecting an image close to the center of the sub-image cluster as a reference image of each sub-image cluster, and determining a processing strategy for the sub-image cluster image based on the pixel difference between the background area and the text area in the reference image;
[0009] Processing images within a cluster based on a processing strategy for sub-image cluster images;
[0010] The processed sub-images are spliced together to obtain the pre-processed ancient book image.
[0011] According to an embodiment of the present invention, clustering the plurality of sub-images according to the color distribution of the color histogram comprises:
[0012] In RGB mode, obtain the color histogram of the sub-image in three color channels;
[0013] According to the pixel value intervals of the three channels, the pixel ratio of each pixel interval under the three color channels is obtained;
[0014] Cluster the sub-images based on the pixel proportions of the three color channels;
[0015] The three color channels are a red channel, a green channel and a blue channel.
[0016] According to one embodiment of the present invention, the process of determining the processing strategy of the sub-image cluster image includes:
[0017] Determine the difference value between the text and background pixels based on the difference between the pixels in the text area and the background area;
[0018] In response to the difference value being greater than a threshold value, a pixel distribution area of the text area is obtained based on the text area of the selected reference image; a pixel point in the reference image that is located within the pixel distribution area is obtained, and edge detection is performed based on the pixel distribution area and Fourier transform to obtain the edge of the text image; and the interior of the shape determined by the edge of the text image is filled;
[0019] In response to the difference value being lower than a threshold value, a pixel distribution area of the text area is obtained based on the text area of the selected reference image.
[0020] According to an embodiment of the present invention, the processing strategy further includes: performing histogram equalization processing on the area outside the edge of the text image.
[0021] According to an embodiment of the present invention, the processing strategy further includes: performing histogram equalization processing on the light-colored area outside the edge of the text image;
[0022] The light-colored area is determined based on the average of the grayscale values of the background area, and the grayscale values of the pixels in the light-colored area are higher than the grayscale values of the background area.
[0023] According to an embodiment of the present invention, when the difference value is lower than a threshold, the edge of the pixel distribution area is compressed based on the Douglas-Peucker algorithm, and the inside of the compressed edge is used as a text pixel area.
[0024] According to an embodiment of the present invention, histogram equalization is performed on the colors outside the text image area of the processed adjacent sub-images.
[0025] According to an embodiment of the present invention, histogram equalization is performed on the colors outside the text image area in the processed ancient book image.
[0026] According to a second aspect of the present invention, there is provided a computer device comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the ancient book image preprocessing method as described in the first aspect of the present invention when executing the computer program.
[0027] According to a third aspect of the present invention, there is provided a readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the steps of the method for preprocessing an ancient book image as described in the first aspect of the present invention are implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 It is a flow chart of a method for preprocessing an ancient book image in an embodiment of the present invention. DETAILED DESCRIPTION
[0029] The present disclosure will now be discussed with reference to several exemplary embodiments. It should be understood that these embodiments are discussed only to enable those skilled in the art to better understand and thus implement the present disclosure, rather than implying any limitation on the scope of the present disclosure.
[0030] like Figure 1 As shown, according to an embodiment of the present invention, a method for preprocessing an ancient book image is provided, including steps 1100-1500.
[0031] Step 1100: Slice the ancient book image to obtain a number of sub-images.
[0032] Ancient books refer to books that are relatively old. Ancient book images contain various ancient book characters. You can use a camera to take pictures of ancient books to obtain ancient book images. The ancient book image is segmented according to a preset size to obtain multiple sub-images. The size of each sub-image can be the same size. For example, for an ancient book image with a size of 2000*3000, it is divided into 100 sub-images with a size of 200*300. In order to better recognize the symbols or Chinese characters in one or more ancient book images, the size of the sub-image can be set to not exceed the pixel size of most text or images in the image. For example, when a text is 200*300 pixels in the acquired image, select this size or a smaller size to segment the image.
[0033] Step 1200: Based on the color histogram of the sub-image, cluster the sub-images according to the color distribution of the color histogram to obtain sub-image clusters with no less than 6 categories.
[0034] The color histogram of the sub-image is used to represent the color attributes of the sub-image, including the proportion of different colors in the image. The color histogram can be obtained in different color spaces. For example, a color histogram based on the RGB color space, in which R represents red, G represents green, and B represents blue. For another example, the color histogram can also be a color histogram based on the HSV color space, in which H represents hue, S represents saturation, and V represents brightness.
[0035] After clustering the sub-images, sub-images with similar colors are grouped into one category. There may be damage in the ancient book image, for example, the text in the ancient book image is damaged. The color of the damaged text is quite different from the color of the undamaged text.
[0036] When clustering sub-images, sub-images without contamination are grouped together. In addition, the contamination type or degree will also affect the color of the text. Texts with similar contamination types or degrees will have similar colors. However, for texts with greatly different contamination types or degrees, their colors will also be greatly different. In this embodiment, by dividing the sub-images into at least 6 sub-image clusters, the contamination types or degrees in the sub-images are further distinguished.
[0037] Step 1300: Select an image close to the center of the sub-image cluster as the reference image of each sub-image cluster, and determine the processing strategy of the sub-image cluster image based on the pixel difference between the background area and the text area in the reference image.
[0038] For sub-images in different sub-image clusters, the pixel differences between the background area and the text area are different. In order to facilitate the subsequent recognition of text in the image, the image processing strategy of each sub-image cluster is determined according to the pixel differences between the background area and the text area of the reference image in each sub-image cluster, so that the processing strategy of each sub-image cluster is more targeted. Here, a reference image is selected, and the image is adjusted so that the color distribution of the adjusted image is as close as possible to the color distribution in the reference image, thereby reducing the impact of contamination on image processing and making the final processed image have a similar color distribution.
[0039] Step 1400: Process the images in the cluster based on the processing strategy of the sub-image cluster images.
[0040] The sub-images contained in each sub-image cluster are processed using the processing strategy corresponding to each sub-image cluster.
[0041] Step 1500: splicing the processed sub-images to obtain a pre-processed ancient book image.
[0042] The processed sub-images are spliced according to the positions of the sub-images when the ancient book image is sliced, so as to obtain the pre-processed ancient book image.
[0043] The present invention obtains a plurality of sub-images by segmenting an ancient book image, clusters the sub-images according to a color histogram, distinguishes the types of contamination or the degree of contamination in the sub-images through clustering, and determines the processing strategy corresponding to each sub-image cluster according to the color difference between the background area and the text area. The processing strategy of each sub-image cluster is more targeted, so that the mathematical symbols in the processed ancient book image are easier to be recognized.
[0044] According to one embodiment of the present invention, clustering several sub-images according to the color distribution of the color histogram includes: in RGB mode, obtaining the color histogram of the sub-image under the three-color channels; obtaining the pixel proportion of each pixel interval under the three-color channels according to the three channel pixel value intervals; clustering the sub-images based on the three-color channel pixel proportions; the three-color channels are red channel, green channel and blue channel.
[0045] In RGB mode, the color of each pixel includes three components, namely, red channel component, green channel component, and blue channel component. The color histogram of the sub-image under the three color channels includes the pixel ratio of the sub-image in the color interval under each color channel.
[0046] For example, for a sub-image of size 200*300, it contains 60,000 pixels in total. In the red channel, the pixel values are in the range of 0-255. Among them, the total number of pixels with pixel values in the range of 0-50 pixels is 6,000, the total number of pixels with pixel values in the range of 51-100 pixels is 18,000, the total number of pixels with pixel values in the range of 101-150 pixels is 21,000, the total number of pixels with pixel values in the range of 151-200 pixels is 12,000, and the total number of pixels with pixel values in the range of 201-255 pixels is 3,000. Then the proportion of pixels in the range of 0-50 pixels is 10%, the proportion of pixels in the range of 51-100 pixels is 30%, the proportion of pixels in the range of 101-150 pixels is 35%, the proportion of pixels in the range of 151-200 pixels is 20%, and the proportion of pixels in the range of 201-255 pixels is 5%.
[0047] The sub-images are clustered according to the pixel ratios of the three color channels. The sub-images with similar pixel ratios are grouped into one category.
[0048] According to an embodiment of the present invention, the process of determining the processing strategy of the sub-image cluster image includes steps 1310-1330.
[0049] Step 1310: Determine the difference value between the text and background pixels based on the pixel difference between the text area and the background area.
[0050] The sub-image includes a background area and a text area. The background area is the area corresponding to the ancient book paper, and the text area is the area corresponding to the text written on the ancient book paper. The colors of the background area and the text area are quite different, for example, the background area is yellow and the text area is black.
[0051] Step 1320: In response to the difference value being greater than a threshold value, obtaining a pixel distribution area of the text area based on the text area of the selected reference image; obtaining pixel points in the reference image that are located within the pixel distribution area, performing edge detection based on the pixel distribution area and Fourier transform to obtain the edge of the text image; and filling the interior of the shape determined by the edge of the text image.
[0052] The threshold is set according to the color difference between the background area and the text area in the ancient book image without pollution. If the color difference between the background area and the text area of the sub-image is greater than the threshold, it can be considered that there is pollution in the sub-image.
[0053] The pixel points in the reference image that are located within the pixel distribution area are the pixel points corresponding to the text area in the reference image. When the difference value is greater than the threshold, the edge of the text image is detected based on the pixel distribution and Fourier transform, and the inside of the edge is filled. The pixel value of the filling pixel can be the same as the pixel value of the edge pixel, which is convenient for subsequent text recognition.
[0054] Step 1330: In response to the difference value being lower than a threshold, obtaining a pixel distribution area of the text area based on the text area of the selected reference image.
[0055] According to an embodiment of the present invention, when the difference value is lower than a threshold, the edge of the pixel distribution area is compressed based on the Douglas-Peucker algorithm, and the inside of the compressed edge is used as a text pixel area.
[0056] The Douglas-Peucker algorithm is an algorithm for simplifying curves. It reduces the number of data points by iteratively segmenting line segments that exceed a certain threshold while maintaining the basic shape of the curve. The compressed edge has fewer pixels, which can eliminate some errors introduced by the image processing process, making it easier to recognize text in the image.
[0057] According to an embodiment of the present invention, the processing strategy further includes: performing histogram equalization processing on the area outside the edge of the text image.
[0058] The area outside the edge of the text image is the background area around the text image, and does not contain other text images. After the area outside the edge of the text image is processed by histogram equalization, the contrast between the text image and the surrounding background area is increased, making the text image easier to recognize. This processing process can recolor the defaced area, increase the RGB value of the corresponding pixel, and thus enhance the contrast of the image.
[0059] Histogram equalization is to evenly distribute the number of gray levels in an image. When the histogram of an image is completely evenly distributed, the probability distribution of each gray level is balanced, and the contrast of the image is maximum.
[0060] According to one embodiment of the present invention, the processing strategy also includes: performing histogram equalization processing on the light-colored area outside the edge of the text image; the light-colored area is determined based on the mean of the grayscale values of the background area, and the grayscale values of the pixels in the light-colored area are higher than the grayscale values of the background area.
[0061] The area outside the edge of the text image is the background area outside the text image. The background area includes a dark area and a light area. Compared with the dark area, the light area is closer to white and has a higher pixel value. Correspondingly, the pixel value of the dark area is lower.
[0062] The mean of the grayscale value of the background area is the average of the grayscale values of all pixels in the background area. The light-colored area and the dark-colored area in the background image can be determined by the mean of the grayscale value of the background area. The area with a grayscale value exceeding the mean of the grayscale value of the background area is regarded as a light-colored area, and the area with a grayscale value lower than the mean of the grayscale value of the background area is regarded as a dark-colored area.
[0063] After determining the light-colored area outside the edge of the text image, the light-colored area is subjected to histogram equalization to avoid loss of details due to local over-brightness.
[0064] According to an embodiment of the present invention, the colors outside the text image area of the processed adjacent sub-images are subjected to histogram equalization processing, so that the colors between adjacent texts can be made more uniform and the pixel differences outside the text area can be avoided to be too large.
[0065] According to an embodiment of the present invention, histogram equalization is performed on the colors outside the text image area in the processed ancient book image.
[0066] The area outside the text image area in the ancient book image is the background area of the ancient book image. By performing histogram equalization on the background area of the ancient book image, the contrast of the image is increased, so that the difference between the text area and the background area in the processed ancient book image is more obvious, and the text in the image is easier to recognize.
[0067] According to one embodiment of the present invention, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the ancient book image preprocessing method described in any embodiment of the present invention when executing the computer program.
[0068] According to one embodiment of the present invention, a readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method for preprocessing an ancient book image described in any embodiment of the present invention are implemented.
[0069] Those of ordinary skill in the art will appreciate that the modules and algorithm steps described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0070] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and equipment can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0071] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.
[0072] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the embodiments of the present invention.
[0073] In addition, each functional module in the embodiment of the present invention may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.
[0074] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the energy-saving signal sending / receiving method of each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a ROM, a RAM, a magnetic disk, or an optical disk.
[0075] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the inventive concept. For example, the above features are replaced with (but not limited to) technical features with similar functions disclosed in the present application.
[0076] It should be understood that the size of the sequence number of each step in the content of the invention and the embodiments of the present invention does not absolutely mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention. For the purpose of example and description, the foregoing description of the implementation of the present disclosure has been given. The foregoing description is not exhaustive and is not intended to limit the present disclosure to the exact form disclosed. Various deformations and modifications may exist according to the above teachings, or various deformations and modifications may be obtained from the practice of the present disclosure. These embodiments are selected and described to illustrate the principles of the present disclosure and its practical application, so that those skilled in the art can use the present disclosure in various embodiments and various modifications suitable for the specific purpose conceived.
Claims
1. The preprocessing method of ancient book images is characterized by: include: Slice the ancient book image to obtain several sub-images; Based on the color histogram of the sub-image, clustering is performed on several sub-images according to the color distribution of the color histogram to obtain sub-image clusters with no less than 6 categories; Selecting an image close to the center of the sub-image cluster as a reference image of each sub-image cluster, and determining a processing strategy for the sub-image cluster image based on the pixel difference between the background area and the text area in the reference image; Processing images within a cluster based on a processing strategy for sub-image cluster images; The processed sub-images are spliced together to obtain a pre-processed ancient book image; The process of determining the processing strategy of the sub-image cluster image includes: Determine the difference value between the text and background pixels based on the difference between the pixels in the text area and the background area; In response to the difference value being greater than a threshold value, a pixel distribution area of the text area is obtained based on the text area of the selected reference image; a pixel point in the reference image that is located within the pixel distribution area is obtained, and edge detection is performed based on the pixel distribution area and Fourier transform to obtain the edge of the text image; and the interior of the shape determined by the edge of the text image is filled; In response to the difference value being lower than a threshold, obtaining a pixel distribution area of the text area based on the text area of the selected reference image; The processing strategy also includes: performing histogram equalization processing on the area outside the edge of the text image; The processing strategy also includes: performing histogram equalization processing on the light-colored area outside the edge of the text image; The light-colored area is determined based on the average of the grayscale values of the background area, and the grayscale values of the pixels in the light-colored area are higher than the grayscale values of the background area; When the difference value is lower than the threshold, the edge of the pixel distribution area is compressed based on the Douglas-Peucker algorithm, and the inside of the compressed edge is used as the text pixel area.
2. The method for preprocessing ancient book images according to claim 1, characterized in that: The clustering of the plurality of sub-images according to the color distribution of the color histogram comprises: In RGB mode, obtain the color histogram of the sub-image in three color channels; According to the pixel value intervals of the three channels, the pixel ratio of each pixel interval under the three color channels is obtained; Cluster the sub-images based on the pixel proportions of the three color channels; The three color channels are a red channel, a green channel and a blue channel.
3. The method for preprocessing ancient book images according to claim 1, characterized in that: The processed adjacent sub-images are subjected to histogram equalization processing on the colors outside the text image area.
4. The method for preprocessing ancient book images as claimed in claim 3, characterized in that: The colors outside the text image area in the processed ancient book image are subjected to histogram equalization processing.
5. Computer device, characterized in that The method comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the ancient book image preprocessing method according to any one of claims 1 to 4 when executing the computer program.
6. A readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a processor, the steps of the method for preprocessing an ancient book image according to any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Character recognition method for ancient books with smudginess and omission and ancient book recognition equipment
CN118038467A
System for automated segmentation of images through layout classification
EP2955645A1