File watermark processing method and system, computer equipment and readable storage medium

By accurately locating the watermark area through the U-NET network and Alpha channel technology, and combining transparency adjustment and mask fusion, the efficiency and accuracy problems of PDF file watermark removal in the existing technology are solved, and efficient and accurate watermark removal effects are achieved, which is suitable for a variety of application scenarios.

CN120689192APending Publication Date: 2025-09-23SHANDONG SAIFEITE SAFETY ENG TECH DEV CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510841074.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-23
Publication Date
2025-09-23

AI Technical Summary

Technical Problem

When removing watermarks from PDF files, existing technologies have difficulty in efficiently and accurately removing various forms of watermarks while maintaining the integrity of the document structure. In particular, it is easy to produce processing artifacts or affect the interactivity and editability of the file in complex backgrounds.

Method used

The pre-trained U-NET network is used for image segmentation. The transparency is adjusted through the Alpha channel and CSS style to generate a watermark mask layer, accurately locate and cover the watermark area. Combined with the deformable convolution layer to adapt to the geometric deformation of the image, the automatic and accurate positioning and masking of the watermark are achieved.

Benefits of technology

It achieves high-precision and lightweight watermark removal, maintains the beauty of documents and the integrity of information, is suitable for browser rendering and image processing environments, adapts to watermark structures of different shapes and positions, reduces false detections and missed detections, and improves processing efficiency and naturalness of results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120689192A_ABST
    Figure CN120689192A_ABST
Patent Text Reader

Abstract

The invention relates to a file watermark processing method and system, computer equipment and a computer readable storage medium, and the method comprises the following steps: a page extraction step: extracting a PDF page of a to-be-processed PDF file; a watermark positioning step: positioning a target watermark in the PDF page based on a pre-trained image segmentation algorithm, and outputting position information corresponding to the shape of the target watermark; a watermark processing step: configuring the transparency of a pixel point at the target watermark, generating a watermark mask layer, fusing the watermark mask layer with the target watermark, and covering the target watermark so as to realize visual shielding processing; and a file output step: repeating the watermark positioning step and the watermark processing step until the watermark processing of the to-be-processed PDF file is completed, and outputting the watermarking-free PDF file. According to the method and the device, high-precision automatic PDF file watermark removal can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image processing technology, and in particular to a file watermark processing method, system, computer device and computer-readable storage medium. Background Art

[0002] In the everyday use of PDF files, watermarks are often used as additional information carriers to indicate copyright, confidentiality levels, or prevent illegal dissemination. Watermark technology can be roughly divided into three categories based on its form: text watermarks (such as "Draft" and "Confidential"), image watermarks (such as company logos and seals), and digital watermarks (such as embedded invisible tracking codes). While watermarks play an important role in document identification and information security, they often interfere with secondary editing, re-formatting, or information extraction, affecting the actual document user experience and editing freedom.

[0003] For example, in the publishing industry or academic data compilation, publishers or university libraries, after obtaining original PDF documents, need to remove watermarks such as "Preview" or "Unofficial Version" before reformatting, archiving, or integrating them into internal databases. While these watermarks are not intended to prevent copying, they can be redundant or detract from the professional presentation of content in delivery scenarios. For another example, after completing a business document review process, a company may obtain permission from its partners to remove temporary watermarks such as "Confidential" or "Draft" from initial drafts in order to produce a formal report.

[0004] Current methods for removing watermarks from PDF files include, for example, using OpenCV-based edge detection (such as the Canny algorithm) to locate the watermark area, followed by image inpainting algorithms to fill in the background. While these techniques are suitable for unstructured images, they are susceptible to background complexity and can easily produce processing artifacts. Another approach involves converting PDF files to PostScript format using tools like Ghostscript and pdf2ps, removing unnecessary objects, and then regenerating the PDF. This approach comes at the cost of potentially losing functional components such as hyperlinks, interactive controls, or forms within the document, impacting the interactivity and editability of the document.

[0005] In recent years, deep learning has been increasingly used in document image analysis. Image restoration networks, such as the Transformer architecture, employ a hierarchical self-attention mechanism to model long-range dependencies and automatically identify and reconstruct watermarked areas in complex backgrounds. However, this approach relies heavily on GPU computing resources and has high training costs.

