Ask Your Question

Revision history [back]

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.