Skip to content

Latest commit

 

History

History
139 lines (125 loc) · 6.79 KB

README.md

File metadata and controls

139 lines (125 loc) · 6.79 KB

FriendBlend

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.

Compile and Run

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

Working Examples


(a) Image 1                                       (b) Image 2                                       (c) Result


(a) Image 1                                       (b) Image 2                                       (c) Result

Working of the Application

There are four stpes involved behind the working algorithm of the application:

1. Color Correction

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


2. Face and Body Detection

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


3. Images alignment

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.

a. Keypoint Detection

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


b. Keypoint Matching

Keypoints in the two images are matched by Hamming distance using Brute Force Matcher.


(a) Matched keypoint


c. Computing the Homography

After we have found a good set of keypoint matches, homography is find using RANSAC based method.


(a) Homography


4. Image Blending

FriendBlend uses two techniques to merge the images depending on whether the persons are close or far apart.

a. Persons 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.


(a) Alpha blending


b. Persons Close Together

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.


(a) Grabcut


References

[1] https://web.stanford.edu/class/ee368/Project_Spring_1415/Reports/Chen_Zeng.pdf