FriendBlend is an application that merges two portraits of different people to create a single, multi-person photo. The
protraits should have same background. The application is very useful when person A takes photo of person B, person B
takes photo of person A with the same background. The application produces a blended image having both persons in the
image.
The application is implemented in C++ and the implementations depends on OpenCV liibrary.
To compile the source code, run
make friendBlend
in the top directory of the application.
To run the application, type ./bin/friendBlend path/to/image1 path/to/image2
.
path/to/image1
and path/to/image2
are the location of the images which you want to blend. To log each step
result, an extra third argument log
can be passed.
make friendBlend
./bin/friendBlend images/test1/friend1.jpg images/test1/friend2.jpg log
(a) Image 1
(b) Image 2
(c) Result
(a) Image 1
(b) Image 2
(c) Result
There are four stpes involved behind the working algorithm of the application:
Before the blending process, the lighting from the two input images should be approximately the same otherwise the blended image could have some artifacts. We perform histogram equalization on both the images for the color correction.
(a) Histogram Equalized Image 1
(b) Histogram Equalized Image 2
We have two image merging process : Alpha blending and Grabcut. Depending on the location of the humans, one of the image merging or blending chosen. To find the location of the human, we detect the face and get the bounding box using Haar Cascade models in OpenCV. From the face bounding box, we estimate the bounding box for the human body.
(a) Face and Body Detection in Image 1
(b) Face and Body Detection in Image 2
The images need to be aligned before we merge them. We compute a homography to warp one of the images so that the perspectives from the two photos are the same prior to merging.
Our application uses Oriented FAST and Rotated BRIEF (ORB) detector for keypoint detection in the images. Further, we also prune the keypoints inside the bounding boxe of the humans.
(a) Keypoint Detection in Image 1
(b) Keypoint Detection in Image 2
Keypoints in the two images are matched by Hamming distance using Brute Force Matcher.
After we have found a good set of keypoint matches, homography is find using RANSAC based method.
FriendBlend uses two techniques to merge the images depending on whether the persons are close or far apart.
We blend the region between the bounding box of the persons using Alpha blending. The left region from the left person image and the right region from the right persion image is copied directly into the final blended image.
When the persons are close, the person which appears in front is cropped in the foreground using GrabCut. This cropped pixels of the person is put on the top of the other image to get the final blended image.
[1] https://web.stanford.edu/class/ee368/Project_Spring_1415/Reports/Chen_Zeng.pdf