Zoomed image restoration method, device, computer equipment and storage medium
By calculating the aspect ratio of a single character area and performing a preset recovery strategy, the problem of difficulty in automatically restoring scaled images in the existing technology is solved, the scaled image is quickly and accurately restored, and the aesthetics of the image and the quality of the text are improved. Legibility.
Patent Information
- Application Number
- CN202011302935.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-19
- Publication Date
- 2024-09-06
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
It is difficult with existing technology to automatically restore a scaled image with text to its original proportions. Especially in web design, after the image is stretched horizontally or vertically, it is difficult for the machine to accurately restore it to the original image.
By obtaining the single character area in the image to be processed, calculating its aspect ratio, and restoring the image based on the preset recovery strategy, dividing the image into sub-images, traversing the pixels to locate the single character area, and calculating the length and width of the text rectangular area ratio, get the compressed aspect ratio, and then restore it to the original ratio.
It achieves fast and accurate restoration of scaled images, and is suitable for scenes where text and images are compressed horizontally or vertically, improving the beauty of images and the legibility of text.
Smart Images

Figure CN112419183B
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a method, device, computer equipment and storage medium for restoring a scaled image. Background Art
[0002] In web design, many images are directly scaled when uploaded to the website because they do not meet the specifications. The images become different in aspect ratio from the original size, which reduces the image quality and seriously reduces the aesthetics. Especially for images with text, the compression is more obvious and the text readability is worse. It is easy to tell whether a compressed image is stretched horizontally or vertically with the naked eye, and it is also easy to drag and drop it back to the original proportion. However, it is still difficult to restore the image to its original proportion through automatic machine. At present, the Baidu AI open platform is known to restore the proportion of stretched images. For example, in the case of the hot air balloon, it is still thinner than the original image after restoration. The main reason is the lack of a reference system, so it is difficult for the machine to directly restore it to the original image. Summary of the invention
[0003] Based on this, in response to the above technical problems, the present application provides a method, device, computer equipment and storage medium for restoring a scaled image to solve the technical problem in the prior art that stretched images with text are difficult to restore.
[0004] A method for restoring a zoomed image, the method comprising:
[0005] Acquire an image to be processed, wherein the image to be processed includes at least one preset text;
[0006] Dividing the image to be processed into multiple sub-images according to a preset division strategy;
[0007] Traversing the pixel points of each sub-image to obtain at least one single-character region, wherein the single-character region is the position of a single preset word on the sub-image;
[0008] Obtaining the text rectangular area of each single character area, calculating the first aspect ratio of each of the text rectangular areas, and calculating the compressed aspect ratio based on a preset length strategy and the first aspect ratio;
[0009] The image to be processed is restored according to the compression aspect ratio based on a preset restoration strategy to obtain a restored image.
[0010] A zoom image restoration device, the device comprising:
[0011] An acquisition module, used for acquiring an image to be processed, wherein the image to be processed includes at least one preset text;
[0012] A division module, used for dividing the image to be processed into a plurality of sub-images according to a preset division strategy;
[0013] A traversal module, used for traversing the pixel points of each sub-image to obtain at least one single-character area, wherein the single-character area is the position of a single preset word on the sub-image;
[0014] A ratio module, used for obtaining the text rectangular area of each single character area, calculating the first aspect ratio of each text rectangular area, and calculating the compressed aspect ratio based on a preset length strategy and the first aspect ratio;
[0015] The restoration module is used to restore the image to be processed according to the compression aspect ratio based on a preset restoration strategy to obtain a restored image.
[0016] A computer device comprises a memory and a processor, and computer-readable instructions stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned zoom image restoration method when executing the computer-readable instructions.
[0017] A computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the above-mentioned zoom image restoration method are implemented.
[0018] The above-mentioned scaled image restoration method, device, computer equipment and storage medium obtain the aspect ratio of the single character area traced by the image to be processed as the compression aspect ratio, and then restore the image to be processed to its original proportion according to the compression aspect ratio to obtain a restored image. This image restoration method is suitable for scenarios where text and images are compressed horizontally or vertically together. The single character area can be quickly located through existing algorithms or models, and then the aspect ratio of the single character area can be obtained to achieve rapid proportional restoration of the compressed image. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0020] Figure 1 A schematic diagram of an application environment of the zoom image restoration method;
[0021] Figure 2 A flowchart of a zoom image restoration method is shown;
[0022] Figure 3 for Figure 2 Schematic diagram of the process of step 202;
[0023] Figure 4 A schematic diagram of dividing the image to be processed;
[0024] Figure 5 for Figure 4 Schematic diagram of the text area in the local image;
[0025] Figure 6 is a schematic diagram of a zoom image restoration device;
[0026] Figure 7 FIG. 1 is a schematic diagram of a computer device in one embodiment. DETAILED DESCRIPTION
[0027] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0028] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0029] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0030] The zoom image restoration method provided by the embodiment of the present invention can be applied to Figure 1 In the application environment shown, the application environment may include a terminal 102, a network and a server 104, the network is used to provide a communication link medium between the terminal 102 and the server 104, and the network may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0031] The user can use the terminal 102 to interact with the server 104 through the network to receive or send messages, etc. Various communication client applications can be installed on the terminal 102, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0032] Terminal 102 can be various electronic devices with a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III, Moving Picture Experts Group Audio Layer 3), MP4 (Moving Picture Experts Group Audio Layer IV, Moving Picture Experts Group Audio Layer 4) players, laptop computers and desktop computers, etc.
[0033] The server 104 may be a server that provides various services, such as a background server that provides support for web pages displayed on the terminal 102 .
[0034] It should be noted that the zoomed image restoration method provided in the embodiment of the present application is generally executed by a server / terminal, and accordingly, the zoomed image restoration device is generally disposed in a server / terminal device.
[0035] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0036] It should be understood that Figure 1 The number of terminals, networks and servers in the embodiment is only for illustration. Any number of terminals, networks and servers may be provided according to the implementation requirements.
[0037] The terminal 102 communicates with the server 104 through a network. The server 104 receives the image to be processed sent by the terminal 102, and divides it into multiple sub-images according to a preset division strategy, then traverses the pixel points of each sub-image to obtain at least one single-character area, obtains the text rectangular area of each single-character area, and calculates its first aspect ratio, obtains the compressed aspect ratio according to the first aspect ratio, and finally restores the image to be processed according to the compressed aspect ratio based on the preset recovery strategy, and sends the restored image back to the terminal 102 after obtaining it. The terminal 102 and the server 104 are connected through a network, which can be a wired network or a wireless network. The terminal 102 can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers and portable wearable devices. The server 104 can be implemented with an independent server or a server cluster composed of multiple servers.
[0038] In one embodiment, Figure 2 As shown, a scaling image restoration method is provided, which is applied to Figure 1 The server in the example is used as an example to illustrate, including the following steps:
[0039] Step 202: Acquire an image to be processed, wherein the image to be processed includes at least one preset text.
[0040] The image to be processed is an image with text, wherein the text generally refers to Chinese characters, Korean characters, Japanese characters, etc. with a standard aspect ratio of 1:1 or other specific sizes of square characters. Because after the original image is uploaded to the web page, when it is compressed by the web page, all images on the image will be compressed at the same ratio, but it is difficult for the computer to obtain the compression ratio of the web page to the image, which makes it difficult to restore the image.
[0041] Step 204: divide the image to be processed into a plurality of sub-images according to a preset division strategy.
[0042] The preset ratio is generally set according to the size of the text on the image. For example, Chinese characters on posters are generally larger, and the area occupied by a single character is 1 / 30-1 / 20 of the entire poster area. The area occupied by a single character on pictures such as flyers and notices will be smaller. Therefore, the preset ratio of image division can be set according to the type of image to be processed to prevent the image to be processed from being divided too small, resulting in a single character being divided into different sub-images due to too small a granularity; or to prevent the segmentation granularity from being too large, resulting in excessive pixel traversal processing and low computational efficiency when subsequently recognizing the text area of each sub-image.
[0043] Specifically, the image type of the image to be processed is obtained; a preset ratio for dividing the image to be processed is set based on the image type; and the image to be processed is divided into a plurality of sub-images according to the preset ratio. The image type of the image to be processed, such as a poster or an ordinary photo, is obtained from an image database, and then a preset ratio for dividing the image to be processed is set according to the image type.
[0044] In this embodiment, a preset ratio of 1 / 96 can be selected to divide the image to be processed into multiple sub-images of the same size, such as Figure 3 As shown, Figure 3 A partial enlarged view of Figure 4 It can be seen that when the image to be processed is cut according to a randomly set ratio, some single characters in the malicious text area on the image will be divided into different sub-images, but most of the adjacent single characters are located in the same sub-image. Therefore, when traversing the text area, only the sub-images adjacent to the sub-image where the text area is located can be traversed, which can save the data processing amount on the server and improve the efficiency of image restoration.
[0045] Step 206, traverse the pixel points of each of the sub-images to obtain at least one single-character region, wherein the single-character region is the position of a single preset text on the sub-image.
[0046] The purpose of traversing the pixels of each sub-image is to extract the pixel value of each pixel, and then determine the background area in each sub-image based on the pixel value. For example, the area corresponding to the color with the largest proportion or the top few proportions is the background area; then calculate the pixel ratio between the colors, and determine the area to be detected based on the pixel ratio. Among them, the pixel ratio is calculated to determine which colors the text may be and which is the color of the background area. Generally, the color with a larger proportion is the background color, and the color with a smaller proportion is the text color. Then you can traverse the area corresponding to the color with a smaller proportion, determine the text area, and perform segmentation processing. This can greatly reduce the amount of data processing on the server side and improve the efficiency of image restoration. Specifically:
[0047] Traversing the pixel points of each of the sub-images, and calculating the pixel ratio according to the pixel values of the pixel points;
[0048] Determine at least one character area to be determined according to the pixel ratio; binarize the sub-images where the character areas to be determined are located, and locate the text coordinates from the binarized sub-images; based on the text coordinates, obtain a single line of text or a single column of text through a proximity search algorithm, and perform text segmentation on the single line of text or the single column of text to obtain the single character area.
[0049] In this embodiment, connected region search can be performed on sub - graphs, and each obtained connected region is regarded as a Chinese character. This is applicable to most Chinese characters, but not to some relatively simple Chinese characters, such as "小 (xiǎo)", "旦 (dàn)", "八 (bā)", "元 (yuán)", "朋 (péng)", "川 (chuān)". Since they do not have connectivity, they are split. Therefore, we need to use the adjacent search algorithm to integrate the regions that may form characters to obtain a single - line text region.
[0050] The purpose of the adjacent search algorithm is to perform dilation, which can "glue" the regions that form Chinese characters. If dilation is performed without search, then dilation occurs in all directions simultaneously, and it is possible to glue different Chinese characters in the left - right columns or up - down rows. Therefore, only dilation in a single direction is allowed. In this embodiment, the direction of dilation is determined by searching adjacent regions, which can be one of up, down, left, or right. Among them, starting from a connected region, the adjacent search algorithm can find the horizontal circumscribed rectangle of the connected region and expand the connected region to the entire rectangle. When the distance between this region and the nearest region is less than a certain range, the dilation of this rectangle is considered, and the direction of dilation is the direction where the nearest region is located. For example, at least one connected region is determined according to the text coordinates, where the connected region is a text region composed of foreground pixel points with the same pixel value and adjacent positions in the image to be processed; the horizontal circumscribed rectangle of the connected region is obtained, and the connected region is expanded to the entire horizontal circumscribed rectangle to obtain an expanded connected region; when the distance between the expanded connected region and the nearest connected region is less than the preset distance, a dilation operation is performed in the direction where the nearest connected region is located to obtain a single - line text or a single - column text.
[0051] Furthermore, when performing search and dilation through the adjacent search algorithm, the distance of dilation in a certain direction needs to be considered. Taking the adjacent search of horizontal text as an example in this embodiment, as Figure 5 shown:
[0052] A rectangular region can be determined by the coordinates (x, y) of the upper - left corner and the coordinates (z, w) of the lower - right corner of region S. Here, the text coordinates are calculated with the upper - left corner coordinate as the origin. Then the center s of region S s is formula (1):
[0053]
[0054] For Figure 5 the two regions S and S' in, the difference vector of their centers (x c , y c ) can be expressed by formula (2):
[0055]
[0056] But if you use directly It is unreasonable to use to represent the distance between two adjacent regions, because the proximity here should be calculated based on the boundary, not the center point. Therefore, it is necessary to subtract the length of the region to obtain the boundary vector difference (x c ′,y c ′):
[0057]
[0058] The distance is defined as formula (4):
[0059]
[0060] As for the direction, it can be judged by the argument, where the argument is the modulus and the argument of the complex number are two basic elements of the complex triangle form. The vector length corresponding to the complex number is called the amplitude of the complex number, and the angle between the vector and the positive direction of the real axis is the argument of the complex number. However, according to the previous "neighborhood search" algorithm, it is easy to glue the upper and lower lines of text together. Therefore, based on our horizontal typesetting assumption, a better way to deal with it is to allow only horizontal expansion. With the distance, we can calculate the distance between each two connected areas and then find the nearest area. We expand each area by one-quarter in the direction of its nearest area, so that the adjacent areas may merge into a new area, thereby integrating the fragments. Experiments show that the idea of neighboring search in this embodiment can effectively integrate text fragments. In this way, it is possible to avoid dividing a left-right or upper-lower structure of Chinese characters, Japanese or Korean into two parts as much as possible. Furthermore, in order to obtain more accurate values later, the present embodiment can also obtain adjacent connected areas of the same size as the text rectangular area, continue to obtain single-line text or single-column text through the proximity search algorithm, and evenly cut the single-line text according to the width or the length of the single-column text to obtain a single-character area. This uniform cutting is generally implemented according to a model, for example, through opencv image morphological transformation or a fully convolutional network, wherein image morphology includes several basic operations: corrosion, expansion, opening operation, and closing operation.
[0061] Step 208 , obtaining the text rectangular area of each single character area, calculating the first aspect ratio of each text rectangular area, and calculating the compressed aspect ratio based on the predicted aspect strategy and the first aspect ratio.
[0062] Because the same single character can be divided into different sub-images, after obtaining multiple single-character areas, in order to ensure that the obtained compressed aspect ratio is more accurate in the current scene, after obtaining the single-character area. Calculate the regional frequency of text rectangular areas with the same first aspect ratio, wherein the regional frequency is the frequency of text areas with the same first aspect ratio appearing in all text rectangular areas; use the first aspect ratio corresponding to the regional frequency greater than the preset frequency as the compressed aspect ratio. Because after cutting a single character, the cut character may not be a complete character, or the character itself may be incomplete or non-standard. In this case, it may cause the final compressed aspect ratio to be significantly different from the aspect ratio of the actual image, so it is necessary to obtain the first aspect ratio of each single-character area in the image, that is, calculate the first aspect ratio of the text rectangular area of each single-character area, and calculate the regional frequency of the text rectangular area with the same first aspect ratio, and use the first aspect ratio corresponding to the text rectangular area whose regional frequency exceeds the preset frequency as the compressed aspect ratio. In some embodiments, the preset frequency is 60%; because there are more than one such compression aspect ratios, when there are multiple compression aspect ratios, the image is restored according to each compression aspect ratio to obtain multiple restored images of different degrees; or, the average of multiple compression aspect ratios is calculated, the average compression aspect ratio is taken, and the image is restored based on the preset recovery strategy. Alternatively, the regional frequencies of the text rectangular areas corresponding to the same first aspect ratio are sorted, and the first aspect ratio corresponding to the largest text rectangular area is used as the compression aspect ratio we need.
[0063] Because no matter under what circumstances, when dividing the image to be processed at a preset ratio, the case where the same Chinese character is divided into different sub-images or the case of irregular characters is a minority case, and the single-character area obtained by the proximity search algorithm may be half a Chinese character, so its aspect ratio is inconsistent with the aspect ratio of normal Chinese characters. Because this type of Chinese characters divided into different sub-images is a minority, and the text rectangular areas of the single-character areas obtained after the division are also different, then the number of text rectangular areas of the entire single-character area alone or the number of text rectangular areas with the same regular text accounts for the majority of all text rectangular areas. Preferably, in some embodiments, the area frequency of the text area rectangles with the same first aspect ratio can be calculated on the basis of the first aspect ratio, and they are sorted in order from high to low, and then the first aspect ratio corresponding to the area frequency ranked first is used as the compression aspect ratio. In this way, irregular Chinese characters or Chinese characters that are cut into pieces are removed, and finally complete Chinese characters are obtained, which greatly improves the accuracy of compressed image ratio restoration.
[0064] Step 210: restore the image to be processed according to the compression aspect ratio based on a preset restoration strategy to obtain a restored image.
[0065] Obtain a fixed aspect ratio of the text rectangular area, and calculate the compression ratio of the image to be processed based on the fixed aspect ratio and the compression aspect ratio; restore the image to be processed based on the compression ratio to obtain the restored image. Generally, the fixed aspect ratio of the text rectangular area will be set according to Chinese characters, Japanese or Korean, and is generally set to 1:1. If the compression aspect ratio is set to M:N, the size of M and N is determined. If M>N, the image to be processed is compressed horizontally. Because the ratio of the compressed image to the image before compression is the compression ratio of the image, this embodiment can obtain the compression ratio of the image to be processed based on the calculated compression aspect ratio and the fixed aspect ratio. Then restore the image to be processed according to the compression ratio.
[0066] In the above-mentioned scaled image restoration method, the aspect ratio of the single character area traced by the image to be processed is obtained as the compression aspect ratio, and then the image to be processed is restored to its original proportion according to the compression aspect ratio to obtain a restored image. This image restoration method is suitable for scenarios where text and images are compressed horizontally or vertically together. The single character area can be quickly located through existing algorithms or models, and then the aspect ratio of the single character area can be obtained to achieve rapid restoration of the compressed image.
[0067] It should be understood that although Figure 2 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 2 At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages do not necessarily have to be executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages does not have to be sequentially, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.
[0068] In one embodiment, Figure 6 As shown, a zoomed image restoration device is provided, and the zoomed image restoration device corresponds to the zoomed image restoration method in the above embodiment. The zoomed image restoration device includes:
[0069] An acquisition module 602 is used to acquire an image to be processed, wherein the image to be processed includes at least one preset text;
[0070] A division module 604 is used to divide the image to be processed into multiple sub-images according to a preset division strategy;
[0071] A traversal module 606, configured to traverse the pixel points of each sub-image to obtain at least one single-character region, wherein the single-character region is a position of a single preset word on the sub-image;
[0072] A ratio module 608 is used to obtain a text rectangular area of each single character area, calculate a first aspect ratio of each text rectangular area, and calculate a compressed aspect ratio based on a preset length strategy and the first aspect ratio;
[0073] The restoration module 610 is used to restore the image to be processed according to the compression aspect ratio based on a preset restoration strategy to obtain a restored image.
[0074] Furthermore, the division module 604 includes:
[0075] A type submodule, used to obtain the image type of the image to be processed;
[0076] A setting submodule, used for setting a preset ratio for dividing the image to be processed based on the image type; and
[0077] The division submodule is used to divide the image to be processed into a plurality of sub-images according to the preset ratio.
[0078] Further, the traversal module 606 includes:
[0079] A traversal submodule, used for traversing the pixel points of each sub-image, and calculating the pixel ratio according to the pixel values of the pixel points;
[0080] A to-be-determined submodule, used to determine at least one to-be-determined character area according to the pixel ratio;
[0081] A coordinate submodule, used for binarizing the sub-images where the character regions to be determined are located, and locating the text coordinates from the binarized sub-images;
[0082] The cutting submodule is used to obtain a single line of text or a single column of text based on the text coordinates through a proximity search algorithm, and perform text cutting on the single line of text or the single column of text to obtain the single character area.
[0083] Furthermore, the cutting submodule includes:
[0084] A connectivity unit, used to determine at least one connected region according to the text coordinates, wherein the connected region is a text region composed of foreground pixels having the same pixel value and adjacent positions in the image to be processed;
[0085] An expansion unit, used for obtaining a horizontal circumscribed rectangle of the connected area, and expanding the connected area to the entire horizontal circumscribed rectangle to obtain an expanded connected area;
[0086] The expansion unit is used to perform an expansion operation in the direction of the nearest connected area when the distance between the expanded connected area and the nearest connected area is less than a preset distance to obtain a single line of text or a single column of text, and cut the single line of text or the single column of text to obtain the single character area.
[0087] Furthermore, the ratio module 608 includes:
[0088] A frequency submodule, used to calculate the regional frequency of text rectangular regions with the same first aspect ratio, wherein the regional frequency is the frequency of occurrence of text regions with the same first aspect ratio in all text rectangular regions;
[0089] The length-width submodule is used to use the first length-width ratio corresponding to the regional frequency greater than the preset frequency as the compression length-width ratio.
[0090] Furthermore, the restoration module 610 includes:
[0091] A fixed submodule, used for obtaining a fixed aspect ratio of the text rectangular area, and calculating a compression ratio of the image to be processed according to the fixed aspect ratio and the compression aspect ratio;
[0092] The restoration submodule is used to restore the image to be processed according to the compression ratio to obtain the restored image.
[0093] It should be emphasized that in order to further ensure the privacy and security of the above-mentioned images to be processed, the above-mentioned images to be processed can also be stored in a node of a blockchain.
[0094] The above-mentioned zoomed image restoration device obtains the aspect ratio of the single character area traced by the image to be processed as the compression aspect ratio, and then restores the image to be processed to its original proportion according to the compression aspect ratio to obtain a restored image. This image restoration method is suitable for scenarios where text and images are compressed horizontally or vertically together. The single character area can be quickly located through existing algorithms or models, and then the aspect ratio of the single character area can be obtained to achieve rapid proportional restoration of the compressed image.
[0095] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 7As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer-readable instruction and a database. The internal memory provides an environment for the operation of the operating system and the computer-readable instruction in the non-volatile storage medium. The database of the computer device is used to store images to be processed and restored images. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer-readable instruction is executed by the processor, a method for restoring a scaled image is implemented. By obtaining the aspect ratio of a single character area traced by the image to be processed as a compression aspect ratio, wherein the compression aspect ratio is the aspect ratio of the original image corresponding to the image to be processed after being scaled; then the image to be processed is restored to its original proportion according to the compression aspect ratio to obtain a restored image. This image restoration method is suitable for scenarios where text and images are compressed horizontally or vertically together. A single character area can be quickly located through an existing algorithm or model, and then the aspect ratio of the single character area is obtained to achieve rapid proportional restoration of the compressed image.
[0096] Among them, technicians in this technical field can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.
[0097] Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0098] In one embodiment, a computer-readable storage medium is provided on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor, the steps of the zoom image restoration method in the above embodiment are implemented, such as Figure 2 Steps 202 to 210 shown in the figure, or when the processor executes the computer-readable instructions, the functions of each module / unit of the zoom image restoration device in the above embodiment are realized, for example Figure 6The functions of modules 602 to 610 are shown.
[0099] By obtaining the aspect ratio of the single character area traced by the image to be processed as the compression aspect ratio, the image to be processed is restored to its original proportion according to the compression aspect ratio to obtain a restored image. This image restoration method is suitable for scenarios where text and images are compressed horizontally or vertically together. The single character area can be quickly located through existing algorithms or models, and then the aspect ratio of the single character area can be obtained to achieve rapid proportional restoration of the compressed image.
[0100] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing related hardware through computer-readable instructions, and the computer-readable instructions can be stored in a non-volatile computer-readable storage medium. When the computer-readable instructions are executed, they may include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0101] The blockchain referred to in this application is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0102] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0103] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0104] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for those of ordinary skill in the art, without departing from the concept of the present application, several modifications, improvements or equivalent replacements of some technical features can be made, and these modifications or replacements do not make the essence of the same technical solution depart from the spirit and scope of the technical solution of each embodiment of the present invention, and all belong to the protection scope of the present application. Therefore, the protection scope of the patent of this application shall be subject to the attached claims.
Claims
1. A method for restoring a zoomed image, characterized in that: The method comprises: Acquire an image to be processed, wherein the image to be processed includes at least one preset text; Dividing the image to be processed into multiple sub-images according to a preset division strategy; Traversing the pixel points of each sub-image to obtain at least one single-character region, wherein the single-character region is the position of a single preset word on the sub-image; Obtaining a text rectangular area of each single character area, calculating a first aspect ratio of each of the text rectangular areas, and calculating a compressed aspect ratio according to a preset aspect strategy and the first aspect ratio; Restoring the image to be processed according to the compression aspect ratio based on a preset restoration strategy to obtain a restored image; The traversing the pixel points of each sub-image to obtain at least one single-character area includes: Traversing the pixel points of each of the sub-images, and calculating the pixel ratio according to the pixel values of the pixel points; Determine at least one character area to be determined according to the pixel ratio; Binarizing the sub-images where the character regions to be determined are located, and locating the text coordinates from the binarized sub-images; Based on the text coordinates, a single line of text or a single column of text is obtained by a proximity search algorithm, and the single line of text or the single column of text is segmented to obtain the single character area; The step of obtaining a single line of text or a single column of text by a proximity search algorithm based on the text coordinates, and performing text segmentation on the single line of text or the single column of text to obtain the single character region includes: Determine at least one connected region according to the text coordinates, wherein the connected region is a text region composed of foreground pixels having the same pixel value and adjacent positions in the image to be processed; Acquire a horizontal circumscribed rectangle of the connected area, and expand the connected area to the entire horizontal circumscribed rectangle to obtain an expanded connected area; When the distance between the expanded connected area and the nearest connected area is less than the preset distance, an expansion operation is performed in the direction of the nearest connected area to obtain a single line of text or a single column of text, and the single line of text or the single column of text is cut to obtain the single character area.
2. The method according to claim 1, characterized in that The step of dividing the image to be processed into a plurality of sub-images according to a preset division strategy includes: Acquire the image type of the image to be processed; Setting a preset ratio for dividing the image to be processed based on the image type; and The image to be processed is divided into a plurality of sub-images according to the preset ratio.
3. The method according to claim 1, characterized in that The step of calculating the compressed aspect ratio according to the preset aspect strategy and the first aspect ratio includes: Calculating the region frequency of text rectangular regions with the same first aspect ratio, wherein the region frequency is the frequency of occurrence of text regions with the same first aspect ratio in all text rectangular regions; The first aspect ratio corresponding to the regional frequency greater than the preset frequency is used as the compression aspect ratio.
4. The method according to claim 1, characterized in that: The restoring the image to be processed according to the compressed aspect ratio based on a preset restoration strategy to obtain a restored image includes: Obtaining a fixed aspect ratio of the text rectangular area, and calculating a compression ratio of the image to be processed according to the fixed aspect ratio and the compression aspect ratio; The image to be processed is restored according to the compression ratio to obtain the restored image.
5. A zoom image restoration device, characterized in that: When the zoomed image restoration device is running, the zoomed image restoration method according to any one of claims 1 to 4 is implemented, and the zoomed image restoration device comprises: An acquisition module, used for acquiring an image to be processed, wherein the image to be processed includes at least one preset text; A division module, used for dividing the image to be processed into a plurality of sub-images according to a preset division strategy; A traversal module, used for traversing the pixel points of each sub-image to obtain at least one single-character area, wherein the single-character area is the position of a single preset word on the sub-image; A ratio module, used for obtaining a text rectangular area of each single character area, calculating a first aspect ratio of each text rectangular area, and calculating a compressed aspect ratio based on a preset aspect strategy and the first aspect ratio; The restoration module is used to restore the image to be processed according to the compression aspect ratio based on a preset restoration strategy to obtain a restored image.
6. The device according to claim 5, characterized in that The division module comprises: A type submodule, used to obtain the image type of the image to be processed; A setting submodule, used for setting a preset ratio for dividing the image to be processed based on the image type; and The division submodule is used to divide the image to be processed into a plurality of sub-images according to the preset ratio.
7. A computer device comprising a memory and a processor, wherein the memory stores computer-readable instructions, characterized in that: When the processor executes the computer-readable instructions, the steps of the method according to any one of claims 1 to 4 are implemented.
8. A computer-readable storage medium having computer-readable instructions stored thereon, characterized in that: When the computer readable instructions are executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.
