Ask Your Question
0

Uniform LBP - problem with histogram [C++]

asked 2016-06-13 12:14:23 -0600

m_fory gravatar image

updated 2016-06-14 00:38:47 -0600

berak gravatar image

I'm having trouble trying to transform my normal LBP into the uniform version, I already read some guides and even the answers here but I'm feeling kinda dumb since I'm not being able to translate their uniform versions to my LBP version.

The concept is okay but I can't "translate" it to the syntax I have, if someone could guide me I would appreciate, I really tried all I could so asking here is my last resort since I can't change all my code to one that fits better the versions I saw because this would be wrong and of course I'm more used to the version I implemented, anyways, here the method that does my currently histogram: example.png

I "slice" the image into subImages and calculate each one independently they are all on the imgCells vector, and maskHist is the vector that contains all the histograms from each imgCell[]

Thank you very much

edit retag flag offensive close merge delete

Comments

please do not post screenshots of code, rather give us the text...

berak gravatar imageberak ( 2016-06-14 01:09:47 -0600 )edit
1

what is the problem, exactly ?

berak gravatar imageberak ( 2016-06-14 01:16:31 -0600 )edit

Sorry, I couldn't post the code properly and was afraid it would be a mess, the problem is that I'm not being able to transform this generateHistogram method on the uniform version using only 59 features vs 256 , I know in theory but I'm having trouble with the syntax

m_fory gravatar imagem_fory ( 2016-06-14 09:16:20 -0600 )edit

if you have converted the lbp features to uniform ones(e.g. using a lookup table), the changes to the histogram code should be just:

float range[] = {0,58};
int histSize = 59;

(i hope, you're not confusing the "unform" param in calcHist with the "uniform lookup" in the lbp part)

berak gravatar imageberak ( 2016-06-14 09:30:00 -0600 )edit
1

"if you have converted the lbp features to uniform ones(e.g. using a lookup table)" That's what I'm having trouble doing right

m_fory gravatar imagem_fory ( 2016-06-14 10:32:04 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-06-14 11:03:22 -0600

berak gravatar image

updated 2016-06-14 11:07:04 -0600

if you imagine an lbp value as bits, i.e:

1 0 0 1 0 0 0 1

it is said to be "uniform", if the number of (circular) 0->1 and 1->0 crossings is <= 2, in other words:

1 1 1 0 0 0 1 1 // uniform
1 0 0 1 0 0 0 1 // not uniform
0 0 0 1 1 1 1 1 // uniform

now, for 8 bits, we can precalculate the values for each combination,

static int uniform[256] = // for exactly 8 bits / neighbours !
{  
    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
};

since we're applying histograms later, each uniform value gets it's own "bin", all non-uniform values go into the "noise" bin (58)

now, if you calculated your lbp feature image, to make this "uniform" all you need to do is to replace each value with the one from the lookup table. we could do this in a loop, replacing lbp[i] with uniform[lbp[i]], but it's far easier to use opencv's LUT

Mat lbp = ...
Mat uniform_lbp;
LUT(lbp, uniform, uniform_lbp);

after that, you can build histograms on grid patches as usual, only difference is, that your range is {0,58} instead of {0,255}, and the histSize is 59, not 256.

edit flag offensive delete link more

Comments

Thank you, I will try to add this logic to my method,I didn't know this LUT method, interesting, so basically it's just this modification I will have to add to my code above?

m_fory gravatar imagem_fory ( 2016-06-15 19:08:21 -0600 )edit

yes, you simply calculate your histogram on uniform_lbp instead of lbp features

berak gravatar imageberak ( 2016-06-15 20:03:50 -0600 )edit

Just one final question (sorry to keep bothering you by the way) to see if I understood, let's say I have the lbp value 00111000, converting to decimal I have the value 56, so I go to this lookup table and look the uniform[45] (46 since the array begins on 0) position and mark the value on uniform[46] as the value on the histogram ?

m_fory gravatar imagem_fory ( 2016-06-15 21:06:19 -0600 )edit
1

no, you don't have to subtract 1 , it's just uniform[56].

berak gravatar imageberak ( 2016-06-16 00:23:24 -0600 )edit

Okay, I understand now, thank you very much

m_fory gravatar imagem_fory ( 2016-06-16 07:00:50 -0600 )edit

one last thing: rather calculate the lbp/uniform features once on the large image, and then divide it into grids to calc the histograms, else you loose too many "border" pixels. i.e, if your image is 80x80, and you calc lbp features with a radius of 2, you only end up with 6x6 pixels per patch contributing to your histogram, instead of 10x10

berak gravatar imageberak ( 2016-06-16 07:15:58 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-06-13 12:14:23 -0600

Seen: 531 times

Last updated: Jun 14 '16