Search code examples
opencvdescriptorlbph-algorithm

How to implement LBP uniform


I'm new in OpenCV. I'm trying to do a sample to extract the features of a face. I'm rading several papers and one of the most recommended was LBP. I understand how to works LBP descriptor but I read a variant from it. LBP uniform I understand it is as LBP original but once you have binary sequence (e.g you compare a particular pixel with the neighboors and you have next result -> 11110001, I understand there are 2 transitions, so in that case we can say it is uniform because number of transitions is <= 2.

My question is what code I have to comput in that pixel after doing this process. I know with the LBP original wew have 256 values but with this variant from LBP uniform que reduce the number to 59 bins values. So my question is what code I have to put after testing if the number of transitions in every pixel is <=2 or >2.

Thanks! I hope I had explained correctly.


Solution

  • Here's a lookup-table for this, assuming 8 neighbours:

        static int uniform[256] =
        {  
            0,1,2,3,4,58,5,6,7,58,58,58,8,58,9,10,11,58,58,58,58,58,58,58,12,58,58,58,13,58,
            14,15,16,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,17,58,58,58,58,58,58,58,18,
            58,58,58,19,58,20,21,22,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,
            58,58,58,58,58,58,58,58,58,58,58,58,23,58,58,58,58,58,58,58,58,58,58,58,58,58,
            58,58,24,58,58,58,58,58,58,58,25,58,58,58,26,58,27,28,29,30,58,31,58,58,58,32,58,
            58,58,58,58,58,58,33,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,34,58,58,58,58,
            58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,
            58,35,36,37,58,38,58,58,58,39,58,58,58,58,58,58,58,40,58,58,58,58,58,58,58,58,58,
            58,58,58,58,58,58,41,42,43,58,44,58,58,58,45,58,58,58,58,58,58,58,46,47,48,58,49,
            58,58,58,50,51,52,58,53,54,55,56,57
        };
    

    using this, you just replace the 8-bit lbp value with the one from the LUT:

        value = uniform[value];