ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Blending a color image with a grayscale image

asked 2014-07-24 06:41:56 -0600

ROSkinect gravatar image

I have RGB image from a camera and depth image from the kinect and I want to blend them so as I get the two in the same window, but without converting RGB to grayscale.

How can I do that ?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-07-24 07:10:40 -0600

Wolf gravatar image

updated 2014-07-24 13:17:09 -0600

Is our depth image already 8 Bit? Otherwise you'll have to find a smart way to scale it to 8 Bit, which might be tricky;)

Assuming your depth image is cv::Mat of type CV_8UC1 and your RGB image is cv::Mat of type CV_8UC3 with color space BGR it is quite easy:

std::vector<cv::Mat> channels;
// split the channels
cv::split( rgb_image, channels );

// blend depth image into each channel
channels[ 0 ] = (channels[ 0 ] * 0.5) +  ( depth_image * 0.5 );
channels[ 1 ] = (channels[ 1 ] * 0.5) +  ( depth_image * 0.5 );
channels[ 2 ] = (channels[ 2 ] * 0.5) +  ( depth_image * 0.5 );

// merge to overlayed image
cv::Mat blended;
cv::merge( channels, blended );
edit flag offensive delete link more
0

answered 2014-07-24 07:26:42 -0600

ROSkinect gravatar image

Easy solution :

double a = 0.5; double b; 

b = ( 1.0 - a );

Mat Blended;

//Create image color
cv::Mat image_rgb(cv_ptr->image.rows, cv_ptr->image.cols, DataType<Vec3b>::type); 

// convert the gray image to rgb
cvtColor(image_gray, image_rgb, CV_GRAY2RGB);

//Blend the two rgb (old+the new)
addWeighted( cv_ptr_omni->image, a, image8U_flip_rgb, 0.5, 0.5, Blended); 

cv::imshow( "Linear Blend", Blended );
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-07-24 06:41:56 -0600

Seen: 1,364 times

Last updated: Jul 24 '14