Ask Your Question

R S Nikhil Krishna's profile - activity

2016-01-04 21:30:48 -0600 received badge  Enthusiast
2016-01-04 21:30:42 -0600 commented answer RGB to Lab conversion and median filtering function

addWeighted( L, ratio, inv, 1.0-ratio, 0.0, blendedDst);

Is the equvalent of saying that for every pixel of your final image (blendedDst), blendedDst = Lratio + inv(1.0-ratio) + 0.0

So suppose I were to replace the 0.0 with, let's say, 3.67, i.e.

addWeighted( L, ratio, inv, 1.0-ratio, 3.67, blendedDst);

Then, for every pixel in blendedDst, blendedDst = Lratio + inv(1.0-ratio) + 3.67

Hence, the 'L' value of each pixel is increased by 3.67. Hence, blendedDst will be brighter as a whole.

To understsand cv::add(), I think it's sufficient to know that the following statements are equivalent

addWeigthed( L, 1.0, inv, 1.0, 0.0, blendedDst);

add(L, inv, blendedDst);

blendedDst = L + inv;     //Yes. openCV has defined an overloaded '+' operator to simplify our life :-D
2016-01-04 21:30:42 -0600 received badge  Enthusiast
2016-01-03 15:32:09 -0600 answered a question RGB to Lab conversion and median filtering function

Yes, the code you have written is correct for both the median blur as well as for inverting the luminance channel of the image.

Assuming what you are looking for in your fourth task is the weighted addition of the two. This can be performed using the function addweighted(). You can refer to this tutorial to see how it's done. The variables src1 and src2 in the tutorial will be replaced by L and inv. Hence, the implementation of addWeighted() should be along the lines of

Mat blendedDst;
double ratio = 0.5    // 0.5 is chosen for simple adding of two images. This can be changed depending on your preference
addWeighted( L, ratio, inv, 1.0-ratio, 0.0, blendedDst);

where the variable ratio is the blending factor for the original L image in the final output.

Note: With the second last argument in addWeighted() , you can also manually input an offset for each pixel's 'L' value to make your image brighter or darker as a whole.