An image processing method based on a feathering mask and related components
By generating feathered masks with linear gradient weights for image sub-blocks and performing weighted fusion, the seam problem when stitching adjacent sub-blocks after block inference of large-size images is solved, and high-quality image stitching effect is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- 深圳牛学长科技有限公司
- Filing Date
- 2026-04-13
- Publication Date
- 2026-06-05
AI Technical Summary
After large-size images are segmented for inference, obvious seams can easily appear when adjacent sub-blocks are stitched together, leading to a decrease in image quality.
An image processing method based on feathering masks is adopted. By generating a target feathering mask with linear gradient weights for each image sub-block, weighting it pixel by pixel and accumulating it onto a blank fusion canvas, the fusion of the four-sided gradient decay characteristics is achieved.
It reduces the appearance of obvious seams in traditional splicing methods, improving the visual coherence and overall quality of the fused images.
Smart Images

Figure CN122156388A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, specifically to an image processing method and related components based on feathering masks. Background Technology
[0002] In applications that utilize deep learning models for block-based inference of large images, such as image super-resolution and deblurring, reassembling the inferred image sub-blocks into a complete image is a crucial step. Existing technologies commonly employ methods such as direct stitching or simple averaging and fusion of overlapping regions.
[0003] However, these methods have drawbacks that lead to a degraded final image quality. Because deep learning models reason independently for each sub-block, even with similar input pixels, the output may exhibit subtle, discontinuous differences or inconsistent responses near the sub-block boundaries. When direct stitching is used, these differences create visually noticeable, harsh boundary lines or color blocks at the sub-block seams, resulting in obvious seams and unnatural transitions. Summary of the Invention
[0004] The purpose of this invention is to provide an image processing method and related components based on feathering masks to solve the problem that obvious seams are easily generated when adjacent sub-blocks are stitched together after large-size image block inference.
[0005] In a first aspect, the present invention provides an image processing method based on feathering masks, comprising: acquiring multiple image sub-blocks that have completed model inference and their position information in the original canvas; for each image sub-block, initializing a one-dimensional matrix matching its own size as an initial mask; calculating a first linear gradient weight of the image sub-block in the horizontal direction based on a preset overlapping region size and the magnification factor of the model inference, to obtain a horizontal weight map; calculating a second linear gradient weight of the image sub-block in the vertical direction based on the preset overlapping region size and the magnification factor, to obtain a vertical weight map; multiplying the initial mask, the horizontal weight map, and the vertical weight map pixel by pixel to generate a target feathering mask with four-sided gradient decay characteristics; weighting each image sub-block and its corresponding target feathering mask pixel by pixel, and accumulating the weighted sub-blocks onto a blank fusion canvas according to the position information to obtain a fused image.
[0006] According to one embodiment of the present invention, the step of initializing an all-one matrix matching its own size as an initial mask for each of the image sub-blocks includes: obtaining the total number of first pixels in the height direction and the total number of second pixels in the width direction of the current image sub-block; creating a two-dimensional matrix with the total number of first pixels as the number of rows and the total number of second pixels as the number of columns; setting all element values in the two-dimensional matrix to the value one, and determining the two-dimensional matrix as the initial mask of the current image sub-block.
[0007] According to one embodiment of the present invention, the step of calculating the first linear gradient weight of the image sub-block in the horizontal direction based on a preset overlapping region size and a magnification factor of model inference to obtain a horizontal weight map includes: calculating the pixel width of the magnified horizontal overlapping region based on the product of the overlapping region size and the magnification factor; generating a first gradient array that linearly increases from zero to one based on the pixel width of the horizontal overlapping region; mapping corresponding gradient weights to the left and right overlapping regions of the image sub-block based on the first gradient array; and concatenating the gradient weights of the left overlapping region, the all-one weights of the middle non-overlapping region, and the gradient weights of the right overlapping region along the horizontal direction to generate the horizontal weight map.
[0008] According to one embodiment of the present invention, the step of calculating the second linear gradient weight of the image sub-block in the vertical direction based on the preset overlapping region size and the magnification factor to obtain a vertical weight map includes: calculating the pixel height of the magnified vertical overlapping region based on the product of the overlapping region size and the magnification factor; generating a second gradient array that linearly increases from zero to one based on the pixel height of the vertical overlapping region; mapping corresponding gradient weights to the top overlapping region and the bottom overlapping region of the image sub-block based on the second gradient array; and concatenating the gradient weights of the top overlapping region, the all-one weights of the middle non-overlapping region, and the gradient weights of the bottom overlapping region along the vertical direction to generate the vertical weight map.
[0009] According to one embodiment of the present invention, the step of multiplying the initial mask, the horizontal weight map, and the vertical weight map pixel by pixel to generate a target feathering mask with four-sided gradient decay characteristics includes: obtaining an initial value for each pixel position in the initial mask; obtaining a first weight value for each pixel position in the horizontal weight map; obtaining a second weight value for each pixel position in the vertical weight map; multiplying the initial value, the first weight value, and the second weight value to obtain a fusion weight value for each pixel position; and constructing the target feathering mask based on the fusion weight values of all pixel positions.
[0010] According to one embodiment of the present invention, the step of weighting each image sub-block with its corresponding target feathering mask pixel by pixel, and accumulating the weighted sub-blocks onto a blank fusion canvas according to the position information to obtain a fused image, includes: initializing an all-zero matrix matching the enlarged size of the original padded image as the blank fusion canvas; multiplying each image sub-block with its corresponding target feathering mask pixel by pixel to obtain a corresponding weighted image sub-block; determining the target accumulation region on the blank fusion canvas according to the position information corresponding to each weighted image sub-block; and accumulating each weighted image sub-block onto the target accumulation region on the blank fusion canvas to obtain the fused image.
[0011] According to one embodiment of the present invention, constructing the target feathering mask based on the fusion weight values of all pixel positions includes: obtaining the position index of the image sub-block in the original canvas; determining whether the image sub-block belongs to a corner region, an edge region, or a middle region based on the position index; when it is determined to belong to a corner region, only enabling gradient decay calculation for the two edge directions adjacent to the adjacent sub-block, and using the fusion weight value for the weight values corresponding to the two edge directions, while fixing the weight values corresponding to other non-adjacent edge directions to a value of one, to obtain the target feathering mask; when it is determined to belong to an edge region, only enabling gradient decay calculation for one edge direction adjacent to the adjacent sub-block, and using the fusion weight value for the weight value corresponding to the one edge direction, while fixing the weight values corresponding to other non-adjacent edge directions to a value of one, to obtain the target feathering mask; when it is determined to belong to a middle region, enabling gradient decay calculation for all four edge directions, and directly determining the fusion weight value as the target feathering mask.
[0012] Secondly, the present invention also provides an image processing apparatus based on a feathered mask, comprising: an acquisition module for acquiring multiple image sub-blocks that have completed model inference and their position information in the original canvas; an initialization module for initializing a one-dimensional matrix matching its own size for each image sub-block as an initial mask; a horizontal weight calculation module for calculating a first linear gradient weight of the image sub-block in the horizontal direction based on a preset overlapping area size and the magnification factor of the model inference, to obtain a horizontal weight map; a vertical weight calculation module for calculating a second linear gradient weight of the image sub-block in the vertical direction based on the preset overlapping area size and the magnification factor, to obtain a vertical weight map; a mask generation module for multiplying the initial mask, the horizontal weight map, and the vertical weight map pixel by pixel to generate a target feathered mask with four-sided gradient decay characteristics; and a fusion module for weighting each image sub-block and its corresponding target feathered mask pixel by pixel, and accumulating the weighted sub-blocks onto a blank fusion canvas according to the position information to obtain a fused image.
[0013] Thirdly, the present invention also provides a computer device, including 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, it implements an image processing method based on feathering mask as described above.
[0014] Fourthly, the present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements an image processing method based on feathering mask as described above.
[0015] The present invention produces at least the following beneficial effects: By generating component maps with linear gradient weights in both the horizontal and vertical directions independently for each image sub-block, and multiplying the two maps pixel by pixel, a target feathering mask with four-sided gradient decay is constructed for the sub-block. This method ensures that corresponding pixels in the overlapping area of adjacent sub-blocks satisfy a complementary weight relationship, reducing the obvious seam lines produced at the stitching points in traditional simple averaging or fixed-weight fusion, thereby improving the visual coherence of the fused image. Attached Figure Description
[0016] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1This is a flowchart of an image processing method based on feathering mask according to an embodiment of the present invention; Figure 2 yes Figure 1 A schematic diagram of a specific implementation method for step S20; Figure 3 yes Figure 1 A schematic diagram of a specific implementation method for step S30; Figure 4 yes Figure 1 A schematic diagram of a specific implementation of step S40; Figure 5 yes Figure 1 A schematic diagram of a specific implementation method for step S50; Figure 6 yes Figure 1 A schematic diagram of a specific implementation method for step S60; Figure 7 yes Figure 5 A flowchart illustrating a specific implementation of step S55; Figure 8 This is a schematic block diagram of an image processing device based on feathering mask according to an embodiment of the present invention. Detailed Implementation
[0018] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0019] It should be understood that, when used in this specification and the appended claims, the terms “comprising” and “including” indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more of its features, integrals, steps, operations, elements, components and / or collections thereof.
[0020] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.
[0021] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0022] To facilitate the description of this application, the following concepts related to this application are introduced.
[0023] Feathering mask: In image processing, it refers to a matrix with the same size as the image, where each element represents the weight coefficient of the corresponding pixel during fusion or overlay. In this application, it specifically refers to a weight matrix generated for each image sub-block, which has linear gradient decay characteristics in the four edge directions, and is used to achieve smooth transitions between sub-blocks.
[0024] Linear gradient weights: refer to a distribution pattern in which the weight values change linearly and continuously along a certain direction (such as from left to right or from top to bottom). In the scheme of this application, weights are used to generate linearly increasing weights from the edge inward (0) to the non-overlapping area (1) in the overlapping area of image sub-blocks, so as to achieve complementary weights between adjacent sub-blocks.
[0025] Four-sided gradient decay refers to the characteristic that a two-dimensional weight matrix exhibits a linearly increasing weight distribution from the boundary to the interior in all four edge directions (top, bottom, left, and right).
[0026] Position adaptation refers to a technique that dynamically adjusts the processing strategy or parameters of an image sub-block based on its position (such as corner, edge, or center) within the complete image grid. In this application, gradient attenuation is enabled on which edge directions based on the sub-block's position to optimize the fusion effect.
[0027] Weighted fusion: refers to the technique of combining multiple image data pixels by pixel according to their corresponding weight coefficients to synthesize a new image. In this application, it specifically refers to the process of multiplying each image sub-block with its corresponding feathering mask and then accumulating the results onto the global canvas to eliminate stitching seams.
[0028] This application provides an image processing method based on feathering masks, referring to... Figure 1 ,include: S10: Obtain multiple image sub-blocks that have completed model inference and their position information in the original canvas.
[0029] The purpose of this step is to collect all intermediate processing results to be fused and their spatial relationships. Specifically, the system receives multiple image sub-blocks from the output of the preceding image block inference process. Each sub-block is a three-dimensional array with dimensions H × W × C, where H is the sub-block height (number of pixels), W is the sub-block width (number of pixels), and C is the number of color channels. Simultaneously, the original starting coordinates (y_i, x_i) of each sub-block in the preprocessing stage (e.g., the image after edge patching) are obtained, forming a list of positional information. This information collectively defines the spatial arrangement of all sub-blocks in the final complete image. S20: For each of the image sub-blocks, initialize an all-one matrix that matches its own size as an initial mask.
[0030] The purpose of this step is to create a base weight template for each sub - block. Specifically, for each image sub - block, its height H and width W are read. A two - dimensional matrix with the shape of (H, W) is created, and all elements of this matrix are filled with the value 1. This all - one matrix is determined as the initial mask of the sub - block, representing that under the condition of no special weight intervention, the default weight of all pixels in the sub - block is 1.
[0031] S30: Based on the preset overlapping region size and the magnification factor of model inference, calculate the first linear gradient weight of the image sub - block in the horizontal direction to obtain the horizontal direction weight map.
[0032] The purpose of this step is to generate a weight gradient of the sub - block in the horizontal left - right direction. Specifically, obtain the height - direction size overlapH, width - direction size overlapW of the preset overlapping region and the model magnification factor scale. Calculate the magnified horizontal overlapping pixel width N_w = overlapW×scale. Generate an array grad_hor=np.linspace(0, 1, N_w) with a length of N_w that linearly increases from 0 to 1. For each position index x in the width direction of the sub - block, according to its distance from the left and right boundaries, assign weights: If 0 <= x < N_w (left overlapping region), then the weight: If N_w <= x < W_sub - N_w (middle non - overlapping region), then W_hor(x)=1; if x >= W_sub - N_w (right overlapping region), then the weight: Combine the horizontal weights at all x positions to obtain the horizontal direction weight map W_hor_map.
[0033] S40: Based on the preset overlapping region size and the magnification factor, calculate the second linear gradient weight of the image sub - block in the vertical direction to obtain the vertical direction weight map.
[0034] The purpose of this step is to generate a weight gradient of the sub - block in the vertical (up - down) direction. Specifically, calculate the magnified vertical overlapping pixel height N_h = overlapH×scale. Generate an array grad_ver=np.linspace(0, 1, N_h) with a length of N_h that linearly increases from 0 to 1. For each position index y in the height direction of the sub - block, according to its distance from the upper and lower boundaries, assign weights: If 0 <= y < N_h (top overlapping region), then the weight: If \(N_h\leq y < H_{sub}-N_h\) (the middle non - overlapping area), then \(W_{ver}(y) = 1\); If \(y\geq H_{sub}-N_h\) (the bottom overlapping area), then the weight: Combine the vertical weights at all \(y\) positions to obtain the vertical weight map \(W_{ver\_map}\).
[0035] S50: Multiply the initial mask, the horizontal weight map, and the vertical weight map pixel - by - pixel to generate a target feathering mask with four - side gradient attenuation characteristics.
[0036] The purpose of this step is to combine three weight components to form the final two - dimensional feathering mask. Specifically, for each pixel position \((y,x)\) in the image sub - block, read the value \(V_{base}\) (constantly 1) of the initial mask \(mask_{base\_i}\) at this position, the value \(V_{hor}\) of the horizontal weight map \(W_{hor\_map}\) at this position, and the value \(V_{ver}\) of the vertical weight map \(W_{ver\_map}\) at this position. Calculate the fused weight value \(V_{final}=V_{base}\times V_{hor}\times V_{ver}\). Since \(V_{base}\) is 1, essentially \(V_{final}=V_{hor}\times V_{ver}\). Perform this calculation for all pixels in the sub - block, and construct the obtained weight value matrix as the target feathering mask \(mask_{final\_i}\). This mask shows a gradient attenuation characteristic of linearly increasing from the edge to the inside in all four edge directions (left, right, up, down).
[0037] S60: Weight each of the image sub - blocks pixel - by - pixel with its corresponding target feathering mask, and accumulate the weighted sub - blocks onto the blank fusion canvas according to the position information to obtain the fused image.
[0038] The purpose of this step is to smoothly composite all sub-blocks into a single complete image using the generated feathering mask. Specifically, a zero-matrix canvas with dimensions matching the enlarged size of the original padded image is initialized as a blank fusion canvas. For each image sub-block `sub_i` and its corresponding target feathering mask `mask_final_i`, a pixel-wise multiplication operation `weighted_sub_i = sub_i × mask_final_i` is performed to obtain a weighted image sub-block. Based on the sub-block's position information (y_i, x_i), its target accumulation region on the canvas is determined. The pixel values of `weighted_sub_i` are accumulated into this region of the canvas. After performing this operation on all sub-blocks, the pixel values in the overlapping region of the canvas are the sum of the weighted values of adjacent sub-blocks, resulting in the fused image `fused_image`. Because the target feathering mask `mask_final_i` generated by this method has linear gradient characteristics, it enables smooth fusion of adjacent image sub-blocks in the overlapping region. Specifically, for any two horizontally adjacent sub-blocks A and B, let the pixel width of the enlarged horizontal overlapping region be N_w (i.e., overlapW × scale). Within the overlapping region, for any position x (0 ≤ x < N_w) counting inward from the right edge of sub-block A, the mask weight W_A(x) of sub-block A at that position is 1 - x / (N_w-1), while the mask weight W_B(x) of sub-block B at the corresponding position is x / (N_w-1). Therefore, W_A(x) + W_B(x) = 1. Similarly, the same complementary weight relationship is satisfied in the vertical overlapping region. This complementary weight characteristic ensures that when all weighted sub-blocks are accumulated onto the blank blended canvas, the values of corresponding pixels within the overlapping region are formed by superimposing adjacent sub-blocks according to complementary weights. This allows for a natural transition of pixel values in the region, helping to eliminate the seam effect and obtain a visually coherent blended image (fused_image).
[0039] The embodiments of this application employ the above method, which produces at least the following beneficial effects: By generating component maps with linear gradient weights in both the horizontal and vertical directions independently for each image sub-block, and multiplying the two maps pixel by pixel, a target feathering mask with four-sided gradient decay is constructed for the sub-block. This method ensures that corresponding pixels in the overlapping area of adjacent sub-blocks satisfy a complementary weight relationship, reducing the obvious seam lines produced at the stitching points in traditional simple averaging or fixed-weight fusion, thereby improving the visual coherence of the fused image.
[0040] By precisely accumulating the weighted results based on the starting coordinates of the sub-blocks' positions into the corresponding areas of the global fusion canvas, spatial alignment and compositing of multiple sub-blocks are achieved. This method reduces the probability of image content ghosting or fragmentation caused by positional misalignment, and improves the structural integrity of the synthesized image.
[0041] This method can be applied to the digitization and enhancement of large-format pathological sections in medical image analysis. After performing block-based enhancement processing on the scanned high-resolution pathological sections, this method can achieve the fusion of sub-blocks through quadrilateral feathering masks, reducing the possibility of artificial stitching marks at the junctions of cell tissues, thereby improving the accuracy of subsequent computer-aided diagnostic algorithm analysis.
[0042] This method can be applied to image stitching scenarios in graphic design and high-definition printing. When multiple captured or rendered images need to be stitched together into a large-size poster or background image, this method can reduce color and brightness differences between sub-images, achieve smooth transitions, reduce the workload of manual image retouching, and improve the overall quality of the final product.
[0043] refer to Figure 2 In some embodiments, step S20 includes: S21: Get the total number of first pixels H_sub in the height direction and the total number of second pixels W_sub in the width direction of the current image sub-block.
[0044] S22: Create a two-dimensional matrix mask_base with the total number of the first pixels H_sub as the number of rows and the total number of the second pixels W_sub as the number of columns.
[0045] S23: Set all element values in the two-dimensional matrix mask_base to the value one, and determine the two-dimensional matrix as the initial mask of the current image sub-block.
[0046] The purpose of this step is to establish a baseline template where all pixels have a weight of 1. The specific implementation steps are as follows: The first step is to read the sub-block size: extract the height H_sub and width W_sub from the array shape attribute of the image sub-block sub_i.
[0047] The second step is to create a matrix: call an array creation function, such as numpy.ones((H_sub,W_sub)) in Python, to generate a two-dimensional matrix mask_base with shape (H_sub,W_sub) and all elements being 1.
[0048] The third step is to specify the output: use the created all-one matrix mask_base as the initial mask output for this sub-block, for use in subsequent steps.
[0049] By creating an all-one matrix as an initial mask for each sub-block, this step provides a neutral baseline for subsequent gradient weight modulation. This method reduces the complexity of the initialization logic, thus providing a clear and uniform starting point for subsequent combined calculations of horizontal and vertical gradients.
[0050] refer to Figure 3 In some embodiments, step S30 includes: S31: Calculate the pixel width N_w of the magnified horizontal overlapping area based on the product of the overlapping area size overlapW and the magnification factor scale.
[0051] S32: Based on the pixel width N_w of the horizontally overlapping region, generate a first gradient array grad_hor that linearly increases from zero to one. Specifically, it can be implemented using np.linspace(0,1,N_w).
[0052] S33: Based on the first gradient array grad_hor, map corresponding gradient weights to the left and right overlapping regions of the image sub-block, respectively. For the left region (x from 0 to N_w-1), the weights are: For the right-hand region (x from W_sub-N_w to W_sub-1), the weights are: S34: Concatenate the gradient weights of the overlapping region on the left, the uniform weights of the non-overlapping region in the middle, and the gradient weights of the overlapping region on the right along the horizontal direction to generate the horizontal weight map W_hor_map. That is, W_hor_map is a one-dimensional array of length W_sub, whose values are arranged in the order [W_left(0),...,W_left(N_w-1),1,...,1,W_right(W_sub-N_w),...,W_right(W_sub-1)].
[0053] The specific implementation steps are as follows: The first step is to calculate the overlap width: multiply the original overlap width overlapW by the model magnification factor scale to obtain the actual overlap pixel width N_w on the magnified sub-block.
[0054] The second step is to generate a linear array: using a linear interpolation function, an array containing N_w elements is generated, with the element values increasing uniformly from 0 to 1. For example, grad_hor=[0,1 / (N_w-1),2 / (N_w-1),...,1].
[0055] The third step is weight mapping and concatenation: Based on the sub-block width W_sub, construct an initial array of all 1s. Assign the grad_hor array forward to the first N_w positions (left overlapping area) of this initial array, and assign the grad_hor array backward to the last N_w positions (right overlapping area). The middle W_sub-2×N_w positions remain 1.
[0056] By generating a gradient array using linear interpolation and precisely mapping it to the overlapping areas of the sub-blocks, this step achieves a smooth and controllable gradient of the horizontal weights. This method reduces the abrupt fusion boundaries caused by using fixed or discrete weights, thus providing a pixel-level smooth transition basis for reducing horizontal stitching seams.
[0057] refer to Figure 4 In some embodiments, step S40 includes: S41: Calculate the pixel height N_h of the magnified vertical overlapping area based on the product of the overlapping area size overlapH and the magnification factor scale.
[0058] S42: Based on the pixel height N_h of the vertically overlapping region, generate a second gradient array grad_ver that linearly increases from zero to one. Specifically, this can be implemented using np.linspace(0,1,N_h).
[0059] S43: Based on the second gradient array grad_ver, map the corresponding gradient weights to the top and bottom overlapping regions of the image sub-block, respectively. For the top region (y from 0 to N_h-1), the weights are: For the bottom region (y from H_sub-N_h to H_sub-1), the weights are: S44: The gradient weights of the top overlapping region, the all-one weights of the middle non-overlapping region, and the gradient weights of the bottom overlapping region are concatenated along the vertical direction to generate the vertical weight map W_ver_map. That is, W_ver_map is a one-dimensional array of length H_sub, whose values are arranged in the order [W_top(0),...,W_top(N_h-1),1,...,1,W_bottom(H_sub-N_h),...,W_bottom(H_sub-1)].
[0060] The specific implementation steps are as follows: The first step is to calculate the overlap height: multiply the original overlap height overlapH by the model magnification factor scale to obtain the actual overlap pixel height N_h on the magnified sub-block.
[0061] The second step is to generate a linear array: using a linear interpolation function, generate an array containing N_h elements, with the element values increasing uniformly from 0 to 1.
[0062] The third step is weight mapping and concatenation: Based on the sub-block height H_sub, construct an initial array of all 1s. Assign the grad_ver array forward to the first N_h positions (top overlapping area) of this initial array, and assign the grad_ver array backward to the last N_h positions (bottom overlapping area). The middle H_sub-2×N_h positions remain 1.
[0063] This step achieves a smooth gradient of vertical weights by generating vertical gradient weights using logic symmetrical to the horizontal direction. This method enables smooth blending of sub-blocks at their top and bottom edges, working in conjunction with the horizontal direction to provide another dimension of weight components for constructing a two-dimensional quadrilateral decay feathering mask.
[0064] refer to Figure 5 In some embodiments, step S50 includes: S51: Obtain the initial value V_base for each pixel position (y,x) in the initial mask mask_base_i.
[0065] S52: Obtain the first weight value V_hor corresponding to each pixel position (y, x) in the horizontal weight map W_hor_map. Since W_hor_map is a one-dimensional array, V_hor is actually only related to the column index x.
[0066] S53: Obtain the second weight value V_ver corresponding to each pixel position (y, x) in the vertical weight map W_ver_map. Since W_ver_map is a one-dimensional array, V_ver is actually only related to the row index y.
[0067] S54: Multiply the initial value V_base, the first weight value V_hor, and the second weight value V_ver to obtain the fusion weight value V_final = V_base × V_hor × V_ver for each pixel position.
[0068] S55: Construct the target feathering mask mask_final_i based on the fusion weight value V_final at all pixel positions. That is, mask_final_i is a two-dimensional matrix, where mask_final_i[y,x]=V_final.
[0069] The purpose of this step is to combine horizontal and vertical gradient effects through multiplication. The specific implementation steps are as follows: The first step is value acquisition: For the target pixel (y,x), read V_base (which is always 1) from mask_base_i, read V_hor from the W_hor_map array according to index x, and read V_ver from the W_ver_map array according to index y.
[0070] The second step is pixel-by-pixel calculation: For each (y, x) within the sub-block range, perform a scalar multiplication operation V_final = 1 × V_hor × V_ver. This operation is equivalent to V_final = V_hor × V_ver.
[0071] The third step is matrix construction: All the calculated V_final values are filled into a new two-dimensional array of size (H_sub, W_sub) according to their (y,x) coordinates. This array is the target feathering mask mask_final_i.
[0072] By multiplying the one-dimensional linear weight maps in the horizontal and vertical directions pixel by pixel, this step couples the gradient effects in the two directions into a two-dimensional, four-sided decaying weight surface. The mask generated by this method has the lowest weight in the corner areas, gradually increasing to 1 towards the center, which conforms to the laws of visual transition, thus providing a weighting tool for achieving high-quality fusion.
[0073] refer to Figure 6 In some embodiments, step S60 includes: S61: Initialize an all-zero matrix that matches the enlarged size of the original padded image, as the blank blending canvas. Its size is (H_total, W_total, C), where H_total and W_total are determined by the preprocessing stage.
[0074] S62: Multiply each image sub-block sub_i pixel by its corresponding target feathering mask mask_final_i to obtain the corresponding weighted image sub-block weighted_sub_i. That is, weighted_sub_i = sub_i × mask_final_i, where × represents a channel-wise broadcast multiplication.
[0075] S63: Determine the target accumulation region on the blank fusion canvas based on the position information (y_i, x_i) corresponding to each weighted image sub-block weighted_sub_i.
[0076] S64: Each weighted image sub-block (weighted_sub_i) is accumulated onto the target accumulation region of the blank fusion canvas to obtain the fused image (fused_image).
[0077] This step aims to illustrate the complete process of weighted fusion using feathering masks. The goal of this step is to combine all processed sub-blocks into a single complete image. The specific implementation steps are as follows: The first step is canvas initialization: based on the input of the entire processing flow (such as the size of the image after edge patching (H_pad, W_pad) and the scaling factor). Calculate the final canvas size (H_pad×scale, W_pad×scale, C) and create a canvas array of all zeros.
[0078] The second step is sub-block weighting: For each pair (sub_i, mask_final_i), element-wise multiplication is performed. Since mask_final_i is a two-dimensional matrix, when multiplied with the three-dimensional sub_i, it is automatically broadcast to each color channel.
[0079] The third step is positioning and accumulation: Based on the original starting coordinates (y_i, x_i) of the sub-block (which usually takes into account the magnification factor), calculate its target rectangular area on the canvas. Use array slicing and addition assignment operations to accumulate the value of weighted_sub_i to this area of the canvas.
[0080] This step transforms multiple independent sub-blocks into a single fused image by precisely accumulating the weighted sub-blocks onto the global canvas. This method helps ensure that the pixel values contributed by each sub-block are placed in the correct positions, and due to the weighted design of the mask, the superposition of overlapping areas is smooth, reducing the visual perception of stitching artifacts in the final image.
[0081] refer to Figure 7 In some embodiments, step S55 includes: S551: Obtain the position index (row_idx, col_idx) of the image sub-block in the original canvas. Where row_idx and col_idx represent the row number and column number of the sub-block in the block grid.
[0082] S552: Determine whether the image sub-block belongs to a corner region, an edge region, or a middle region based on the position index (row_idx, col_idx). The determination conditions are as follows: if both row_idx and col_idx are located at the grid boundary (0 or the maximum value), it is a corner region; if only row_idx or only col_idx is located at the grid boundary, it is an edge region; otherwise, it is a middle region.
[0083] S553: When the target is determined to be a corner region, gradient decay calculation is only enabled for the two edge directions adjacent to the adjacent sub-block, and the weight values corresponding to these two edge directions are set to the fused weight value V_final. At the same time, the weight values corresponding to other non-adjacent edge directions are fixed to the value one, thus obtaining the target feathering mask. For example, gradient decay is enabled only for the right and bottom edges of the top left corner sub-block.
[0084] S554: When a region is determined to be an edge region, gradient decay calculation is only enabled for one edge direction adjacent to the adjacent sub-block, and the weight value corresponding to that edge direction is set to the fused weight value V_final. At the same time, the weight values corresponding to other non-adjacent edge directions are fixed to the value one, thus obtaining the target feathering mask. For example, gradient decay is enabled only at the bottom edge of the top edge sub-block.
[0085] S555: When it is determined to belong to the middle region, gradient decay calculation is enabled for all four edge directions, and the fusion weight value V_final is directly determined as the target feathering mask.
[0086] The specific implementation steps are as follows: The first step is position resolution: the logical coordinates (i,j) of the sub-block in the block grid are resolved from the position information of the sub-block.
[0087] The second step is region determination: obtain the total number of rows numH and the total number of columns numW of the grid. If i=0 and j=0, it is the top left corner; if i=0 and j=numW-1, it is the top right corner; if i=numH-1 and j=0, it is the bottom left corner; if i=numH-1 and j=numW-1, it is the bottom right corner. If i=0 or i=numH-1 or j=0 or j=numW-1 but is not a corner, then it is an edge sub-block. Otherwise, it is a middle sub-block.
[0088] The third step is adaptive mask adjustment: For corner sub-blocks, after calculating V_final = V_hor × V_ver, the directional weights of sub-blocks without adjacent nodes are forcibly set to 1 based on their specific positions. For example, for the top-left corner sub-block, which has no adjacent nodes on its top and left, its mask is modified to: mask_final_i = np.ones((H_sub, W_sub)) (all 1s), and then only the area in the right N_w column and the bottom N_h row is replaced with the calculated V_final value. The adjustment logic for edge sub-blocks and middle sub-blocks is similar.
[0089] This step optimizes the fusion weight allocation for image boundary regions by introducing adaptive mask adjustment based on sub-block location. This method reduces unnecessary weight decay in corner and edge sub-blocks in non-adjacent directions, thereby improving the overall brightness uniformity of the final fused image and reducing the possibility of unnecessary vignetting or brightness loss around the image perimeter.
[0090] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0091] Reference Figure 8 This invention provides an image processing apparatus 100 based on feathering masks, comprising: The acquisition module 101 is used to acquire multiple image sub-blocks that have completed model inference and their position information in the original canvas; The initialization module 102 is used to initialize a one-dimensional matrix matching its own size for each of the image sub-blocks as an initial mask; The horizontal weight calculation module 103 is used to calculate the first linear gradient weight of the image sub-block in the horizontal direction based on the preset overlapping area size and the magnification factor of the model inference, so as to obtain the horizontal weight map. The vertical weight calculation module 104 is used to calculate the second linear gradient weight of the image sub-block in the vertical direction based on the preset overlapping area size and the magnification factor, so as to obtain a vertical weight map. The mask generation module 105 is used to multiply the initial mask, the horizontal weight map and the vertical weight map pixel by pixel to generate a target feathered mask with four-sided gradient decay characteristics. The fusion module 106 is used to perform pixel-by-pixel weighting of each image sub-block and its corresponding target feathering mask, and to accumulate the weighted sub-blocks onto the blank fusion canvas according to the position information to obtain the fused image.
[0092] For specific limitations regarding the feathering mask-based image processing apparatus 100, please refer to the limitations of the feathering mask-based image processing method described above, which will not be repeated here. Each module in the aforementioned feathering mask-based image processing apparatus 100 can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0093] This invention also provides a computer device, which includes a processor, a memory, a network interface, and a database connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile and / or volatile storage media and internal memory. The non-volatile storage media stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The network interface communicates with external clients via a network connection. When the computer program is executed by the processor, it implements the functions or steps of the feathering mask-based image processing method provided in the above embodiments.
[0094] This invention also provides a computer-readable storage medium storing a computer program that, when executed, can implement the functions or steps of the feathering mask-based image processing method provided in the above embodiments.
[0095] It should be noted that the functions or steps that can be implemented by the computer-readable storage medium or computer device described above can be referred to the relevant descriptions on the server side and client side in the foregoing method embodiments. To avoid repetition, they will not be described one by one here.
[0096] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0097] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is used as an example. In practical applications, the above functions can be assigned to 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.
[0098] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.
Claims
1. An image processing method based on feathering mask, characterized in that, include: Obtain multiple image sub-blocks that have completed model inference and their position information in the original canvas; For each of the image sub-blocks, initialize an all-one matrix that matches its own size as an initial mask; Based on the preset overlapping region size and the magnification factor of the model inference, the first linear gradient weight of the image sub-block in the horizontal direction is calculated to obtain the horizontal weight map. Based on the preset overlapping region size and the magnification factor, the second linear gradient weight of the image sub-block in the vertical direction is calculated to obtain the vertical weight map; The initial mask, the horizontal weight map, and the vertical weight map are multiplied pixel by pixel to generate a target feathered mask with four-sided gradient decay characteristics. Each image sub-block is weighted pixel-by-pixel with its corresponding target feathering mask, and the weighted sub-blocks are accumulated onto the blank fusion canvas according to the position information to obtain the fused image.
2. The image processing method based on feathering mask according to claim 1, characterized in that, The initialization of a one-dimensional matrix matching its own size as an initial mask for each of the image sub-blocks includes: Get the total number of pixels in the height direction and the total number of pixels in the width direction of the current image sub-block; Create a two-dimensional matrix with the total number of the first pixels as the number of rows and the total number of the second pixels as the number of columns; Set all element values in the two-dimensional matrix to the value 1, and use the two-dimensional matrix as the initial mask for the current image sub-block.
3. The image processing method based on feathering mask according to claim 1, characterized in that, The first linear gradient weight of the image sub-block in the horizontal direction is calculated based on the preset overlapping region size and the magnification factor of the model inference, resulting in a horizontal weight map, including: The pixel width of the magnified horizontal overlapping region is calculated based on the product of the overlapping region size and the magnification factor. Based on the pixel width of the horizontal overlapping region, a first gradient array is generated that linearly increases from zero to one. Based on the first gradient array, corresponding gradient weights are mapped to the left and right overlapping regions of the image sub-block, respectively. The gradient weights of the overlapping region on the left, the uniform weights of the non-overlapping region in the middle, and the gradient weights of the overlapping region on the right are spliced together along the horizontal direction to generate the horizontal weight map.
4. The image processing method based on feathering mask according to claim 1, characterized in that, The step of calculating the second linear gradient weight of the image sub-block in the vertical direction based on the preset overlapping region size and the magnification factor to obtain a vertical weight map includes: The pixel height of the magnified vertical overlapping region is calculated based on the product of the overlapping region size and the magnification factor. Based on the pixel height of the vertical overlapping region, a second gradient array is generated that linearly increases from zero to one. Based on the second gradient array, corresponding gradient weights are mapped to the top and bottom overlapping regions of the image sub-blocks, respectively; The gradient weights of the top overlapping region, the uniform weights of the middle non-overlapping region, and the gradient weights of the bottom overlapping region are concatenated along the vertical direction to generate the vertical weight map.
5. The image processing method based on feathering mask according to claim 1, characterized in that, The step of multiplying the initial mask, the horizontal weight map, and the vertical weight map pixel by pixel to generate a target feathering mask with four-sided gradient decay characteristics includes: Obtain the initial value for each pixel position in the initial mask; Obtain the first weight value for each pixel position in the horizontal weighted image; Obtain the second weight value for each pixel position in the vertical weight map; The initial value, the first weight value, and the second weight value are multiplied together to obtain the fusion weight value for each pixel position; The target feathering mask is constructed based on the fusion weight values of all pixel locations.
6. The image processing method based on feathering mask according to claim 1, characterized in that, The step of weighting each image sub-block and its corresponding target feathering mask pixel by pixel, and then accumulating the weighted sub-blocks onto the blank fusion canvas according to the position information to obtain the fused image includes: Initialize an all-zero matrix that matches the enlarged size of the original edge-padded image, and use it as the blank blending canvas; Each image sub-block is multiplied pixel-by-pixel with its corresponding target feathering mask to obtain the corresponding weighted image sub-block; Based on the position information corresponding to each weighted image sub-block, determine its target accumulation region on the blank fusion canvas; Each weighted image sub-block is cumulatively added to the target accumulation area of the blank fusion canvas to obtain the fused image.
7. The image processing method based on feathering mask according to claim 5, characterized in that, The process of constructing the target feathering mask based on the fusion weight values of all pixel positions includes: Obtain the position index of the image sub-block in the original canvas; Based on the location index, it is determined whether the image sub-block belongs to a corner region, an edge region, or a middle region; When it is determined to be a corner region, gradient decay calculation is only enabled for the two edge directions adjacent to the adjacent sub-block, and the weight values corresponding to the two edge directions are fused weight values. At the same time, the weight values corresponding to other non-adjacent edge directions are fixed to the value of one, thus obtaining the target feathering mask. When it is determined to belong to the edge region, gradient decay calculation is only enabled for one edge direction adjacent to the adjacent sub-block, and the weight value corresponding to that edge direction is the fused weight value. At the same time, the weight values corresponding to other non-adjacent edge directions are fixed to the value of one, so as to obtain the target feathering mask. When it is determined to belong to the middle region, gradient decay calculation is enabled for all four edge directions, and the fusion weight value is directly determined as the target feathering mask.
8. An image processing apparatus based on feathering mask, characterized in that, include: The acquisition module is used to acquire multiple image sub-blocks that have completed model inference and their position information in the original canvas; An initialization module is used to initialize a one-dimensional matrix matching its own size for each of the image sub-blocks as an initial mask; The horizontal weight calculation module is used to calculate the first linear gradient weight of the image sub-block in the horizontal direction based on the preset overlapping region size and the magnification factor of the model inference, so as to obtain the horizontal weight map. The vertical weight calculation module is used to calculate the second linear gradient weight of the image sub-block in the vertical direction based on the preset overlapping region size and the magnification factor, so as to obtain the vertical weight map; The mask generation module is used to multiply the initial mask, the horizontal weight map, and the vertical weight map pixel by pixel to generate a target feathered mask with four-sided gradient decay characteristics. The fusion module is used to perform pixel-by-pixel weighting of each image sub-block and its corresponding target feathering mask, and to accumulate the weighted sub-blocks onto the blank fusion canvas according to the position information to obtain the fused image.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the image processing method based on feathering mask as described in any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the image processing method based on feathering mask as described in any one of claims 1 to 7.