How can I make the composite of two images in OpenCV with Python?
Question: I have one image that remains unchanged and another image which is the first
one, but with a filter applied on it. I want to create the third image which
should be the composite of these first two images.

I know that in MATLAB there is a function called as `imfuse()` with the
default color channel green-magenta. I want to do the same thing in Python,
with exactly the same color channel. How can I do this ?

Here are the images (first is the original picture, second is the first
picture with the filter applied, third is the MATLAB result):

![image](http://i59.tinypic.com/2q1usqs.jpg)
![filter](http://i59.tinypic.com/35iq612.jpg)
![result](http://i62.tinypic.com/21c9vmf.jpg)

Thanks for your help !


Answer: By default, [`imfuse`](http://www.mathworks.com/help/images/ref/imfuse.html)
simply overlays the pair of images in different color bands (Default being
`Method=falsecolor` and `ColorChannels=green-magenta`).

Here is an example in MATLAB to illustrate (it should should be easy to write
this in Python/OpenCV):

    
    
    % a pair of grayscale images
    A = imread('cameraman.tif');
    B = imrotate(A,5,'bicubic','crop');    % image "A" rotated a bit
    
    % use IMFUSE
    C = imfuse(A,B);
    imshow(C)
    
    % use our version where: Red=B, Green=A, Blue=B
    C = cat(3, B, A, B);
    imshow(C)
    

Both should give you the same thing:

![fused_images](http://i.stack.imgur.com/TBUuf.png)

* * *

# EDIT:

Here is the Python/OpenCV version:

    
    
    import numpy as np
    import cv2
    
    A = cv2.imread(r"C:\path\to\a.png", 0)
    B = cv2.imread(r"C:\path\to\b.png", 0)
    
    #C = cv2.merge((B,A,B))
    C = np.dstack((B,A,B))
    cv2.imshow("imfuse",C)
    cv2.waitKey(0)
    

![opencv_python_imfuse](http://i.stack.imgur.com/nmjE1.png)