[0006] Therefore, how to efficiently and accurately remove various forms of PDF watermarks while maintaining the integrity of the document structure remains a technical problem that needs to be solved urgently. Summary of the Invention

[0007] The embodiments of the present application provide a file watermark processing method, system, computer device and computer-readable storage medium to at least solve the problem of how to efficiently and accurately remove various forms of PDF watermarks.

[0008] In a first aspect, an embodiment of the present application provides a method for processing a file watermark, comprising: Page extraction step, extracting PDF pages of the PDF file to be processed; a watermark positioning step, locating a target watermark in the PDF page based on a pre-trained image segmentation algorithm, and outputting position information corresponding to the shape of the target watermark; a watermark processing step of configuring the transparency of the pixels at the target watermark, generating a watermark mask layer, fusing the watermark mask layer with the target watermark, and covering the target watermark to achieve visual masking; The file output step repeats the watermark positioning step and the watermark processing step until the watermark processing of the PDF file to be processed is completed and a PDF document without watermark is output.

[0009] In some embodiments, the watermark processing step includes setting the transparency of pixels at the target watermark by using the opacity attribute of the CSS style or the rgba() color value.

[0010] This method can mask or weaken the watermark area without changing the rest of the image, effectively concealing the original watermark image. It's particularly suitable for front-end or interactive pre-processing scenarios, and can also be used with PDF rendering engines (such as PDF.js) to dynamically achieve preview effects or output conversion.

[0011] In some embodiments, the watermark processing step further includes: Convert the PDF page to an image file, including PNG, TIFF, or WebP formats; The alpha channel is used to set the transparency of the image file.

[0012] In some embodiments, the image segmentation algorithm adopts a U-NET network.

[0013] In another embodiment, a deep learning model of the Mask R-CNN architecture may also be used as the image segmentation algorithm.

[0014] In some embodiments, the U-NET network includes: An encoder is used to obtain the PNG image to be processed, and extract image features through convolution operations and pooling operations of multiple groups of convolution layers and pooling layers. The pooling layer is a maximum pooling layer with a convolution kernel size of 2×2, which is used to reduce the spatial dimension of the feature map, thereby obtaining a multi-scale image feature representation. The convolution kernel size of the pooling layer is 3×3 and is activated by a ReLU activation function to increase nonlinear expression capabilities; The decoder is used to restore the spatial dimensions of the image through multiple groups of upsampling layers and convolutional layers. The upsampling layer is used to increase the spatial dimensions of the feature map to facilitate splicing with the feature map of the encoder. The feature map in the encoder is directly passed to the convolutional layer of the decoder through jump connections for splicing and feature fusion. This ensures that the high-resolution features extracted in the encoding stage are effectively utilized in the decoding stage, which helps to combine shallow features and deep features in the decoder to better restore details.

[0015] The output layer is used to generate a segmentation map with a category label for each pixel through a 1×1 convolution layer, that is, the binary classification result of watermark pixels and non-watermark pixels. The 1×1 convolution layer uses softmax as the loss function. The category label is used to identify whether it is a watermark. The softmax function is combined with the 1×1 convolution to generate a pixel-level classification map, which improves the model's adaptability to watermark areas in different image backgrounds.

[0016] In the above embodiment, the calculation model of the softmax is expressed as the following calculation model:

[0017] in, is the pixel position, is the number of categories, for The corresponding The value of each channel.

[0018] Based on the aforementioned U-NET network, the network outputs a mask image of the same size as the input image, with the watermark location highlighted within the mask. This allows the precise shape and coordinates of the watermark to be extracted. During the training phase, the network uses supervised learning with data containing annotated watermark regions, and during the deployment phase, it performs inference and prediction, enabling automatic and precise watermark location. This network structure allows the network to retain important spatial features in the image, resulting in more accurate watermark boundary identification. Compared to traditional segmentation algorithms, U-NET is more adaptable to changes in watermark shape and size, reducing false and missed detections and ensuring the accuracy of subsequent masking and processing operations.

