Blending Example OpenCV Multiband Blending

I was assigned a project for panorama generation using OpenCV.These involved steps like finding and matching the feature points.

Once I warped the second image and copied it to the first one,I got the panorama but there was still a problem ie ,there was a visible seam in between two images.

Anyone can easily identify that they are two seperate images from two seprate sources.So I googled and found the way out for this problem & it was called

Image Blending”.

In addition it came to my notice that OpenCV has API`s for this, the keywords which I got were

1)Multiband Blending.

2)Feather Blending.

In addition I got some other keywords,

3)Alpha Blending

4)Laplacian Blending

but there was still a problem there were little to no examples which I could use directly in my code.

So,I googled some git repositories got some codes working.

I thought I would share with you all ,the working codes(linux + OpenCV 2.4.9) in this tutorial series.

DISCLAIMER:I do not claim any authority over these codes,I have just compiled them in one place and edited to run on Linux + OpenCV 2.4.9.All authors are credited here and If anyone has complaints about the use of these codes can comment here to bring it to my notice.

1)Multiband Blending

#include <stdio.h>

#include <iostream>

#include "opencv2/core/core.hpp"

#include "opencv2/features2d/features2d.hpp"

#include "opencv2/highgui/highgui.hpp"

#include "opencv2/nonfree/nonfree.hpp"

#include "opencv2/calib3d/calib3d.hpp"

#include "opencv2/imgproc/imgproc.hpp"

#include "opencv2/ts/ts_gtest.h"

#include <iostream>

#include <fstream>

#include <string>

#include "opencv2/opencv_modules.hpp"

#include "opencv2/stitching/detail/autocalib.hpp"

#include "opencv2/stitching/detail/blenders.hpp"

#include "opencv2/stitching/detail/camera.hpp"

#include "opencv2/stitching/detail/exposure_compensate.hpp"

#include "opencv2/stitching/detail/matchers.hpp"

#include "opencv2/stitching/detail/motion_estimators.hpp"

#include "opencv2/stitching/detail/seam_finders.hpp"

#include "opencv2/stitching/detail/util.hpp"

#include "opencv2/stitching/detail/warpers.hpp"

#include "opencv2/stitching/warpers.hpp"

using namespace cv;

using namespace cv::detail;

using namespace std;

/** @function main */

int main( int argc, char** argv )

{

Mat image1 = imread("lena.jpeg");//Read first image

Mat image2 = imread("baboon.jpeg");//Read Second Image

//ASSERT_EQ(image1.rows, image2.rows); ASSERT_EQ(image1.cols, image2.cols);

Mat image1s, image2s;

image1.convertTo(image1s, CV_16S);

image2.convertTo(image2s, CV_16S);

Mat mask1(image1s.size(), CV_8U);

mask1(Rect(0, 0, mask1.cols/2, mask1.rows)).setTo(255);

mask1(Rect(mask1.cols/2, 0, mask1.cols - mask1.cols/2, mask1.rows)).setTo(0);

Mat mask2(image2s.size(), CV_8U);

mask2(Rect(0, 0, mask2.cols/2, mask2.rows)).setTo(0);

mask2(Rect(mask2.cols/2, 0, mask2.cols - mask2.cols/2, mask2.rows)).setTo(255);

imshow("mask1",mask1);

imshow("mask2",mask2);

MultiBandBlender blender(false, 5);

blender.prepare(Rect(0, 0, max(image1s.cols, image2s.cols), max(image1s.rows, image2s.rows)));

blender.feed(image1s, mask1, Point(0,0));

blender.feed(image2s, mask2, Point(0,0));

Mat result_s, result_mask;

blender.blend(result_s, result_mask);

Mat result; result_s.convertTo(result, CV_8U);

imshow("result",result);

imshow("result_mask",result_mask);

waitKey(0);

return 0;

}

Input Images:          baboon.jpeg                                      lena.jpeg

 

 

 

 

 

Resultant Image:

 

 

 

 

 

 

Here we create two masks

mask1 -Half portion of lena.

mask2 -Half portion of baboon.

Resultant we get blended image.Compile and run this code you will get clarity .

Credits:

Official documentation:

http://docs.opencv.org/2.4/modules/stitching/doc/blenders.html#detail-blender-prepare

https://github.com/jasonrchaves/PanoramaFromVideo/blob/master/video_stitching_detailed.cpp

https://github.com/Itseez/opencv/blob/master/samples/cpp/stitching_detailed.cpp

Second part of this series here.


Like what you read?
Do you think you have knowledge to fetch Overseas Jobs and Projects?
Register here and start posting...
The following two tabs change content below.

Embedded Design Engineer by profession .Extremly intrested in Emedded Systems,Linux and Electronics.I truely believe in open source , join me in this mission by registering .

How to Integrate Google “No CAPTCHA reCAPTCHA” on Your Website


Leave a Reply