LBP with HSV is not working.

asked 2015-05-11 02:53:14 -0500

fredreload gravatar image

So I tried to use the bytefish code again and tried to run it for color images, HSV, RGB, but the result does not show up well. What I did is load in the image as RGB. Pass the CV_8UC3 as Vec3b. Use the ELBP to compute individual bit for R, G, and B as shown below. But the image looks bad either as HSV or RGB. RGB gets a distance result with Kullback but the image does not match. HSV gets negative value which is not supposed to happen. Does this code not work for color images?

void lbp::ELBP(const Mat& src, Mat& dst, int radius, int neighbors) {
    switch(src.type()) {
        case CV_8UC3: ELBPA_<cv::Vec3b>(src, dst, radius, neighbors); break;

for(int i=radius; i < src.rows-radius;i++) {
            for(int j=radius;j < src.cols-radius;j++) {
                for(int k=0; k<3; k++)
                float t = w1*<_Tp>(i+fy,j+fx)[k] + w2*<_Tp>(i+fy,j+cx)[k] + w3*<_Tp>(i+cy,j+fx)[k] + w4*<_Tp>(i+cy,j+cx)[k];
                // we are dealing with floating point precision, so add some little tolerance
      <cv::Vec3b>(i-radius,j-radius)[k] += ((t ><_Tp>(i,j)[k]) && (abs(<_Tp>(i,j)[k]) > std::numeric_limits<float>::epsilon())) << n;

image description

edit retag flag offensive close merge delete


  • "Does this code not work for color images?" - i doubt that it was ever intended to be used with colour. what kind of gain do you expect from using it ? also, wouldn't it be easier, to split the colour image into channels, and handle those separately ?
  • "But the image looks bad" - the machine has to like it, not humans.
  • "HSV gets negative value" - where ? with your kldiv ? maybe show that code, too ?
berak gravatar imageberak ( 2015-05-11 03:08:32 -0500 )edit

I want to do a similar texture comparison but with color and shape, not just gray image with shape only. Well, it is calculated base on 3 different channels from k=0 to k=2. But it seems this code does not work for the color images, I might have to find another one.

fredreload gravatar imagefredreload ( 2015-05-11 03:17:20 -0500 )edit

On second thought, maybe my image is correct but I need a different histogram comparison this time.

fredreload gravatar imagefredreload ( 2015-05-11 03:53:27 -0500 )edit

Man, there's no color and shape analysis, does it mean it's not doable?

fredreload gravatar imagefredreload ( 2015-05-11 04:11:55 -0500 )edit

hmm ? what is not doable ?

btw, what exactly are you trying to compare ? textures ? faces ?

if you want colour involved, maybe you need a different mechanism than lbp, e.g. filter convolutions ?

(machine learning is large, you barely scratched the surface...)

berak gravatar imageberak ( 2015-05-11 04:15:18 -0500 )edit

Right well, I am thinking of doing Gabor filter, but does it apply for color images (color + shape)? For 2D textures, not faces.

fredreload gravatar imagefredreload ( 2015-05-11 04:21:44 -0500 )edit

yes, gabor filters will work with color images.

berak gravatar imageberak ( 2015-05-11 04:31:58 -0500 )edit

Just a small remark, I notice you keep telling us you are reading in RGB images. Keep in mind that OpenCV reads in BGR images, certainly when you will be matching seperate channels, so that results will not be as expected from a RGB image. Like @berak said, you might need something else here.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-05-11 05:07:15 -0500 )edit