[0019] In some embodiments, the loss function further includes a cross-entropy loss function, which is expressed as the following calculation model:

[0020] in, is the pixel space, which is used to represent the pixel set of the image area. It is the weight factor of the pixel when calculating the cross entropy loss, which is used to adjust the importance of different areas to the overall loss value.

[0021] Specifically, , Adding weight to the Gaussian type, defining a Gaussian distribution attenuation weight through an exponential function to emphasize the boundary area between target categories, It is a preset basic category weight function used to represent pixel points The base weight of the category, is the weight coefficient, which can be assigned according to the actual training effect, and the assignment range is 1~10. 、 Pixel The distance to the nearest boundary of two different category areas emphasizes the area near the category boundary to increase the sensitivity to edge pixels. The specific value can be calculated using a distance transformation algorithm (such as Euclidean distance transform EDT). It is the Gaussian kernel parameter, which is used to control the width of the Gaussian function. The smaller the value, the higher the weight area is limited to the vicinity of the boundary. The larger the value, the farther the weight area spreads. It can be adjusted according to actual needs. For example, a smaller value, such as 5 to 10, can be selected to focus on the area close to the boundary. Based on this, based on the weight formula, the weight of the boundary area is increased during training, which is beneficial for the model to capture boundary details and improve segmentation accuracy.

[0022] In some of the embodiments, in the encoder and decoder, some or all of the convolutional layers are replaced with deformable convolutional layers, which adjust the sampling position of the convolution kernel through a learnable offset so that the convolution operation can better adapt to the geometric deformation in the image to accommodate cross-page or irregular watermarks.

[0023] In the above embodiment, the weights of the offset generation layer are initialized to zero, so that the behavior in the initial stage is close to the standard convolution. After completing the training process of the U-NET network, fine-tuning is performed to add the deformable convolution layer.

[0024] The core of the deformable convolution layer lies in adding a set of learnable two-dimensional offsets to the traditional regular convolution sampling positions. This allows the convolution kernel to no longer be limited to fixed grid positions when performing operations, but to dynamically adjust its receptive area based on the morphology of the input features. This mechanism allows the network to automatically adaptively model areas in the image with significant deformation, distorted watermark structures, or blurred boundaries, thereby more accurately extracting local key features. Specifically, the deformable convolution layer can be applied to the downsampling path of the encoder to improve feature expression, and can also be applied to the upsampling path of the decoder to improve the accuracy of spatial restoration and the ability to recover details.

[0025] In a second aspect, an embodiment of the present application provides a file watermark processing system for implementing the file watermark processing method described in the first aspect above, the system comprising: A page extraction unit, used for extracting PDF pages from a PDF file to be processed; a watermark positioning unit, configured to locate a target watermark in the PDF page based on a pre-trained image segmentation algorithm and output position information corresponding to a shape of the target watermark; a watermark processing unit configured to configure the transparency of pixels at a target watermark, generate a watermark mask layer, and fuse the watermark mask layer with the target watermark to cover the target watermark; The file output unit is used to repeatedly execute the watermark positioning unit and the watermark processing unit until the watermark processing of the PDF file to be processed is completed and a PDF document without watermark is output.

[0026] In a third aspect, an embodiment of the present application provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the file watermark processing method as described in the first aspect above is implemented.

[0027] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the file watermark processing method as described in the first aspect above.

[0028] The details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings: Figure 1 is a flow chart of a file watermark processing method according to an embodiment of the present application; Figure 2 This is a schematic diagram of a PDF page watermark effect according to an embodiment of the present application; Figure 3 This is a schematic diagram of the effect of removing a watermark from a PDF page according to an embodiment of the present application; Figure 4 It is a structural block diagram of a file watermark processing system according to an embodiment of the present application.

[0030] In the picture: 1. Page extraction unit; 2. Watermark positioning unit; 3. Watermark processing unit; 4. File transfer unit. DETAILED DESCRIPTION

[0031] In order to make the purpose, technical solutions and advantages of this application more clearly understood, the present application is described and illustrated below in conjunction with the accompanying drawings and examples. It should be understood that the specific embodiments described herein are merely used to explain this application and are not intended to limit this application. Based on the embodiments provided in this application, all other embodiments obtained by those of ordinary skill in the art without making any creative efforts are within the scope of protection of this application.

