Ask Your Question

Revision history [back]

Bug in LBP

Hi,

In the last couple of hours, I worked closely with LBP in OpenCV and compared it with the original implementation in Matlab. There was a slight difference in the results I got, so I looked more closely at the code.

I found the following bug. In the lines:

float x = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors))); 
float y = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));

the roles of x and y are flipped. It should be :

float y = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors))); 
float x = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));

As in Matlab it's:

spoints(i,1) = -radius*sin((i-1)*a); %y
spoints(i,2) = radius*cos((i-1)*a); %x

The reason is obvious - x corresponds to the cos value of the angle and y corresponds to the y value of the angle. After changing the code, the results in Matlab and OpenCV were the same.

I can upload LBP images of "before" and "after" the fix, if you want.

How do I report it?

Thanks,

Gil.

Bug in LBP

Hi,

In the last couple of hours, I worked closely with LBP in OpenCV and compared it with the original implementation in Matlab. There was a slight difference in the results I got, so I looked more closely at the code.

I found the following bug. In the lines:

float x = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors))); 
float y = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));

the roles of x and y are flipped. It should be :

float y = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors))); 
float x = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));

As in Matlab it's:

spoints(i,1) = -radius*sin((i-1)*a); %y
spoints(i,2) = radius*cos((i-1)*a); %x

The reason is obvious - x corresponds to the cos value of the angle and y corresponds to the y value of the angle. After changing the code, the results in Matlab and OpenCV were the same.

I can upload LBP images of "before" and "after" the fix, if you want.

How do I report it?

Thanks,

Gil.