Ask Your Question

jaqqu7's profile - activity

2016-01-12 12:02:31 -0600 received badge  Editor (source)
2016-01-12 11:37:15 -0600 asked a question Problem with compareHist

I have pictures cut into halves and quarters like that:

halfImage[0] = Mat(greyimg, Rect(0, 0, cols/2, rows)).clone();
halfImage[1] = Mat(greyimg, Rect(cols/2, 0, cols/2, rows)).clone();

quarterImg[0] = Mat(greyimg, Rect(0, 0, cols / 2, rows / 2)).clone();
quarterImg[1] = Mat(greyimg, Rect(cols / 2, 0, cols / 2, rows / 2)).clone();
quarterImg[2] = Mat(greyimg, Rect(0, rows / 2, cols / 2, rows / 2)).clone();
quarterImg[3] = Mat(greyimg, Rect(cols / 2, rows / 2, cols / 2, rows / 2)).clone();

... and I try to calculate histograms for them like that:

    Mat dst;
    int histSize = 255; 
    int histSizeHalf = 127;
    Mat dstHalfVerticalOne, dstHalfVerticalTwo;
    dstHalfVerticalOne = halfImage[0];
    dstHalfVerticalTwo = halfImage[1];

    calcHist(&dstHalfVerticalOne, 1, 0, Mat(), halfImgHist[0], 1, &histSize, 0);
    calcHist(&dstHalfVerticalTwo, 1, 0, Mat(), halfImgHist[1], 1, &histSize, 0);

    Mat dstQuarterOne, dstQuarterTwo, dstQuarterThree, dstQuarterFour;
    dstQuarterOne = quarterImg[0];
    dstQuarterTwo = quarterImg[1];
    dstQuarterThree = quarterImg[2];
    dstQuarterFour = quarterImg[3];

    calcHist(&dstQuarterOne, 1, 0, Mat(), quarterImgHist[0], 1, &histSize, 0);
    calcHist(&dstQuarterTwo, 1, 0, Mat(), quarterImgHist[1], 1, &histSize, 0);
    calcHist(&dstQuarterThree, 1, 0, Mat(), quarterImgHist[2], 1, &histSize, 0);
    calcHist(&dstQuarterFour, 1, 0, Mat(), quarterImgHist[3], 1, &histSize, 0);

... and I have one more picture which is also cut this way.

But the problem appears when I want to compare those histograms like that:

for (int k = 0; k < picturesFromFolder.size(); k++)
{
    picturesFromFolder[0].sumHistCompValueVertical = 0;
    for (int c = 0; c < 2; c++)
    {
    picturesFromFolder[k].histCompValueHalfVertical[c] = compareHist(referencePicture.halfImgHist[c], picturesFromFolder[k].halfImgHist[c], HISTCMP_CORREL);

    picturesFromFolder[k].histCompValueHalfVertical[c] = compareHist(referencePicture.halfImgHist[c], picturesFromFolder[k].halfImgHist[c], HISTCMP_CORREL);

    picturesFromFolder[k].sumHistCompValueVertical = picturesFromFolder[k].sumHistCompValueVertical + picturesFromFolder[k].histCompValueHalfVertical[c];
    }
    cout << "Value of compareHist: " << picturesFromFolder[k].sumHistCompValueVertical << endl;
}

Function compareHist() just return 1. But when I am comparing whole picture the return values are correct. What I am doing wrong?

2016-01-11 10:47:15 -0600 commented question How to cut image to smaller pieces?

No, this is correct now.

2016-01-11 10:33:14 -0600 commented question How to cut image to smaller pieces?

Thanks! Now I understand what I did wrong. I did not know that the coordinates add up in this function. Your first comment helps me alot.

halfImage[0] = Mat(greyimg, Rect(0, 0, 163, 93)).clone();
halfImage[1] = Mat(greyimg, Rect(164, 0, 163, 93)).clone();

This is correct way.

2016-01-11 10:26:47 -0600 commented question How to cut image to smaller pieces?

So, Is it possible that I just keep using Rect() wrong way? My image has size of 327x93.

2016-01-11 10:19:06 -0600 asked a question How to cut image to smaller pieces?

I need to cut image in half and each of them save as different one. For example I have image in grayscale and I try to do it like this:

halfImg[0] = Mat(greyimg, Rect(0, 0, 163, 93)).clone();
halfImg[1] = Mat(greyimg, Rect(164, 0, 327, 93)).clone();

but the second one generates this error:

image description

Is there another way to do it in Open CV?