[0032] Obviously, the drawings described below are merely examples or embodiments of the present application. Those skilled in the art can, without inventive effort, apply the present application to other similar scenarios based on these drawings. Furthermore, it is also understood that, although the effort involved in such a development process may be complex and lengthy, for those skilled in the art related to the content disclosed in this application, changes in design, manufacturing, or production based on the technical content disclosed in this application are merely conventional technical means and should not be construed as an insufficiency of the content disclosed in this application.

[0033] References to "embodiments" in this application mean that a particular feature, structure, or characteristic described in connection with the embodiment may be included in at least one embodiment of the application. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor does it refer to independent or alternative embodiments that are mutually exclusive of other embodiments. It is understood, both explicitly and implicitly, by those skilled in the art that the embodiments described in this application may be combined with other embodiments unless there is a conflict.

[0034] Unless otherwise defined, technical or scientific terms used herein shall have the ordinary meaning as understood by persons of ordinary skill in the art to which this application belongs. The terms "a," "an," "an," "the," and similar expressions used herein do not denote quantitative limitations and may refer to either the singular or the plural. The terms "comprise," "include," "have," and any variations thereof, used herein, are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus comprising a series of steps or modules (units) is not limited to the listed steps or units but may also include steps or units not listed, or may include other steps or units inherent to the process, method, product, or apparatus. The terms "connected," "connected," "coupled," and similar expressions used herein are not limited to physical or mechanical connections but may include electrical connections, whether direct or indirect. As used herein, "plurality" means two or more. "And / or" describes an association between associated objects, indicating that three possible relationships exist. For example, "A and / or B" may mean: A exists alone; A and B exist simultaneously; or B exists alone. The character " / " generally indicates that the objects before and after are in an "or" relationship. The terms "first", "second", "third", etc. involved in this application are only used to distinguish similar objects and do not represent a specific order for the objects.

[0035] The alpha channel is part of the internal storage of image files (such as PNG, GIF, and WebP). Each pixel contains four RGBA values ​​(R: red, G: green, B: blue, A: transparency). The alpha value directly defines the degree of transparency of the pixel (for example, A=0 means completely transparent, A=255 means completely opaque).

[0036] The CSS opacity property or rgba() color value is a visual effect superimposed on the display through code and does not affect the original image data.

[0037] This embodiment provides a file watermark processing method. Figure 1 is a flow chart of a method for processing file watermarks according to an embodiment of the present application. Figure 1 As shown, the process includes the following steps: Page extraction step S1, extracting the PDF page of the PDF file to be processed, such as Figure 2 As shown, the page is marked with "For internal use only"; Watermark positioning step S2, locating the target watermark in the PDF page based on a pre-trained image segmentation algorithm, and outputting position information corresponding to the shape of the target watermark; Watermark processing step S3, configures the transparency of the pixel points at the target watermark, generates a watermark mask layer, merges the watermark mask layer with the target watermark, covers the target watermark, and realizes visual masking processing, and obtains the following Figure 3 The visuals shown; In the file output step S4, the watermark positioning step S2 and the watermark processing step S3 are repeated until the watermark processing of the PDF file to be processed is completed and a PDF document without a watermark is output.

[0038] Based on the above steps, the embodiment of the present application can achieve high-precision automated watermark removal for PDF files, avoiding the tedious manual identification and processing and improving work efficiency. The deep learning segmentation algorithm can accurately obtain the watermark boundary and effectively adapt to watermark structures of different shapes and positions; the watermark area is processed by transparency adjustment and mask fusion, maintaining the overall aesthetics and information integrity of the image; the final output PDF file is clear and neat, suitable for subsequent document archiving, display, or secondary editing.

[0039] In some embodiments, when operating in a browser environment or a PDF processing framework based on HTML rendering, the transparency of the located target watermark area can be directly controlled using a CSS style. The watermark processing step S3 includes setting the transparency of the pixel at the target watermark using the opacity attribute of the CSS style or the rgba() color value. For example, setting the opacity attribute to 0 indicates complete transparency, or setting rgba(255, 255, 255, 0) to create a visual effect similar to a mask overlay when displayed through code.

