Ask Your Question
0

How can i calculate Image quality by using BRISQUE in Opencv 3.4.1?

asked 2018-09-03 06:13:19 -0600

Samjith888 gravatar image

updated 2018-09-03 06:57:39 -0600

berak gravatar image

I have go through several tutorial about BRISQUE algorithm ,but most of them are old tutorial and those contain error . So anyone can write the code or give a reference for this ? I gone through and this tutorial . I wrote the following code by using those tutorial but it showing errors .

 int main()
{
    Mat im = imread("C:/Users/Samjith.CP/Desktop/1.jpg");

    if (im.empty())
    {
        cout << "img read fail" << endl;
    }
    else
    {
        cvtColor(im, im, COLOR_BGR2GRAY); // convert to grayscale

        im.convertTo(im, 1.0 / 255); // normalize and copy the read image to orig_bw
        Mat mu(im.size(), CV_64FC1, 1);
        GaussianBlur(im, mu, Size(7, 7), 1.166); // apply gaussian blur
        Mat mu_sq = mu.mul(mu);

        // compute sigma
        Mat sigma (im.size(), CV_64FC1, 1);
        sigma = im.mul(im);
        GaussianBlur(sigma, sigma, Size(7, 7), 1.166); // apply gaussian blur
        subtract(sigma, mu_sq, sigma); // sigma = sigma - mu_sq
        cv::pow(sigma, double(0.5), sigma); // sigma = sqrt(sigma)
        add(sigma, Scalar(1.0 / 255), sigma); // to avoid DivideByZero Exception
        Mat structdis(im.size(), CV_64FC1, 1);
        subtract(im, mu, structdis); // structdis = im - mu
        divide(structdis, sigma, structdis);

        // declare shifting indices array
        int shifts[4][2] = { { 0, 1 },{ 1, 0 },{ 1, 1 },{ -1, 1 } };

        // calculate pair-wise products for every combination of shifting indices
        for (int itr_shift = 1; itr_shift <= 4; itr_shift++)
        {
            int* reqshift = shifts[itr_shift - 1]; // the required shift index
                                                   // declare shifted image
            Mat shifted_structdis(imdist_scaled.size(), CV_64F, 1);
            // BwImage is a helper class to create a copy of the image and create helper functions to access it's pixel values
            BwImage OrigArr(structdis);
            BwImage ShiftArr(shifted_structdis);
            // calculate pair-wise component for the given orientation
            for (int i = 0; i < structdis.rows; i++)
            {
                for (int j = 0; j < structdis.cols; j++) 
                {
                    if (i + reqshift[0] >= 0 && i + reqshift[0] < structdis.rows && j + reqshift[1] >= 0 && j + reqshift[1] < structdis.cols)
                    {
                        ShiftArr[i][j] = OrigArr[i + reqshift[0]][j + reqshift[1]];
                    }
                    else
                    {
                        ShiftArr[i][j] = 0;
                    }
                }
            }
            Mat shifted_new_structdis;
            shifted_new_structdis = ShiftArr.equate(shifted_new_structdis);
            // find the pairwise product
            multiply(structdis, shifted_new_structdis, shifted_new_structdis);
        }
        // make a svm_node object and push values of feature vectors into it
        struct svm_node x[37];

        // features is a rescaled vector to (-1, 1)
        for (int i =0 ; i < 36; ++i) 
        {
            x[i].value = features[i];
            x[i].index = i + 1; // svm_node indexes start from 1
        }

        // load the model from modelfile - allmodel
        string model = "allmodel";
        Ptr<ml::SVM> model = ml::SVM::load(modelfile.c_str());


            // get number of classes from the model
            int nr_class = svm_get_nr_class(model);
        double *prob_estimates = (double *)malloc(nr_class * sizeof(double));

        // predict the quality score using svm_predict_probability function
        qualityscore = svm->predict_probability(model, x, prob_estimates);

    }

}
edit retag flag offensive close merge delete

Comments

and the error ?

berak gravatar imageberak ( 2018-09-03 06:57:58 -0600 )edit
1
  • the original code is calculating an image pyramid here. (that's where imdist_scaled`came from ...). you probably need to do so, too.
  • the AGGDFit code went awol, it's an essential part of the algorithm, imho.
  • you can't use the SVM code, or the model with cv::SVM (i think, you have to you use libsvm from the answer link)
berak gravatar imageberak ( 2018-09-03 08:01:34 -0600 )edit

@berak: Can i proceed with above code by correcting errors(by using libsvm)?

Samjith888 gravatar imageSamjith888 ( 2018-09-04 05:55:42 -0600 )edit

i found this on my disk, maybe it helps.

berak gravatar imageberak ( 2018-09-04 06:00:53 -0600 )edit

and the svm code there is calculating a single regression score, not probabilities for different distortion classes. no idea, what you wanted.

berak gravatar imageberak ( 2018-09-04 06:08:53 -0600 )edit

@ berak : Objective Blind or No-Reference IQA- this all i want to use . I have a image and i want want to get the quality score . I got the above code and read about BRISQUE from this link

Samjith888 gravatar imageSamjith888 ( 2018-09-04 07:02:24 -0600 )edit

then you probably can use the existing allmodel with libsvm

berak gravatar imageberak ( 2018-09-04 07:16:08 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-09-03 06:21:22 -0600

berak gravatar image

updated 2018-09-03 06:44:28 -0600

there is a reference implementation for BRISQUE (and related algo's !) here: http://live.ece.utexas.edu/research/Q...

(unfortunately, some IplImages in it ...)

edit flag offensive delete link more

Comments

@berak : Yes , its using IplImage and diffcult to understand .Can u suggest the steps or code for checking the quality of an input image

Samjith888 gravatar imageSamjith888 ( 2018-09-04 05:13:04 -0600 )edit

not enough algorithms here ?

and academic code is never maintained, and has to be tweaked.

you also need some understanding of the theory, and some coding skill.

berak gravatar imageberak ( 2018-09-04 05:15:48 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-09-03 06:13:19 -0600

Seen: 1,901 times

Last updated: Sep 03 '18