Hi I am trying to produce an image which is a combination of multiple images such as in focus stacking. Now I have 6 photos and I want to produce a final image such that the final image uses blocks of individual images with maximum value of the block. But I want to do edge detection of these 6 images first and based on the maximum edges produce a final image such that the final image has the maximum edges from the combination of all images. But the final image produced should be a color image and not in the edge detected form. Is it possible to do so? Images can be accessed here

  • $\begingroup$ You don't need to explicitly perform an edge detection for this. You can just use the gradients (e.g. sobel) to guide you during fusing. Do you have sample images? $\endgroup$ Oct 16, 2019 at 2:31
  • $\begingroup$ Yes I'll link them in the question. @TolgaBirdal $\endgroup$
    – user45676
    Oct 16, 2019 at 3:01

1 Answer 1


First of all, thanks for sharing this problem. I hope it can foster some good discussions here at stack-exchange. I guess this problem is commonly called Multi-Focus Multi-Image Fusion (MF-MIF).

Let's look at all the images together with their grayscale histograms and the gradient magnitude (information content in each image):

enter image description here enter image description here

As the original question requires an edge-based (or rather gradient as I take it) method, I will follow the idea presented in the following paper:

S. Paul, I.S. Sevcenco, P. Agathoklis, "Multi-exposure and Multi-focus image fusion in gradient domain", Journal of Circuits, Systems, and Computers, Vol. 25, No. 10 (2016), DOI: 10.1142/S0218126616501231 https://pdfs.semanticscholar.org/114b/835c5ea86e93efff1027cd6da7188c0cc92f.pdf

Essentially, the method aims to blend the gradients of the luminance components of the input images using the maximum gradient magnitude at each pixel location and then to obtain the fused luminance using a Haar wavelet-based image reconstruction technique. The algorithm also includes a Poisson solver at each resolution to eliminate artifacts that may appear due to the non-conservative nature of the resulting gradient.

The official source code of the method is given in this github repository and in your, kind of challenging dataset, the output looks like the following:

enter image description here

I am not sure if this is a sufficiently good output, but I bet further investigations can quickly lead to improved results. A small observation: The first image seems to be quite sharp. It seems like it has a global focus and already looks (only looks though) better than the resulting image.

  • $\begingroup$ thanks for sharing this. It does exactly what I wanted. Even though the output I expected can still use some improvement. Maybe aligning the images first could produce better results. $\endgroup$
    – user45676
    Oct 16, 2019 at 4:22
  • $\begingroup$ definitely. I added a small paragraph in the end. the first image looks sharp already : ). I neither know the capture properties nor the desired outcome of course. $\endgroup$ Oct 16, 2019 at 4:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.