[0040] This method can mask or weaken the watermark area without changing the rest of the image, effectively concealing the original watermark image. It's particularly suitable for front-end or interactive pre-processing scenarios, and can also be used with PDF rendering engines (such as PDF.js) to dynamically achieve preview effects or output conversion.

[0041] This implementation provides a lightweight, highly compatible watermark processing method that leverages existing CSS properties to set the transparency of the target watermark area, eliminating the need for complex image processing algorithms or image restoration processes. This method offers the advantages of simplicity and efficiency. This method can be directly applied to browser rendering scenarios and is suitable for HTML5-based PDF preview or editing platforms. Furthermore, by adjusting the opacity or RGBA alpha parameters, a watermark can be adjusted to weaken rather than completely obscure the image, adapting to different usage requirements.

[0042] In a non-browser environment, the corresponding logic can be migrated to image processing code, such as using the Pillow library in Python to adjust the pixel transparency channel; or using alpha channel blending technology in OpenCV for equivalent processing.

[0043] For PDF image conversion processes that do not support CSS, the same masking effect can also be achieved by constructing a mask layer and merging it into the target image.

[0044] In addition, when setting the RGB value, you can select an appropriate RGB value according to the image background to improve the naturalness of the occlusion, such as using the local background color for fusion to reduce visual abruptness.

[0045] In some embodiments, the watermark processing step S3 further includes: Convert the PDF page to an image file, including PNG, TIFF, or WebP formats, which support alpha channels and retain high image quality. This conversion can be achieved using tools such as poppler, pdf2image, or ImageMagick. The alpha channel is used to set the transparency of the image file.

[0046] Based on the above steps, by adjusting the alpha value of the target watermark area to 0 or a low value, the watermark is masked or faded, enhancing the flexibility and precision of watermark processing. This process can be performed using image processing tools (such as Pillow and OpenCV) to ensure processing accuracy and image consistency. Through image-level operations, it can achieve precise coverage of complex watermark areas (such as graphic watermarks and mixed image and text watermarks). It also supports transparency gradients and regional selective processing to enhance the naturalness of visual processing. It also avoids visual interference in non-watermark areas, maintaining the image quality and information integrity of the original page, making it particularly suitable for demanding document cleanup scenarios.

[0047] After adjusting the image transparency, you can choose to keep the image file or further reorganize it into a PDF file.

[0048] In some embodiments, the image segmentation algorithm adopts a U-NET network.

[0049] In another embodiment, a deep learning model of the Mask R-CNN architecture may also be used as the image segmentation algorithm.

[0050] In some embodiments, the U-NET network includes: An encoder is used to obtain the PNG image to be processed, and extract image features through convolution operations and pooling operations of multiple groups of convolution layers and pooling layers. The pooling layer is a maximum pooling layer with a convolution kernel size of 2×2, which is used to reduce the spatial dimension of the feature map, thereby obtaining a multi-scale image feature representation. The convolution kernel size of the pooling layer is 3×3 and is activated by a ReLU activation function to increase nonlinear expression capabilities; The decoder is used to restore the spatial dimension of the image through multiple groups of upsampling layers and convolution layers. The upsampling layer is used to increase the spatial dimension of the feature map to facilitate splicing with the feature map of the encoder. The feature map in the encoder is directly transferred to the convolution layer of the decoder through a jump connection for splicing and feature fusion operation; to ensure the effective use of the high-resolution features extracted in the encoding stage in the decoding stage, it is helpful to combine shallow features and deep features in the decoder to better restore details. Among them, the shallow features of the encoder and the deep features of the decoder are directly fused to avoid the disappearance of the gradient while retaining the high-frequency details of the image, such as texture details and edge details. The shallow features are used to provide pixel-level information of the background, and the deep features are used to provide semantic consistency constraints to ensure a natural transition between the watermark area and the background.

