Blending Example OpenCV Feather Blending

This is second post in the tutorial series which compiles all the available blender codes in OpenCV.

If you haven’t read the first ,its here.

It covers MultibandBlending.

Now,for this part of tutorial we will cover Feather Blending.I want you to test this code yourself and comment on the results.

Also,If you find any errors particularly in this post feel free to comment below,I will correct it.

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.

Now ,Lets start with Feather Blending.

Its very similar to what we did in multiband blending,just one minute change is we need to make a overlapping masks in it.(Not pretty sure about it.)

Lets directly jump to the code:

#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/gpu/device/utility.hpp>
//#include "opencv2/imgcodecs.hpp"
//#include "opencv2/highgui.hpp"
#include "opencv2/stitching/detail/autocalib.hpp"
#include "opencv2/stitching/detail/blenders.hpp"
//#include "opencv2/stitching/detail/timelapsers.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)+10, mask1.rows)).setTo(255); // Mask defines visible region of 1st  image ,+10 is overlapping region
mask1(Rect((mask1.cols/2)+10, 0, mask1.cols - (mask1.cols/2)-10, mask1.rows)).setTo(0); //Hidden portion of 1st  image
Mat mask2(image2s.size(), CV_8U);
mask2(Rect(0, 0, mask2.cols/2, mask2.rows)).setTo(0);//Hidden portion of 2nd image
mask2(Rect(mask2.cols/2, 0, mask2.cols - mask2.cols/2, mask2.rows)).setTo(255);//Visible region of 2nd image

imshow("mask1",mask1);
imshow("mask2",mask2);

//MultiBandBlender blender(false, 5);
FeatherBlender  blender(0.5f); //sharpness
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);
//Mat expected = imread(string(cvtest::TS::ptr()->get_data_path()) + "stitching/baboon_lena.png");
//double psnr = cvtest::PSNR(expected, result);
//EXPECT_GE(psnr, 50);
imshow("result",result);
imshow("result_mask",result_mask);
	

 
 waitKey(0);//needed for imashow
 return 0;
 }

Please go through comments for the explanation.I am not shure about the overlapping region,also the output is not appealing as in multiband blending.Any corrective suggestions are most welcome.

Source Images:

Result:

Find third part of series here.

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


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