Ask Your Question

Revision history [back]

There are some problems with cvtColor and convertTo.

  1. You cannot use CV_32F with cvtColor
  2. normalisation constant in convertTo are wrong. You have to find min and max before convertTo

you should try like this :

    Mat outImg =imread("f:/lib/opencv/samples/data/lena.jpg",IMREAD_GRAYSCALE);
    Mat gaborOut, outAsFloat, gaborImage;
    outImg.convertTo( outAsFloat, CV_32F);
    Mat gaborKernel = getGaborKernel(cv::Size(30, 30), 1, 0, 1, 0.02);
    filter2D(outAsFloat, gaborOut, CV_32F, gaborKernel);
    double xmin[4],xmax[4];
    minMaxIdx(gaborOut,xmin,xmax);
    gaborOut.convertTo(gaborImage, CV_8U, 1.0 / 255.0);
    imshow("1-problem", gaborImage);
    gaborOut.convertTo(gaborImage, CV_8U, 255.0/(xmax[0]-xmin[0]),-255*xmin[0] /(xmax[0] -xmin[0]));
    imshow("2-CV_8U", gaborImage);
    waitKey(0);

There are some problems with cvtColor and convertTo.

  1. You cannot use CV_32F with cvtColor CV_32F cosntant is equal to COLOR_BGRA2RGBA. I don't think that is what you want.
  2. normalisation constant in convertTo are wrong. You have to find min and max before convertTo

you should try like this :

    Mat outImg =imread("f:/lib/opencv/samples/data/lena.jpg",IMREAD_GRAYSCALE);
    Mat gaborOut, outAsFloat, gaborImage;
    outImg.convertTo( outAsFloat, CV_32F);
    Mat gaborKernel = getGaborKernel(cv::Size(30, 30), 1, 0, 1, 0.02);
    filter2D(outAsFloat, gaborOut, CV_32F, gaborKernel);
    double xmin[4],xmax[4];
    minMaxIdx(gaborOut,xmin,xmax);
    gaborOut.convertTo(gaborImage, CV_8U, 1.0 / 255.0);
    imshow("1-problem", gaborImage);
    gaborOut.convertTo(gaborImage, CV_8U, 255.0/(xmax[0]-xmin[0]),-255*xmin[0] /(xmax[0] -xmin[0]));
    imshow("2-CV_8U", gaborImage);
    waitKey(0);