[0051] The output layer is used to generate a segmentation map with a category label for each pixel through a 1×1 convolution layer, that is, the binary classification result of watermark pixels and non-watermark pixels. The 1×1 convolution layer uses softmax as the loss function. The category label is used to identify whether it is a watermark. The softmax function is combined with the 1×1 convolution to generate a pixel-level classification map, which improves the model's adaptability to watermark areas in different image backgrounds.

[0052] In the above embodiment, the calculation model of the softmax is expressed as the following calculation model:

[0053] in, is the pixel position, is the number of categories, for The corresponding The value of each channel.

[0054] In the above solution, the convolution kernel size can be adjusted appropriately based on the image resolution or watermark feature size, for example, changing to a 3×3 convolution to enhance the local receptive field. LeakyReLU, GELU, or other activation functions can be used instead of ReLU to improve feature representation. Average pooling can be used in the pooling layer instead of max pooling to more smoothly extract background information. The decoder's upsampling operation can also be implemented through deconvolution or pixel shuffle to improve the restoration effect. The output layer's loss function can be replaced with Diceloss, Focal loss, or other loss functions more suitable for segmentation tasks with imbalanced data, improving the model's ability to recognize small watermarked areas. Skip connections can optimize their fusion weights through the attention mechanism, further enhancing the retention and prominence of important features.

[0055] Based on the aforementioned U-NET network, the network outputs a mask image of the same size as the input image, with the watermark location highlighted within the mask. This allows the precise shape and coordinates of the watermark to be extracted. During the training phase, the network uses supervised learning with data containing annotated watermark regions, and during the deployment phase, it performs inference and prediction, enabling automatic and precise watermark location. This network structure allows the network to retain important spatial features in the image, resulting in more accurate watermark boundary identification. Compared to traditional segmentation algorithms, U-NET is more adaptable to changes in watermark shape and size, reducing false and missed detections and ensuring the accuracy of subsequent masking and processing operations.

[0056] In some embodiments, the loss function further includes a cross-entropy loss function, which is expressed as the following calculation model:

[0057] in, is the pixel space, which is used to represent the pixel set of the image area. It is the weight factor of the pixel when calculating the cross entropy loss, which is used to adjust the importance of different areas to the overall loss value.

[0058] Specifically, , Adding weight to the Gaussian type, defining a Gaussian distribution attenuation weight through an exponential function to emphasize the boundary area between target categories, It is a preset basic category weight function used to represent pixel points The base weight of the category, is the weight coefficient, which can be assigned according to the actual training effect, and the assignment range is 1~10. 、 Pixel The distance to the nearest boundary of two different category areas emphasizes the area near the category boundary to increase the sensitivity to edge pixels. The specific value can be calculated using a distance transformation algorithm (such as Euclidean distance transform EDT). It is the Gaussian kernel parameter, which is used to control the width of the Gaussian function. The smaller the value, the higher the weight area is limited to the vicinity of the boundary. The larger the value, the farther the weight area spreads. It can be adjusted according to actual needs. For example, a smaller value, such as 5 to 10, can be selected to focus on the area close to the boundary. Based on this, based on the weight formula, the weight of the boundary area is increased during training, which is beneficial for the model to capture boundary details and improve segmentation accuracy.

[0059] In the above embodiment, in the image segmentation task, the classification of each pixel is regarded as an independent prediction target. The model guides the network to learn more accurate watermark positioning boundaries and region recognition by minimizing the sum of negative cross entropy of all pixels. This loss function has a large penalty for misclassified pixels and can enhance the model's ability to recognize boundary transition areas. Compared with other loss functions, negative cross entropy is more sensitive to the gradient of the predicted probability, which helps the network to quickly establish an effective feature discrimination boundary in the early stages of training. It is particularly suitable for scenes with blurred transition areas between watermarks and backgrounds. This method can effectively reduce misjudgments and missed judgments, enhance the model's ability to recognize tiny watermark patterns, and take into account the restoration of background information, ensuring that the final output cover map is more natural and coordinated.

[0060] In some embodiments, taking into account the situation where the watermark overlaps across pages, the present application replaces some or all of the convolution layers in the encoder and decoder with deformable convolution layers. The deformable convolution layers adjust the sampling position of the convolution kernel through a learnable offset, so that the convolution operation can better adapt to the geometric deformation in the image to adapt to cross-page or irregular watermarks.

