Forge
Skip to main content

A self supervised learning technique for multi-focus image fusion

Weights and Biases ML-Ops course on Model Development- Final Course Project report.
Last updated: June 26, 2026
Please click here to read about the baseline-model report.

Overview

What is image fusion and why should I care ?

Image fusion is a technique or a process in which we take in several images of the same scene or same object and merge them in order to obtain a higher quality image. There are several kinds of image fusion techniques in the literature based on different types of images and modalities used to capture those images. The technique that is presented in this report is known as multi-focus image fusion. Here the images being fused have different regions in focus - and our objective is to obtain a fully focused image, the example image below explains it pictorially:
An example image to demonstrate multi-focus image fusion | Image source: author
Before understanding the business value or use-case of this proposed technique and architecture, let's first get familiar with some image fusion techniques:

Business Value

"Business value" term maybe a misnomer here, but the ideal task for building and training this model is to make a single self-supervised learning model, which can perform not just multi-focus image fusion but also the other two fusion techniques (mentioned above) as well. Hence this is an attempt to build a single network which can fulfill three types of image fusion techniques.
Few papers with this kind of approach:

Dataset information

For this project report, I have just used multi-focus images, and not any other images. So the dataset considered is the MFIF-database which is publicly available here. The dataset consists of 63 RGB valued multi-focus image pairs having different resolutions, and hence training the model was rather challenging. The Image Table below displays few of the images in our dataset.


Previously, for our baseline model, while loading the images, we had also performed a center-crop operation so that we can increase the training batch-size (which was impossible otherwise due to computational limitations). Unfortunately that did not go well for me, because for some images- cropping them resulted in cropping either the focused or defocused parts of the source images, which is rather undesirable for the training network. Therefore, for this report by compromising with the batch-size we have trained the model by resizing the source images to 500x500x3 px.

Model Architecture

  1. A Siamese kind of Autoencoder based architecture is considered for the baseline model, having skip connections between encoder and decoder.
  2. At first, two source images will be passed through the encoder in a Siamese fashion, which will output two feature vectors say A and B of size 800 each
  3. We then stack them together horizontally, and pass it to the decoder.
  4. The decoder then outputs an image matrix of the same size as the input source images.
  5. The final step is to calculate the loss in a self supervised fashion.
  6. Let's say, the output to the decoder is F and the source images were I1 and I2. For the baseline model, we have used a custom SSIM loss function which calculates the loss like this: L = ( 1/SSIM(F, I1) + 1/SSIM(F,I2) )/2
Have a look at the model architecture below, and the code used for model construction can be found here:
Model architecture | Image source: author | created from here

Training

The model was trained for four different hyperparameter configurations:
config1 = dict(
epochs = 150,
optimizer = 'adam',
learning_rate = 0.0009,
batch_size = 20,
dropout = 0.1,
grad_clip = 0.9,
weight_decay = 1e-5,
momentum = None
)

config2 = dict(
epochs = 150,
optimizer = 'sgd',
learning_rate = 0.0009,
batch_size = 20,
dropout = 0.2,
grad_clip = 0.8,
weight_decay = 1e-6,
momentum = 0.95
)

config3 = dict(
epochs = 100,
optimizer = 'adam',
learning_rate = 0.0001,
batch_size = 20,
dropout = 0.25,
grad_clip = 0.75,
weight_decay = 1e-4,
momentum = None
)

config4 = dict(
epochs = 200,
optimizer = 'sgd',
learning_rate = 0.0001,
batch_size = 20,
dropout = 0.25,
grad_clip = 0.9,
weight_decay = 1e-5,
momentum = 0.9
)

#Note that "batch_size" was kept fixed to 20, due to computational limitations.
Each of the model came down to a respectable loss value, but "graceful-fire-23" (corresponding to config1) outperformed all of them in terms of visual clarity. Have a look at the training and validation loss charts:


W&B also provides a parallel plots chart which makes it even easier to look at the model hyperparameters, and pick the one with the best performance.



Actual Fusion results

What is expected from the model

  1. Automatically capture the focus regions of each of the source images and put those features together and create a fused image.
  2. Capture the color and contrast information of both the source images.
  3. Make sure no additional artifacts are generated (noise, blurriness, etc.)
Here are the results given by the best model, also the results given by the other models can be viewed on my GitHub repo (Link is provided at the end of the report).



Experiment summary and findings

  1. The model architecture was same throughout, for each of the experiments.
  2. For the baseline model, MSE loss function was implemented, which was actually capturing the defocused parts of the image, and ignoring the focused parts, which was rather undesirable.
  3. Hyper-parameter optimization was done manually, because for each model we had to see the fusion results, and in doing so, we found out that using SSIM (Structural Similarity Index Measure) as a loss function was able to give us the desired output.
  4. Adam and momentum based SGD optimizers were used to compare the results, and Adam was observed to perform better.
  5. The current best model had 150 epochs, which gave a validation loss of about: 1.06, and was still decreasing.
  6. The best model's output was able to give visually appealing results, however some blurring artifacts were also seen, and the color and contrast information was different from the original source images (something to look into, later!)

Conclusion

In this work, SSIM loss function played the key role for making the fusion process possible, the results were far better than the previously trained baseline model in which a rather naïve MSE loss was implemented. Also having the images resized before-hand was not a bad idea. However, the fused images still have some blurred artifacts in them, also majority of the fused images lack the color and depth information that the input source images had.

Future work

  1. Due to some code related issues I could not implement synthetic blurring while training, which can actually further improve our model's performance. Also, incorporating pre-trained models for the encoding process can help increase the model's overall performance. All these things will be worked upon in the future.
  2. Obviously, we need to increase the data used for training, adding other kinds of images will be of great importance in order to train a single model for all three types of image fusion techniques that was mentioned earlier.

Acknowledgements

That's it for this report :) I would really like to thank W&B's team for making this course available to us, I got to learn a lot of cool and useful things from all the instructors, which got me really motivated to work on this topic. (I will be continuing this work at a greater depth for my thesis and would definitely be using this environment for all the experiments)
Detailed code for all this can be found at my GitHub repo.
As you can see, this project has a lot of room for improvement, and so any kind of suggestions or tweaks are always welcome, please feel free to comment or contact with me directly via LinkedIn or email me at [email protected]