Ask Your Question
0

RGB to Lab conversion and median filtering function

asked 2016-01-03 09:53:59 -0600

tofi gravatar image

updated 2016-01-03 14:01:27 -0600

Hi .

I trying to do the following tasks using function below :

  1. after the RGB input image is converted to an Lab* image, an

  2. extract L ( illuminative component ) and apply a 31×31 median filter to the L image,

  3. obtain the inverted illuminative image (L) .

  4. adding the inverted image to the original L image.

I need your review of the function is it ok ?

and how the addition of inverted image and L component can be obtained (void add() or addWeighted() )

or is there another way to do it ?

    void split_lab(Mat planes)
    {

    Mat lab,dst,inv;
    cvtColor(planes, lab, CV_BGR2Lab);

    vector <Mat> splits;
    split(lab, splits);


    Mat L = splits[0];

    medianBlur(L, dst, 31);             // is that how 31*31 median blur is obtained ?


    bitwise_not(dst, inv);             // is this the right way to obtain invert ?

      }
edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
1

answered 2016-01-03 15:32:09 -0600

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.

edit flag offensive delete link more

Comments

@r S Nikhil ,

  1. can you make this clearer

    ( 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. )

  2. what about cv::add() ? what the difference if I used it ?

Thanks very much

tofi gravatar imagetofi ( 2016-01-03 18:08:27 -0600 )edit

nice answer.

addWeighted( L, ratio, inv, 1.0-ratio, 0.0, blendedDst); is equal of L = L * 0.5 in this case

also see my answer on S.O

sturkmen gravatar imagesturkmen ( 2016-01-03 19:10:53 -0600 )edit

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
R S Nikhil Krishna gravatar imageR S Nikhil Krishna ( 2016-01-04 21:30:42 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2016-01-03 09:53:59 -0600

Seen: 757 times

Last updated: Jan 03 '16