[0061] In the above embodiment, the weights of the offset generation layer are initialized to zero, so that the behavior in the initial stage is close to the standard convolution. After completing the training process of the U-NET network, fine-tuning is performed to add the deformable convolution layer.

[0062] The core of the deformable convolution layer lies in adding a set of learnable two-dimensional offsets to the traditional regular convolution sampling positions. This allows the convolution kernel to no longer be limited to fixed grid positions when performing operations, but to dynamically adjust its receptive area based on the morphology of the input features. This mechanism allows the network to automatically adaptively model areas in the image with significant deformation, distorted watermark structures, or blurred boundaries, thereby more accurately extracting local key features. Specifically, the deformable convolution layer can be applied to the downsampling path of the encoder to improve feature expression, and can also be applied to the upsampling path of the decoder to improve the accuracy of spatial restoration and the ability to recover details.

[0063] Based on the above steps, this application uses the network structure of the U-NET network to simultaneously capture the global distribution and local details of the watermark, and uses its jump connection mechanism, pixel-level processing capabilities and end-to-end image generation characteristics to adapt to the watermark processing task in a targeted manner. Traditional target detection models, such as Faster R-CNN, can achieve watermark positioning based on the classification regression structure, but may cause local texture blur or artifacts after watermark removal, and it is difficult to directly generate a watermark image. This application uses pixel-level semantic segmentation to achieve more refined boundary extraction, combined with transparency adjustment and mask fusion processing, to achieve natural and traceless removal of complex watermarks, meeting the needs of high-fidelity image editing. Therefore, the image watermark processing method proposed in this application is superior to existing detection solutions in terms of accuracy, naturalness and processing efficiency, and is particularly suitable for scenarios where watermarks are removed from batch PDF image documents.

[0064] It should be noted that the steps shown in the above process or the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0065] This embodiment also provides a file watermark processing system, which is used to implement the above-mentioned embodiments and preferred implementations. Details that have already been described will not be repeated. As used below, the terms "module," "unit," "subunit," etc. may refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation using hardware, or a combination of software and hardware, is also possible and contemplated.

[0066] Figure 4 is a structural block diagram of a file watermark processing system according to an embodiment of the present application, such as Figure 4 As shown, the system includes: The page extraction unit 1 is used to extract PDF pages from the PDF file to be processed; a watermark positioning unit 2, configured to locate a target watermark in the PDF page based on a pre-trained image segmentation algorithm and output position information corresponding to the shape of the target watermark; The watermark processing unit 3 is used to configure the transparency of the pixel points at the target watermark, generate a watermark mask layer, and merge the watermark mask layer with the target watermark to cover the target watermark; The file output unit 3 is used to repeatedly execute the watermark positioning unit and the watermark processing unit until the watermark processing of the PDF file to be processed is completed and a PDF document without watermark is output.

[0067] It should be noted that the above modules can be functional modules or program modules, and can be implemented through software or hardware. For modules implemented through hardware, the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.

[0068] In addition, combined Figure 1 The file watermark processing method described in the embodiment of the present application can be implemented by a computer device. The computer device may include a processor and a memory storing computer program instructions.

[0069] Specifically, the processor may include a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.

[0070] The memory may include a large-capacity memory for data or instructions. By way of example, and not limitation, the memory may include a hard disk drive (HDD), a floppy disk drive, a solid-state drive (SSD), flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a Universal Serial Bus (USB) drive, or a combination of two or more of these. Where appropriate, the memory may include removable or non-removable (or fixed) media. Where appropriate, the memory may be internal or external to the data processing device. In a specific embodiment, the memory is non-volatile memory. In a specific embodiment, the memory includes read-only memory (ROM) and random access memory (RAM). Where appropriate, the ROM may be a mask-programmed ROM, a programmable ROM (PROM), an erasable PROM (EPROM), an electrically erasable PROM (EEPROM), an electrically alterable ROM (EAROM) or a flash memory (FLASH), or a combination of two or more of these. Under appropriate circumstances, the RAM can be a static random access memory (SRAM) or a dynamic random access memory (DRAM), where the DRAM can be a fast page mode dynamic random access memory (FPMDRAM), an extended data out dynamic random access memory (EDODRAM), a synchronous dynamic random access memory (SDRAM), etc.

