A zero-sample multi-focus image fusion method, device, equipment and storage medium based on SAM
Mask generation and fusion processing are performed through the SAM model to achieve zero-sample multi-focus image fusion, which solves the problems of dependence on gold standard data and insufficient generalization ability in the existing technology, and improves the accuracy and quality of image fusion.
Patent Information
- Application Number
- CN202410947977.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-16
- Publication Date
- 2024-10-08
- Estimated Expiration
- 2044-07-16
AI Technical Summary
Existing multi-focus image fusion technology requires a large amount of gold standard fusion data for supervised training of deep learning models, and has limited generalization capabilities, making it difficult to cope with complex blur situations in the real world.
A zero-shot multi-focus image fusion method based on Segment Anything Model (SAM) is used to achieve weighted average fusion of images through mask generation, matching, foreground and background assignment, voting decision-making and optimization processing, avoiding reliance on a large amount of gold standard data. .
Without relying on a large number of gold standard fusion images, the accuracy and generalization of multi-focus image fusion is improved, the problems of edge blur, information loss and artifacts are solved, and high-quality multi-focus image fusion is achieved.
Smart Images

Figure CN118485902B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and in particular to a zero-sample multi-focus image fusion method, device, equipment and storage medium based on SAM. Background Art
[0002] In traditional optical imaging systems, due to the physical properties of the lens, only objects within the depth of field can remain clear, and objects beyond the depth of field will appear blurred. In order to overcome this limitation, multi-focus image fusion technology came into being. The core idea of this technology is to shoot the scene at different depth levels, and then synthesize these images with different focal planes into a clear image with full focus. The synthesized image will contain all the clear parts of the original image, thus providing an overall visual effect that is clear from the foreground to the background. Multi-focus image fusion is of great significance in many fields. In the field of medical imaging, multi-focus image fusion can be used to enhance the details of tissues and organs, such as in microscope images, endoscopic images or three-dimensional reconstruction, to ensure that the entire observation area is clear and improve the accuracy of doctors' diagnosis. In military reconnaissance and monitoring systems, multi-focus image fusion can provide more comprehensive and clear image information, helping military personnel to better analyze and judge. In addition, in the fields of industrial inspection, satellite remote sensing and unmanned driving, multi-focus image fusion can also improve the efficiency and accuracy of image processing, and provide better visual solutions for related industries.
[0003] At present, the multi-focus image fusion technology mainly includes traditional fusion methods and deep learning fusion methods. Traditional fusion methods include transform domain-based methods and spatial domain-based methods. Transform domain-based methods generally consist of three stages, namely image transformation, coefficient fusion and inverse transformation. First, the source image is converted from the spatial domain to the transform domain by applying appropriate transformations, such as discrete cosine transform DCT, discrete wavelet transform DWT, discrete Fourier transform DFT, etc. Then, the transformed coefficients are merged through a pre-designed fusion strategy, which includes steps such as activity level measurement, fusion rules and consistency verification. Finally, the fused image is reconstructed by performing the corresponding inverse transformation on the fusion coefficients. Transform domain-based methods may cause information loss or deformation when converting images to transform domains, thereby affecting the quality and details of the image. In addition, image transformation also increases the complexity and computational burden of the algorithm. The spatial domain-based method abandons the complex transformation process and operates directly at the pixel level. It generates a weighted average of the source image by generating a weight map, which is divided into two major strategies: block-based and region-based. Although these strategies are intuitive and can preserve image details well, they are highly dependent on accurate region division and control of block effects. Especially in complex scenes, they require a lot of prior knowledge and are difficult to achieve universally applicable solutions. Whether it is a transform domain-based method or a spatial domain-based method, the feature extraction process relies more on manual design, which requires complex mathematical knowledge, and the designed methods are usually only applicable to specific application scenarios, with poor generalization and robustness, and are difficult to deal with diverse images.
[0004] In this context, deep learning fusion methods have brought new perspectives to multi-focus image fusion with their powerful automatic feature learning capabilities. Using models such as convolutional neural networks (CNNs), autoencoders, or generative adversarial networks (GANs), deep learning methods can directly learn the intrinsic associations of multi-focus images from a large amount of annotated data, achieve full-focus image synthesis by optimizing the loss function, get rid of complex manual prior designs, and greatly improve generalization capabilities. However, deep learning methods require a large amount of supervised data to train the model, and it is difficult to build a gold standard multi-focus image dataset, which is a major obstacle to the development and growth of deep learning methods in the field of multi-focus image fusion.
[0005] Chinese patent document CN 113822828 A discloses a multi-focus image fusion method, which first reshapes the original image to a uniform size and converts the semantic label into a binary label. Then, images of different blur levels are generated through Gaussian blur processing. According to the binary label, the original image is combined with the multi-level blurred image to create a positive and negative sample data set for training the network model. After training, the two registered source images are input into the model to produce their corresponding score maps. By comparing these score maps, a decision map is generated to guide the image fusion process. In the fusion process, a guided filtering algorithm is first applied based on the decision map and the preliminary fused image to generate a high-quality guided map, effectively remove boundary artifacts, and improve the visual effect of the fused image. Finally, the guided map and the source image are weighted averaged to obtain the final fused image.
[0006] Chinese patent document CN 116452476 A discloses a multi-focus image fusion method, device, equipment and medium. The document first obtains multiple images of different focus points in the target scene. Then, a trained mask model is used to enhance the focus area and defocus area in these images to generate a first enhanced image. Then, the first enhanced image is further processed by a guided filter to obtain a second enhanced image by transferring high-frequency information. Finally, all the second enhanced images are fused to generate a final fused image.
[0007] The fusion methods mentioned in the above two patent documents need to undergo a lot of training on specific data sets before they can complete the task of multi-focus image fusion. Among them, the Chinese patent document CN 113822828 A constructs a synthetic data set through the Gaussian blur method, and then uses supervised training to obtain a decision graph for image fusion. However, Gaussian blur is usually based on a simplified assumption that the blur follows a Gaussian distribution, but the blur effect of multi-focus images obtained in real scenes may be caused by a variety of complex factors. The blur patterns caused by these factors are more complex and anisotropic, which cannot be accurately captured by Gaussian blur. In addition, when synthesizing blurred boundaries, the transition from clear to blurred is too abrupt, which is inconsistent with the actual gradient effect of the blurred boundaries in real images. This not only limits the diversity of training data, but also may weaken the generalization ability of the model, making it perform poorly when facing various blurry situations that are widely present in the real world. Chinese patent document CN 116452476A abandons the method of constructing a synthetic dataset and reduces the dependence on large-scale labeled data by constructing a self-supervised task. However, it still requires a large amount of data for training. The size of the dataset will determine its performance. Limited by the size of its dataset, this type of method is difficult to achieve good generalization ability, let alone zero-sample image fusion.
[0008] Therefore, it is necessary to establish a zero-shot multi-focus image fusion method that does not require training and has the powerful performance of deep learning. Summary of the invention
[0009] In view of the problem that existing multi-focus image fusion methods are difficult to obtain gold standard fusion data for supervised training of deep learning models, the present invention provides a zero-sample multi-focus image fusion method, device, equipment and storage medium based on SAM, which realizes clear fusion of multi-focus images without relying on a large number of gold standard fusion images and image acquisition, overcomes the limitations of traditional fusion methods and deep learning fusion methods, and greatly improves the accuracy and generalization of multi-focus image fusion algorithms.
[0010] To achieve the above object, the present invention adopts the following technical solutions:
[0011] In a first aspect of the present invention, a zero-sample multi-focus image fusion method based on SAM is disclosed. The method comprises the following steps:
[0012] S1. Mask generation: Use the SAM model to segment two source images of the same scene respectively to obtain a set of segmentation masks for each image.
[0013] S2, mask matching: Calculate the intersection-and-union ratio of all mask pairs from different segmentation mask sets, and match the masks pointing to the same visual area according to the intersection-and-union ratio to form a set of matched mask pairs.
[0014] S3. Foreground and background assignment: Based on the set of matched mask pairs, compare the clarity of the overlapping areas of each pair of matching masks in the two source images, pre-mark the overlapping areas according to the clarity scores, and obtain the assigned mask set.
[0015] S4, voting decision: A pixel-by-pixel voting mechanism is used to integrate the foreground and background information of each assigned mask in the assigned mask set to obtain an initial decision mask.
[0016] S5, optimization processing: use morphological operations and guided filtering methods to optimize the initial decision mask to obtain the final decision mask.
[0017] S6. Image fusion: Based on the final decision mask, a weighted average method is used to obtain the fused image.
[0018] Preferably, in step S1, the use of the SAM model to segment two source images of the same scene respectively to obtain a segmentation mask set for each image includes:
[0019] The source images I1 and I2 of the same scene are respectively input into the SAM model, and all possible potential objects or regions in each source image are segmented out, thereby obtaining a segmentation mask set for each source image, and the masks in each segmentation mask set are sorted by area size.
[0020] The step S1 is implemented using formula (1) and formula (2):
[0021] (1);
[0022] (2);
[0023] In formula (1) and formula (2), and Respectively represent source image I1 and source image I2; and They respectively represent the segmentation mask sets obtained after the source images I1 and I2 are processed by the SAM model and sorted; Represents a mask sort operation, which sorts elements according to a specific comparison key value; It represents the automatic mask generation operation of SAM, which receives the image to be segmented and automatically generates n binary segmentation masks according to the semantic information of the image, where the value of n is determined by the image content; Represents a mask set The i Zhang mask, Represents a mask set The j Mask.
[0024] Preferably, in step S2, the intersection-and-union ratios of all mask pairs from different segmentation mask sets are calculated, and masks pointing to the same visual area are matched according to the intersection-and-union ratios to form a set of matched mask pairs, including:
[0025] S21. Use formula (3) to calculate the intersection-over-union (IOU) of all mask pairs from different mask sets:
[0026] (3);
[0027] In formula (3), express and The intersection and union ratio of Represents a set of segmentation masks The i Zhang mask, Represents a set of segmentation masks The j Zhang mask; and They respectively represent the segmentation mask sets obtained after the source images I1 and I2 are processed by the SAM model and sorted.
[0028] S22. Sort the intersection-and-union ratios of the mask pairs in descending order, select the mask pairs corresponding to the first N intersection-and-union ratios as matching mask pairs, and form a matching mask pair set; N is a positive integer.
[0029] Preferably, according to the present invention, in step S3, based on the set of matched mask pairs, the clarity of the overlapping areas of each pair of matched masks in the two source images is compared, and the overlapping areas are pre-marked according to the clarity scores to obtain the assigned mask set, including:
[0030] S31. Obtain overlapping area: Based on N matching mask pairs, use formula (4) to obtain the overlapping area of each pair of matching masks:
[0031] (4);
[0032] In formula (4), Representation mask and mask The overlapping area mask of ; Indicates the pixel position; Represents a set of segmentation masks The i Zhang mask; Represents a set of segmentation masks The j Mask.
[0033] S32, calculating the clarity score: using formula (5) and formula (6) to calculate the clarity score of the overlapping area of each pair of matching masks in the source image I1 and the source image I2 respectively:
[0034] (5);
[0035] (6);
[0036] In formula (5) and formula (6), Representation mask The clarity score of the corresponding area in the source image I1; Representation mask The clarity score of the corresponding area in the source image I2; and Respectively represent source image I1 and source image I2; Representation mask and mask The overlapping area mask of ; It is the general form of the expression on the right side of formula (5) and formula (6). The specific calculation process is implemented by formula (7)-formula (10):
[0037] (7);
[0038] (8);
[0039] (9);
[0040] (10);
[0041] In formula (7) to formula (10), Used to quantize a given image In the specified mask The clarity of the image is calculated by In the mask The average value of the gradient strength of all points in the region is achieved; Indicates the pixel position; express The gradient strength at is a weighted combination of the horizontal gradient and the vertical gradient, with the weights given by the parameters Control, 0 ≤ ≤1; and Respectively The gradient amplitude in the horizontal and vertical directions; [ ]and [ ] indicates the application of Sobel operator in the horizontal and vertical directions respectively; Representing images exist The pixel intensity value at ; Representation mask exist The value at .
[0042] S33, foreground and background assignment: According to the clarity score, use formula (11) to assign the foreground and background to the overlapping area of each pair of matching masks, obtain N assigned masks, and obtain the assigned mask set:
[0043] (11);
[0044] In formula (11), Indicated by mask and mask The resulting assignment mask; Indicates the pixel position; Representation mask and mask The overlapping area mask of ; Representation mask The clarity score of the corresponding area in the source image I1; Representation mask The clarity score of the corresponding area in the source image I2; if The value is greater than or equal to , then in the assignment mask The area is pre-marked as foreground, and the pixel value is set to 1; otherwise, The area is pre-marked as background, and the pixel value is set to 0, and the pixel value of the remaining unmarked area is set to None.
[0045] Preferably, in step S4, a pixel-by-pixel voting mechanism is used to integrate the foreground and background information of each assigned mask in the assigned mask set to obtain an initial decision mask, including:
[0046] For any pixel position , use the voting mechanism shown in formula (12) to decide its final ownership and obtain the initial decision mask:
[0047] (12);
[0048] In formula (12), represents the initial decision mask; Indicates the pixel position; Indicates that in N assigned masks, the pixel The mask counts where the value is 1; Indicates that in N assigned masks, the pixel The mask count is not None; if Greater than or equal to , then the pixel point is set in the initial decision mask If it is determined to be a foreground pixel, the pixel value is set to 1; if not, the pixel point is set to 1 in the initial decision mask. Determined as background pixels, the pixel value is set to 0.
[0049] Preferably, according to the present invention, in step S5, the initial decision mask is optimized using morphological operations and guided filtering methods to obtain a final decision mask, including:
[0050] S51, optimizing the initial decision mask using the morphological operation shown in formula (13);
[0051] (13);
[0052] In formula (13), represents the optimized initial decision mask; Indicates the pixel position; Represents the opening operation of a binary image; Indicates the operation of removing small areas; Represents the closing operation of a binary image; represents the initial decision mask; is a structural element, used to define the neighborhood; It is the area ratio parameter, which is used to define the small area.
[0053] S52, based on the guided filter, the optimized initial decision mask is guided filtered using formulas (14) and (15) to smooth the mask and obtain the final decision mask:
[0054] (14);
[0055] (15);
[0056] In formula (14) and formula (15), is the initial fusion image; Indicates the pixel position; represents the optimized initial decision mask; and Respectively represent source image I1 and source image I2; represents the final decision mask; represents the guided filter operation, and are the parameters of the guided filter.
[0057] Preferably, in step S6, based on the final decision mask, a fused image is obtained by weighted averaging, which includes:
[0058] Formula (16) is used to perform weighted averaging on the final decision mask to fuse the source image I1 and the source image I2 to generate a fused image:
[0059] (16);
[0060] In formula (16), is the final fused image; represents the final decision mask; and They represent source image I1 and source image I2 respectively; in the final decision mask, the foreground pixels adopt the pixel values of source image I1, and the background pixels adopt the pixel values of source image I2.
[0061] In a second aspect of the present invention, a zero-sample multi-focus image fusion device based on SAM is disclosed, which includes a mask generation module, a mask matching module, a foreground and background assignment module, a voting decision module, an optimization processing module and an image fusion module.
[0062] The mask generation module is used to segment two source images of the same scene using the SAM model to obtain a segmentation mask set for each image. The mask matching module is used to calculate the intersection-over-union (IOU) of all mask pairs from different segmentation mask sets, and match the masks pointing to the same visual area according to the intersection-over-union (IOU) to form a set of matching mask pairs. The foreground-background assignment module is used to compare the clarity of the overlapping areas of each pair of matching masks in the two source images, and pre-mark the overlapping areas as foreground or background according to the clarity score, and set the pixel values of the non-overlapping areas to None to obtain the assigned mask set. The voting decision module is used to integrate the foreground and background information of each assigned mask in the assigned mask set using a pixel-by-pixel voting mechanism to obtain an initial decision mask. The optimization processing module is used to optimize the initial decision mask using morphological operations and guided filtering methods to obtain a final decision mask. The image fusion module is used to obtain a fused image based on the final decision mask by weighted averaging.
[0063] In a third aspect of the present invention, an electronic device is disclosed, comprising: at least one processor; and a memory, wherein the memory stores instructions, and when the instructions are executed by the at least one processor, the at least one processor executes the above-mentioned SAM-based zero-sample multi-focus image fusion method.
[0064] In a fourth aspect of the present invention, a machine-readable storage medium is disclosed, which stores executable instructions, and when the instructions are executed, the machine executes the above-mentioned SAM-based zero-sample multi-focus image fusion method.
[0065] Compared with the prior art, the advantages of the present invention are:
[0066] The present invention cleverly combines traditional image processing technology and deep learning technology for multi-focus image fusion tasks, and proposes a zero-sample multi-focus image fusion method and system based on SAM. This is the first time that SAM has been used in the field of image fusion, and there is no need to build a data set, so that zero-sample multi-focus image fusion is achieved. The present invention uses pre-trained SAM, whose powerful zero-sample migration ability enables the algorithm to adapt to diverse image content and structure, and achieves clear fusion of multi-focus images without relying on a large number of gold standard fusion images and image acquisition; SAM is used to automatically generate masks of all potential objects or regions in the image, so that there is no need to understand the image characteristics in advance and manually design segmentation strategies, reduce manual operations and a large number of manual priors, and greatly improve the generalization and efficiency of the algorithm. Through clarity evaluation and foreground and background assignment, the present invention can select the clearest source image part for fusion for different areas in the image, thereby improving the quality and clarity of the fused image; a pixel-by-pixel voting mechanism is used to determine the final ownership of pixels, ensuring the accuracy of pixel classification at complex boundaries, and solving the problems of edge blur, information loss, and introduction of artifacts in the fusion results of the current method. BRIEF DESCRIPTION OF THE DRAWINGS
[0067] Figure 1 It is a method flow chart of the zero-sample multi-focus image fusion method based on SAM in the present invention;
[0068] Figure 2 It is a schematic diagram of the zero-sample multi-focus image fusion method based on SAM in the present invention;
[0069] Figure 3 This is the model architecture diagram of SAM;
[0070] Figure 4a is a schematic diagram of the source image I1;
[0071] Figure 4b is a set of segmentation masks The first mask in Schematic diagram;
[0072] Figure 4c is a set of segmentation masks The second mask in Schematic diagram;
[0073] Figure 4d is a set of segmentation masks The third mask in Schematic diagram;
[0074] Figure 4e is a schematic diagram of the source image I2;
[0075] Figure 4f is a set of segmentation masks The first mask in Schematic diagram;
[0076] Figure 4g is a set of segmentation masks The second mask in Schematic diagram;
[0077] Figure 4h is a set of segmentation masks The third mask in Schematic diagram;
[0078] Figure 5a is the maximum IOU corresponding to the set of segmentation masks Schematic diagram of the mask;
[0079] Figure 5b is the maximum IOU corresponding to the set of segmentation masks Schematic diagram of the mask;
[0080] Figure 5c yes Figure 5a and Figure 5b Schematic diagram of the overlapping area;
[0081] Figure 5d yes Figure 5a and Figure 5b Schematic diagram of the assignment mask;
[0082] Figure 5e is a schematic diagram of the initial decision mask;
[0083] Figure 5f is a schematic diagram of the optimized initial decision mask;
[0084] Figure 5g is the schematic diagram of the final decision mask;
[0085] Figure 5h This is a schematic diagram of the final fused image. DETAILED DESCRIPTION
[0086] The present disclosure is further described below with reference to the accompanying drawings and embodiments:
[0087] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present disclosure. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present disclosure belongs.
[0088] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present disclosure. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.
[0089] In the absence of conflict, the embodiments in the present disclosure and the features in the embodiments may be combined with each other.
[0090] Example 1
[0091] In the application scenario of multi-focus image fusion, the same object or objects with similar semantic information in the image usually show consistent focus properties. All you need to do is identify all the objects in the scene, determine which source image each object is clearer in, and fuse the corresponding area into the final result to obtain a full-focus image with all objects clear.
[0092] This embodiment provides a zero-sample multi-focus image fusion method based on SAM. Figure 1 and Figure 2 As shown, the method comprises the following steps:
[0093] S1. Mask generation: Use the SAM model to segment two source images of the same scene respectively to obtain a set of segmentation masks for each image.
[0094] SAM (Segment Anything Model) is a new image segmentation model developed by Meta AI. This model can be used to generate masks of all objects in an image. SAM has been trained on a dataset of 11 million images and 11 billion masks, and has been exposed to extremely diverse images and prompts during training, which enables it to learn rich common features, so that it can still generate accurate segmentation masks when faced with unseen images and tasks. Therefore, SAM has a strong zero-shot migration capability and can achieve zero-shot generalization on new image distributions and tasks. SAM's automatic mask generation function means that the model can automatically identify and generate segmentation masks for all objects in an image without any user-provided prompts (such as points, boxes, or masks).
[0095] In step S1, the two source images of the same scene are segmented respectively using the SAM model to obtain a segmentation mask set for each image, including:
[0096] The source images I1 and I2 of the same scene are respectively input into the SAM model, and all possible potential objects or regions in each source image are segmented out, thereby obtaining a segmentation mask set for each source image, and the masks in each segmentation mask set are sorted by area size.
[0097] The step S1 is implemented using formula (1) and formula (2):
[0098] (1);
[0099] (2);
[0100] In formula (1) and formula (2), and Respectively represent source image I1 and source image I2; and They respectively represent the segmentation mask sets obtained after the source images I1 and I2 are processed by the SAM model and sorted; Represents a mask sort operation, which sorts elements according to a specific comparison key value; It represents the automatic mask generation operation of SAM, which receives the image to be segmented and automatically generates n binary segmentation masks according to the semantic information of the image, where the value of n is determined by the image content; Represents a mask set The i Zhang mask, Represents a mask set The j Mask.
[0101] In this embodiment, the source image I1 is as follows: Figure 4a As shown, the source image I2 is Figure 4e The model architecture diagram of the SAM used in this embodiment is shown in Figure 3 As shown in Figure 1, it consists of an image encoder and a lightweight mask decoder. The first three masks in the segmentation mask set obtained from the source image I1 are like Figure 4b , Figure 4c and Figure 4d As shown, the first three masks in the segmentation mask set obtained from the source image I2 like Figure 4f , Figure 4g , Figure 4h shown.
[0102] S2, mask matching: Calculate the intersection-and-union ratio of all mask pairs from different segmentation mask sets, and match the masks pointing to the same visual area according to the intersection-and-union ratio to form a set of matched mask pairs.
[0103] In step S2, the intersection-and-union ratios of all mask pairs from different segmentation mask sets are calculated, and masks pointing to the same visual area are matched according to the intersection-and-union ratios to form a set of matched mask pairs, including:
[0104] S21. Use formula (3) to calculate the intersection-over-union (IOU) of all mask pairs from different mask sets:
[0105] (3);
[0106] In formula (3), express and The intersection and union ratio of Represents a set of segmentation masks The i Zhang mask, Represents a set of segmentation masks The j Zhang mask; and They represent the segmentation mask sets obtained after the source images I1 and I2 are processed by the SAM model and sorted. In this embodiment, the mask pair corresponding to the maximum IOU is as follows Figure 5a and Figure 5b shown.
[0107] In this embodiment, there are two source images, namely source image I1 and source image I2, and the obtained segmentation mask sets are two groups. In step S21, the IOU (intersection over union) of all mask pairs between the two segmentation mask sets is calculated.
[0108] S22. Sort the intersection-and-union ratios of the mask pairs in descending order, select the mask pairs corresponding to the first N intersection-and-union ratios as matching mask pairs, and form a matching mask pair set; N is a positive integer.
[0109] The larger the IOU value, the higher the overlap of the mask pair, which means that the areas corresponding to the two masks in their respective source images have a higher similarity. This step ensures that subsequent operations can match the same area in the scene. N is a positive integer, and N is set to 100 in this embodiment.
[0110] S3, foreground and background assignment: Based on the set of matched mask pairs, compare the clarity of the overlapping areas of each pair of matching masks in the two source images, pre-mark the overlapping areas according to the clarity scores, and obtain the assigned mask set. In the pre-marking process, the overlapping areas are pre-marked as foreground (pixel value is set to 1) or background (pixel value is set to 0), and the pixel value of the non-overlapping area is set to None.
[0111] In step S3, based on the set of matched mask pairs, the clarity of the overlapping areas of each pair of matched masks in the two source images is compared, and the overlapping areas are pre-marked according to the clarity scores to obtain the assigned mask set, including:
[0112] S31, obtaining overlapping areas: Based on the N matching mask pairs obtained in step S22, the overlapping areas of each mask pair are obtained using formula (4):
[0113] (4);
[0114] In formula (4), Representation mask and mask The overlapping area mask of ; Indicates the pixel position; Represents a set of segmentation masks The i Zhang mask; Represents a set of segmentation masks The j Mask.
[0115] In this embodiment, Figure 5a and Figure 5b The overlapping area of Figure 5c shown.
[0116] S32, calculating clarity scores: respectively calculating clarity scores of overlapping areas of each pair of matching masks in the two source images, or respectively calculating clarity scores of corresponding areas of the smaller mask or the larger mask in each pair of matching masks in the two source images.
[0117] In step S32, the clarity scores of the overlapping areas of each pair of matching masks in the source image I1 and the source image I2 are calculated respectively, using formula (5) and formula (6):
[0118] (5);
[0119] (6);
[0120] In formula (5) and formula (6), Indicates the mask The clarity score of the corresponding area in the source image I1; Representation mask The clarity score of the corresponding area in the source image I2; and Respectively represent source image I1 and source image I2; Representation mask and mask The overlapping area mask of . It is a clarity evaluation function. Its core idea is to calculate the gradient intensity of the image (reflecting the drastic changes in edges and textures) and take the average value as a quantitative indicator of image clarity. It is the general form of the expression on the right side of formula (5) and formula (6). The specific calculation process is implemented by formula (7)-formula (10):
[0121] (7);
[0122] (8);
[0123] (9);
[0124] (10);
[0125] In formula (7) to formula (10), Used to quantize a given image In the specified mask The clarity of the image is calculated by In the mask The average value of the gradient strength of all points in the region is achieved; Indicates the pixel position; express The gradient strength at is a weighted combination of the horizontal gradient and the vertical gradient, with the weights given by the parameters Control, 0 ≤ ≤1; and Respectively The gradient amplitude in the horizontal and vertical directions; [ ]and [ ] indicates the application of Sobel operator in the horizontal and vertical directions respectively; Representing images exist The pixel intensity value at ; Representation mask exist The Sobel operator is an edge detection operator that can effectively capture the gradient changes of local images. In this embodiment, is set to 0.5.
[0126] S33, foreground and background assignment: According to the clarity score, the overlapping area of each pair of matching masks is assigned to the foreground and background using formula (11), and N assignment masks are obtained to obtain an assignment mask set. If the clarity score of the overlapping area in the source image I1 is higher than the clarity score in the source image I2, the area is pre-marked as the foreground (the pixel value is set to 1), otherwise, the area is pre-marked as the background (the pixel value is set to 0), and the pixel values of the remaining unmarked areas are set to None, thereby obtaining an assignment mask.
[0127] (11);
[0128] In formula (11), Indicated by mask and mask The resulting assignment mask; Indicates the pixel position; Representation mask and mask The overlapping area mask of ; Representation mask The clarity score of the corresponding area in the source image I1; Representation mask The clarity score of the corresponding area in the source image I2; if The value is greater than or equal to , then in the assignment mask The area is pre-marked as foreground, and the pixel value is set to 1; otherwise, The area is pre-marked as background, and the pixel value is set to 0, and the pixel values of the remaining areas are set to None.
[0129] Figure 5a and Figure 5b The assignment mask is Figure 5d shown. Note: Figure 5d The pixel value of the unmarked area (white visual area) is None instead of 1.
[0130] S4, voting decision: A pixel-by-pixel voting mechanism is used to integrate the foreground and background information of each assigned mask in the assigned mask set to obtain an initial decision mask.
[0131] After completing the foreground and background assignment, it is necessary to integrate these N independent assignment masks into a unified mask to guide the final image fusion. In the multi-focus fusion task, the source image can be roughly divided into three areas, namely the focus area, the defocus area and the uncertain area. The uncertain area usually exists at the boundary of the focus and defocus area of the image, and contains the pixels of the image focus and defocus. The classification of these pixels is more difficult. Therefore, in order to achieve a good fusion effect, it is necessary to carefully classify each pixel. In the algorithm proposed in the present invention, a voting mechanism is adopted to decide the final ownership of each pixel.
[0132] Specifically, for any pixel position (x, y), the voting mechanism shown in formula (12) is used to decide its final ownership, and the initial decision mask is obtained by combining the information of the corresponding positions of N assignment masks.
[0133] (12);
[0134] In formula (12), represents the initial decision mask; Indicates the pixel position; Indicates that in N assigned masks, the pixel The mask counts where the value is 1; Indicates that in N assigned masks, the pixel The mask count is not None; if Greater than or equal to , then the pixel point is set in the initial decision mask If it is determined to be a foreground pixel, the pixel value is set to 1; if not, the pixel point is set to 1 in the initial decision mask. Determined as background pixels, the pixel value is set to 0.
[0135] The initial decision mask obtained in this embodiment is as follows Figure 5e shown.
[0136] A pixel-by-pixel voting mechanism is used to determine the ownership of each pixel in the fused image, and the decision result is used as the final ownership result of the pixel, rather than simply superimposing all masks marked as foreground in step S23 as the foreground, which can ensure that the fusion of the image at the boundary of the focused and defocused areas is more natural and accurate.
[0137] S5, optimization processing: use morphological operations and guided filtering methods to optimize the initial decision mask to obtain the final decision mask.
[0138] S51. Mask optimization: The initial decision mask is optimized using morphological operations (opening, closing, and small region removal strategies) to eliminate noisy or discontinuous areas, enhance its quality and robustness, reduce noise and unnecessary details, and make the fusion result cleaner and more accurate.
[0139] (13);
[0140] In formula (13), represents the optimized initial decision mask; Indicates the pixel position; Represents the opening operation of a binary image; Indicates the operation of removing small areas; Represents the closing operation of a binary image; represents the initial decision mask; is a structural element, used to define the neighborhood; It is the area ratio parameter, which is used to define the small area.
[0141] The optimized initial decision mask obtained in this embodiment is as follows: Figure 5f shown.
[0142] S52, guided filtering: Use formula (14) and formula (15) to perform guided filtering on the optimized initial decision mask to smooth the mask and obtain the final decision mask.
[0143] (14);
[0144] (15);
[0145] In formula (14) and formula (15), is the initial fusion image; represents the optimized initial decision mask; Indicates the pixel position; and Respectively represent source image I1 and source image I2; represents the final decision mask; represents a guided filter operation, and are the parameters of the guided filter, which are set to 4 and 0.1 respectively in this embodiment. The guided filter is used to further smooth the mask, reduce internal noise while maintaining the edge, and improve the quality of the mask, which is crucial for accurate image fusion.
[0146] The final decision mask obtained in this embodiment is as follows Figure 5g shown.
[0147] S6. Image fusion: Based on the final decision mask, a weighted average method is used to obtain the fused image.
[0148] Formula (16) is used to perform weighted averaging on the final decision mask to fuse the source image I1 and the source image I2 to generate a fused image:
[0149] (16);
[0150] In formula (16), is the final fused image; Indicates the pixel position; represents the final decision mask; and They represent source image I1 and source image I2 respectively; in the final decision mask, the foreground pixels adopt the pixel values of source image I1, and the background pixels adopt the pixel values of source image I2.
[0151] The final fused image obtained in this embodiment is as follows Figure 5h shown.
[0152] In summary, the above method ensures that each object or region in the fused image is represented by pixels with higher definition by utilizing the powerful zero-shot segmentation capability of SAM and subsequent meticulous mask processing, thereby improving the quality and visual coherence of the overall image and achieving efficient fusion. The above method is a zero-shot multi-focus image fusion method that does not require training and has powerful deep learning performance, has stronger generalization ability and saves model training time.
[0153] In all operations of step S3 of this embodiment, if the overlapping area of each pair of matching masks is involved, the overlapping area of each pair of matching masks can be replaced as a whole by the corresponding area of the larger mask in each pair of matching masks or the corresponding area of the smaller mask in each pair of matching masks. Replace with or .
[0154] Example 2
[0155] This embodiment provides a zero-sample multi-focus image fusion device based on SAM, which includes a mask generation module, a mask matching module, a foreground and background assignment module, a voting decision module, an optimization processing module and an image fusion module.
[0156] The mask generation module is used to segment two source images of the same scene using the SAM model to obtain a segmentation mask set for each image. The mask matching module is used to calculate the intersection-over-union (IOU) of all mask pairs from different segmentation mask sets, and match the masks pointing to the same visual area according to the intersection-over-union (IOU) to form a set of matching mask pairs. The foreground-background assignment module is used to compare the clarity of the overlapping areas of each pair of matching masks in the two source images, and pre-mark the overlapping areas as foreground or background according to the clarity score, and set the pixel values of the non-overlapping areas to None to obtain the assigned mask set. The voting decision module is used to integrate the foreground and background information of each assigned mask in the assigned mask set using a pixel-by-pixel voting mechanism to obtain an initial decision mask. The optimization processing module is used to optimize the initial decision mask using morphological operations and guided filtering methods to obtain a final decision mask. The image fusion module is used to obtain a fused image based on the final decision mask by weighted averaging.
[0157] Example 3
[0158] This embodiment also provides an electronic device, including: at least one processor; and a memory, wherein the memory stores instructions, and when the instructions are executed by the at least one processor, the at least one processor executes the zero-sample multi-focus image fusion method based on SAM as described above. In this embodiment, the electronic device may include but is not limited to: a personal computer, a server computer, a workstation, a desktop computer, a laptop computer, a notebook computer, a mobile computing device, a smart phone, a tablet computer, a cellular phone, a personal digital assistant (PDA), a handheld device, a messaging device, a wearable computing device, a consumer electronic device, and the like.
[0159] Example 4
[0160] This embodiment also provides a machine-readable storage medium, which stores executable instructions, and when the instructions are executed, the machine executes the zero-sample multi-focus image fusion method based on SAM as described above. Specifically, a system or device equipped with a readable storage medium can be provided, on which a software program code for implementing the functions of any of the above embodiments is stored, and the computer or processor of the system or device reads and executes the instructions stored in the readable storage medium. In this case, the program code read from the readable medium itself can implement the functions of any of the above embodiments, so the machine-readable code and the readable storage medium storing the machine-readable code constitute part of this specification. Embodiments of readable storage media include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD-RW), magnetic tapes, non-volatile memory cards, and ROMs. Optionally, the program code can be downloaded from a server computer or a cloud by a communication network. Those skilled in the art should understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code. The present invention is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the process Figure 1 A process or multiple processes and / or boxes Figure 1 These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing device to work in a specific way, so that the instructions stored in the computer-readable memory produce a product including an instruction device, which implements the functions specified in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0161] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The above embodiments are only descriptions of the preferred implementation modes of the present invention, and are not intended to limit the scope of the present invention. Without departing from the design spirit of the present invention, various modifications and improvements made by ordinary technicians in this field to the technical solution of the present invention should fall within the protection scope determined by the claims of the present invention.
Claims
1. A zero-sample multi-focus image fusion method based on SAM, characterized in that: The method comprises the following steps: S1. Mask generation: Use the SAM model to segment two source images of the same scene and obtain a set of segmentation masks for each image. S2, mask matching: Calculate the intersection-and-union ratio of all mask pairs from different segmentation mask sets, and match the masks pointing to the same visual area according to the intersection-and-union ratio to form a set of matched mask pairs; S3, foreground and background assignment: based on the set of matched mask pairs, compare the clarity of the overlapping areas of each pair of matching masks in the two source images, pre-mark the overlapping areas according to the clarity scores, and obtain the assigned mask set; S4, voting decision: using a pixel-by-pixel voting mechanism to integrate the foreground and background information of each assigned mask in the assigned mask set to obtain an initial decision mask; S5, optimization processing: using morphological operations and guided filtering methods to optimize the initial decision mask to obtain the final decision mask; S6, image fusion: Based on the final decision mask, a fused image is obtained by weighted averaging; In step S1, the two source images of the same scene are segmented respectively using the SAM model to obtain a segmentation mask set for each image, including: The source images I1 and I2 of the same scene are input into the SAM model respectively, and all possible potential objects or regions in each source image are segmented respectively, thereby obtaining a segmentation mask set for each source image, and the masks in each segmentation mask set are sorted by area size; The step S1 is implemented using formula (1) and formula (2): (1); (2); In formula (1) and formula (2), and Respectively represent source image I1 and source image I2; and They respectively represent the segmentation mask sets obtained after the source images I1 and I2 are processed by the SAM model and sorted; Represents a mask sort operation, which sorts elements according to a specific comparison key value; It represents the automatic mask generation operation of SAM, which receives the image to be segmented and automatically generates n binary segmentation masks according to the semantic information of the image, where the value of n is determined by the image content; Represents a mask set The i Zhang mask, Represents a mask set The j Zhang mask; In step S2, the intersection-and-union ratios of all mask pairs from different segmentation mask sets are calculated, and masks pointing to the same visual area are matched according to the intersection-and-union ratios to form a set of matched mask pairs, including: S21. Use formula (3) to calculate the intersection-over-union (IOU) of all mask pairs from different mask sets: (3); In formula (3), express and The intersection and union ratio of Represents a set of segmentation masks The i Zhang mask, Represents a set of segmentation masks The j Zhang mask; and They respectively represent the segmentation mask sets obtained after the source images I1 and I2 are processed by the SAM model and sorted; S22, sorting the intersection-and-union ratios of the mask pairs in descending order, selecting the mask pairs corresponding to the first N intersection-and-union ratios as matching mask pairs, to form a matching mask pair set; N is a positive integer; In step S3, based on the set of matched mask pairs, the clarity of the overlapping areas of each pair of matched masks in the two source images is compared, and the overlapping areas are pre-marked according to the clarity scores to obtain the assigned mask set, including: S31. Obtain overlapping area: Based on N matching mask pairs, use formula (4) to obtain the overlapping area of each pair of matching masks: (4); In formula (4), Representation mask and mask The overlapping area mask of ; Indicates the pixel position; Represents a set of segmentation masks The i Zhang mask; Represents a set of segmentation masks The j Zhang mask; S32, calculating the clarity score: using formula (5) and formula (6) to calculate the clarity score of the overlapping area of each pair of matching masks in the source image I1 and the source image I2 respectively: (5); (6); In formula (5) and formula (6), Representation mask The clarity score of the corresponding area in the source image I1; Representation mask The clarity score of the corresponding area in the source image I2; and Respectively represent source image I1 and source image I2; Representation mask and mask The overlapping area mask of ; It is the general form of the expression on the right side of formula (5) and formula (6). The specific calculation process is implemented by formula (7)-formula (10): (7); (8); (9); (10); In formula (7) to formula (10), Used to quantize a given image In the specified mask The clarity of the image is calculated by In the mask The average value of the gradient strength of all points in the region is achieved; Indicates the pixel position; express The gradient strength at is a weighted combination of the horizontal gradient and the vertical gradient, with the weights given by the parameters Control, 0 ≤ ≤1; and Respectively The gradient amplitude in the horizontal and vertical directions; [ ]and [ ] indicates the application of Sobel operator in the horizontal and vertical directions respectively; Representing images exist The pixel intensity value at ; Representation mask exist The value at S33, foreground and background assignment: According to the clarity score, use formula (11) to assign the foreground and background to the overlapping area of each pair of matching masks, obtain N assigned masks, and obtain the assigned mask set: (11); In formula (11), Indicated by mask and mask The resulting assignment mask; Indicates the pixel position; Representation mask and mask The overlapping area mask of ; Representation mask The clarity score of the corresponding area in the source image I1; Representation mask The clarity score of the corresponding area in the source image I2; if The value is greater than or equal to , then in the assignment mask The area is pre-marked as foreground, and the pixel value is set to 1; otherwise, The area is pre-marked as background, and the pixel value is set to 0, and the pixel value of the remaining unmarked area is set to None; In step S4, a pixel-by-pixel voting mechanism is used to integrate the foreground and background information of each assigned mask in the assigned mask set to obtain an initial decision mask, including: For any pixel position , use the voting mechanism shown in formula (12) to decide its final ownership and obtain the initial decision mask: (12); In formula (12), represents the initial decision mask; Indicates the pixel position; Indicates that in N assigned masks, the pixel The mask counts where the value is 1; Indicates that in N assigned masks, the pixel The mask count is not None; if Greater than or equal to , then the pixel point is set in the initial decision mask If it is determined to be a foreground pixel, the pixel value is set to 1; if not, the pixel point is set to 1 in the initial decision mask. Determined as background pixels, the pixel value is set to 0.
2. The zero-sample multi-focus image fusion method based on SAM according to claim 1, characterized in that: In step S5, the initial decision mask is optimized using morphological operations and guided filtering methods to obtain a final decision mask, including: S51, optimizing the initial decision mask using the morphological operation shown in formula (13); (13); In formula (13), represents the optimized initial decision mask; Indicates the pixel position; Represents the opening operation of a binary image; Indicates the operation of removing small areas; Represents the closing operation of a binary image; represents the initial decision mask; is a structural element, used to define the neighborhood; is the area ratio parameter, used to define small areas; S52, based on the guided filter, the optimized initial decision mask is guided filtered using formulas (14) and (15) to smooth the mask and obtain the final decision mask: (14); (15); In formula (14) and formula (15), is the initial fusion image; Indicates the pixel position; represents the optimized initial decision mask; and Respectively represent source image I1 and source image I2; represents the final decision mask; represents a guided filter operation, and are the parameters of the guided filter.
3. The SAM-based zero-sample multi-focus image fusion method according to claim 2, characterized in that: In step S6, based on the final decision mask, a fused image is obtained by weighted averaging, including: Formula (16) is used to perform weighted averaging on the final decision mask to fuse the source image I1 and the source image I2 to generate a fused image: (16); In formula (16), is the final fused image; represents the final decision mask; and They represent source image I1 and source image I2 respectively; in the final decision mask, the foreground pixels adopt the pixel values of source image I1, and the background pixels adopt the pixel values of source image I2.
4. A zero-sample multi-focus image fusion device based on SAM, characterized in that: The device comprises a mask generation module, a mask matching module, a foreground and background assignment module, a voting decision module, an optimization processing module and an image fusion module; The mask generation module is used to segment two source images of the same scene using the SAM model to obtain a segmentation mask set for each image; The SAM model is used to segment two source images of the same scene to obtain a segmentation mask set for each image, which is implemented using formula (1) and formula (2): (1); (2); In formula (1) and formula (2), and Respectively represent source image I1 and source image I2; and They respectively represent the segmentation mask sets obtained after the source images I1 and I2 are processed and sorted by the SAM model; Represents a mask sort operation, which sorts elements according to a specific comparison key value; It represents the automatic mask generation operation of SAM, which receives the image to be segmented and automatically generates n binary segmentation masks according to the semantic information of the image, where the value of n is determined by the image content; Represents a mask set The i Zhang mask, Represents a mask set The j Zhang mask; The mask matching module is used to calculate the intersection-over-union (IOU) of all mask pairs from different segmentation mask sets, and match masks pointing to the same visual area according to the IOU to form a set of matched mask pairs; The calculating of the intersection-and-union ratios of all mask pairs from different segmentation mask sets and matching masks pointing to the same visual area according to the intersection-and-union ratios to form a set of matching mask pairs includes: Formula (3) is used to calculate the intersection-over-union (IOU) of all mask pairs from different mask sets: (3); In formula (3), express and The intersection and union ratio of Represents a set of segmentation masks The i Zhang mask, Represents a set of segmentation masks The j Zhang mask; and They respectively represent the segmentation mask sets obtained after the source images I1 and I2 are processed by the SAM model and sorted; Sort the intersection-and-union ratios of the mask pairs from large to small, select the mask pairs corresponding to the first N intersection-and-union ratios as matching mask pairs, and form a matching mask pair set; N is a positive integer; The foreground-background assignment module is used to compare the clarity of the overlapping areas of each pair of matching masks in the two source images, and pre-mark the overlapping areas as foreground or background according to the clarity scores, and set the pixel values of the non-overlapping areas to None, so as to obtain an assigned mask set; The clarity of the overlapping areas of each pair of matching masks in the two source images is compared, and the overlapping areas are pre-marked as foreground or background according to the clarity score, and the pixel values of the non-overlapping areas are set to None, to obtain the assigned mask set, including: Obtain overlapping area: Based on N matching mask pairs, use formula (4) to obtain the overlapping area of each pair of matching masks: (4); In formula (4), Representation mask and mask The overlapping area mask of ; Indicates the pixel position; Represents a set of segmentation masks The i Zhang mask; Represents a set of segmentation masks The j Zhang mask; Calculate the clarity score: Use formula (5) and formula (6) to calculate the clarity score of the overlapping area of each pair of matching masks in the source image I1 and the source image I2: (5); (6); In formula (5) and formula (6), Representation mask The clarity score of the corresponding area in the source image I1; Representation mask The clarity score of the corresponding area in the source image I2; and Respectively represent source image I1 and source image I2; Representation mask and mask The overlapping area mask of ; It is the general form of the expression on the right side of formula (5) and formula (6). The specific calculation process is implemented by formula (7)-formula (10): (7); (8); (9); (10); In formula (7) to formula (10), Used to quantize a given image In the specified mask The clarity of the image is calculated by In the mask The average value of the gradient strength of all points in the region is achieved; Indicates the pixel position; express The gradient strength at is a weighted combination of the horizontal gradient and the vertical gradient, with the weights given by the parameters Control, 0 ≤ ≤1; and Respectively The gradient amplitude in the horizontal and vertical directions; [ ]and [ ] indicates the application of Sobel operator in the horizontal and vertical directions respectively; Representing images exist The pixel intensity value at ; Representation mask exist The value at Foreground and background assignment: According to the clarity score, use formula (11) to assign the foreground and background to the overlapping area of each pair of matching masks, obtain N assigned masks, and obtain the assigned mask set: (11); In formula (11), Indicated by mask and mask The resulting assignment mask; Indicates the pixel position; Representation mask and mask The overlapping area mask of ; Representation mask The clarity score of the corresponding area in the source image I1; Representation mask The clarity score of the corresponding area in the source image I2; if The value is greater than or equal to , then in the assignment mask The area is pre-marked as foreground, and the pixel value is set to 1; otherwise, The area is pre-marked as background, and the pixel value is set to 0, and the pixel value of the remaining unmarked area is set to None; The voting decision module is used to integrate the foreground and background information of each assigned mask in the assigned mask set by using a pixel-by-pixel voting mechanism to obtain an initial decision mask; The pixel-by-pixel voting mechanism is used to integrate the foreground and background information of each assigned mask in the assigned mask set to obtain an initial decision mask, including: For any pixel position , use the voting mechanism shown in formula (12) to decide its final ownership and obtain the initial decision mask: (12); In formula (12), represents the initial decision mask; Indicates the pixel position; Indicates that in N assigned masks, the pixel The mask counts where the value is 1; Indicates that in N assigned masks, the pixel The mask count is not None; if Greater than or equal to , then the pixel point is set in the initial decision mask If it is determined to be a foreground pixel, the pixel value is set to 1; if not, the pixel point is set to 1 in the initial decision mask. Determined as background pixel, the pixel value is set to 0; The optimization processing module is used to optimize the initial decision mask using morphological operations and guided filtering methods to obtain a final decision mask; The image fusion module is used to obtain a fused image by weighted averaging based on the final decision mask.
5. An electronic device, characterized in that: include: at least one processor; and a memory storing instructions, which, when executed by the at least one processor, enable the at least one processor to perform the SAM-based zero-sample multi-focus image fusion method according to any one of claims 1 to 3.
6. A machine-readable storage medium, characterized in that: The machine stores executable instructions, which, when executed, enable the machine to perform the SAM-based zero-sample multi-focus image fusion method according to any one of claims 1 to 3.