[0071] The memory may be used to store or cache various data files required for processing and / or communication, as well as possible computer program instructions executed by the processor.

[0072] The processor implements any one of the file watermark processing methods in the above embodiments by reading and executing computer program instructions stored in the memory.

[0073] The computer device can execute the file watermark processing method in the embodiment of the present application based on the acquired file, thereby realizing the combination Figure 1 Describes the file watermarking method.

[0074] In addition, in conjunction with the file watermark processing method in the above embodiments, the present application embodiment can provide a computer-readable storage medium for implementation. The computer-readable storage medium stores computer program instructions; when the computer program instructions are executed by a processor, any of the file watermark processing methods in the above embodiments is implemented.

[0075] The technical features of the above-mentioned embodiments can be combined arbitrarily. In order to make the description concise, not all possible combinations of the technical features in the above-mentioned 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.

[0076] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person skilled in the art could make various modifications and improvements without departing from the spirit of the present application, all of which fall within the scope of protection of the present application. Therefore, the scope of protection of the present patent application shall be determined by the appended claims.

Claims

1. A method for processing a file watermark, characterized in that: include: Page extraction step, extracting PDF pages of the PDF file to be processed; a watermark positioning step, locating a target watermark in the PDF page based on a pre-trained image segmentation algorithm, and outputting position information corresponding to the shape of the target watermark; a watermark processing step, configuring the transparency of the pixels at the target watermark, generating a watermark mask layer, and fusing the watermark mask layer with the target watermark to cover the target watermark; The file output step repeats the watermark positioning step and the watermark processing step until the watermark processing of the PDF file to be processed is completed and a PDF document without watermark is output.

2. The method for processing a file watermark according to claim 1, wherein: The watermark processing step includes: setting the transparency of the pixel points at the target watermark through the opacity attribute of the CSS style or the rgba() color value.

3. The method for processing a file watermark according to claim 1 or 2, characterized in that: The watermark processing step further includes: Convert the PDF page into an image file; The alpha channel is used to set the transparency of the image file.

4. The method for processing a file watermark according to claim 1, wherein: The image segmentation algorithm adopts the U-NET network.

5. The method for processing a file watermark according to claim 4, wherein: The U-NET network includes: An encoder is used to obtain the PNG image to be processed and extract image features through convolution operations and pooling operations of multiple groups of convolution layers and pooling layers; The decoder is used to restore the spatial dimensions of the image through multiple sets of upsampling layers and convolutional layers. The feature maps in the encoder are directly passed to the convolutional layer of the decoder through skip connections for splicing and feature fusion. The output layer is used to generate a segmentation map with a category label for each pixel through a 1×1 convolutional layer, that is, a binary classification result of watermark pixels and non-watermark pixels. The 1×1 convolutional layer uses softmax as the loss function, and the category label is used to identify whether it is a watermark.

6. The method for processing a document watermark according to claim 5, wherein: The loss function also includes: a cross entropy loss function.

7. The method for processing a document watermark according to claim 5, wherein: In the encoder and decoder, some or all convolutional layers are replaced with deformable convolutional layers, which adjust the sampling positions of the convolution kernels by learnable offsets.

8. A file watermark processing system, characterized in that: For implementing the file watermark processing method according to any one of claims 1 to 7, the system comprises: A page extraction unit, used for extracting PDF pages from a PDF file to be processed; a watermark positioning unit, configured to locate a target watermark in the PDF page based on a pre-trained image segmentation algorithm and output position information corresponding to a shape of the target watermark; a watermark processing unit configured to configure the transparency of pixels at a target watermark, generate a watermark mask layer, and fuse the watermark mask layer with the target watermark to cover the target watermark; The file output unit is used to repeatedly execute the watermark positioning unit and the watermark processing unit until the watermark processing of the PDF file to be processed is completed and a PDF document without watermark is output.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the file watermark processing method according to any one of claims 1 to 7 is implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the file watermark processing method according to any one of claims 1 to 7 is implemented.