Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Insane max Hue ranges?

I don't why.. but for some reason is my histogram showing that the max hue value of my image is around 339498 which doesn't make sense for me..

I am trying to create a mask, that recognizes the dominant color of the picture, and based on that creates a mask. I've converted my image to HSV , and created a histogram based on the Hue channel, for which i look at the highest value.

then I manually check each Hue-value in the picture, to create a binary image of the things that contains the dominant color.

But for some reason is my max Hue value too high no idea why.. here is the code.

#include <iostream>
#include "opencv2/opencv.hpp"

using namespace std;
using namespace cv;

int main(int argc, const char * argv[]) {
    std::cout << "Hello, World!\n";
    Mat src;
    src = imread("/Users/keerthikanratnarajah/Desktop/IMG_3607.jpg");
    Mat src_HSV;
    cvtColor(src, src_HSV, CV_RGB2HSV);
    //vector<Mat> HSV_planes;
    //split(src_HSV, HSV_planes);
    int hbins = 30;
    int histSize[] = {hbins};
    float hranges[] = { 0, 180 };
    const float* ranges[] = { hranges };
    Mat hist;
    int channels[] = {0};

    calcHist(&src_HSV, 1, channels, Mat(), hist, 1, histSize, ranges,true,false);
    double maxVal=0;
    minMaxLoc(hist, 0, &maxVal, 0, 0);
    cout << "highest Hue value: " << maxVal << endl;
    Mat histImg = Mat::zeros(hbins*10,hbins*10, CV_8UC3);
    Mat result(src_HSV.rows,src_HSV.cols,CV_8UC1);
    for (int i = 0; i<src_HSV.rows; i++) {
        for (int j = 0; j<src_HSV.cols; j++) {
            Vec3b HSV = src_HSV.at<Vec3b>(i,j);
            if (HSV[0]==maxVal)
            {
                cout << "HSV Lower: " << HSV[0] << endl;
                result.at<uchar>(i,j) = 0;
            }
            else
            {
                cout << "HSV Higher': " << HSV[0] << endl;
                result.at<uchar>(i,j) = 255;
            }
        }
    }

    /// Draw for each channel
    for( int h = 0; h < hbins; h++ )
        for( int s = 0; s < hbins; s++ )
        {
            float binVal = hist.at<float>(h, s);
            int intensity = cvRound(binVal*255/maxVal);
            rectangle( histImg, Point(h*10, s*10),
                      Point( (h+1)*10 - 1, (s+1)*10 - 1),
                      Scalar::all(intensity),
                      CV_FILLED );
        }

    while (waitKey(1)) {
        imshow("Hue-channel",  src_HSV);
        //imshow("S-channel", HSV_planes[1]);
        //imshow("V-channel", HSV_planes[2]);
        imshow("histimage",histImg);
        imshow("result", result);
    }



    return 0;
}

Insane max Hue ranges?

I don't why.. but for some reason is my histogram showing that the max hue value of my image is around 339498 which doesn't make sense for me..

I am trying to create a mask, that recognizes the dominant color of the picture, and based on that creates a mask. I've converted my image to HSV , and created a histogram based on the Hue channel, for which i look at the highest value.

then I manually check each Hue-value in the picture, to create a binary image of the things that contains the dominant color.

But for some reason is my max Hue value too high no idea why.. here is the code.

#include <iostream>
#include "opencv2/opencv.hpp"

using namespace std;
using namespace cv;

int main(int argc, const char * argv[]) {
    std::cout << "Hello, World!\n";
    Mat src;
    src = imread("/Users/keerthikanratnarajah/Desktop/IMG_3607.jpg");
    Mat src_HSV;
    cvtColor(src, src_HSV, CV_RGB2HSV);
    //vector<Mat> HSV_planes;
    //split(src_HSV, HSV_planes);
    int hbins = 30;
    int histSize[] = {hbins};
    float hranges[] = { 0, 180 };
    const float* ranges[] = { hranges };
    Mat hist;
    int channels[] = {0};

    calcHist(&src_HSV, 1, channels, Mat(), hist, 1, histSize, ranges,true,false);
    double maxVal=0;
    minMaxLoc(hist, 0, &maxVal, 0, 0);
    cout << "highest Hue value: " << maxVal << endl;
    Mat histImg = Mat::zeros(hbins*10,hbins*10, CV_8UC3);
    Mat result(src_HSV.rows,src_HSV.cols,CV_8UC1);
    for (int i = 0; i<src_HSV.rows; i++) {
        for (int j = 0; j<src_HSV.cols; j++) {
            Vec3b HSV = src_HSV.at<Vec3b>(i,j);
            if (HSV[0]==maxVal)
            {
                cout << "HSV Lower: " << HSV[0] << endl;
                result.at<uchar>(i,j) = 0;
            }
            else
            {
                cout << "HSV Higher': " << HSV[0] << endl;
                result.at<uchar>(i,j) = 255;
            }
        }
    }

    /// Draw for each channel
    for( int h = 0; h < hbins; h++ )
        for( int s = 0; s < hbins; s++ )
        {
            float binVal = hist.at<float>(h, s);
            int intensity = cvRound(binVal*255/maxVal);
            rectangle( histImg, Point(h*10, s*10),
                      Point( (h+1)*10 - 1, (s+1)*10 - 1),
                      Scalar::all(intensity),
                      CV_FILLED );
        }

    while (waitKey(1)) {
        imshow("Hue-channel",  src_HSV);
        //imshow("S-channel", HSV_planes[1]);
        //imshow("V-channel", HSV_planes[2]);
        imshow("histimage",histImg);
        imshow("result", result);
    }



    return 0;
}

Insane max Hue ranges?

I don't why.. but for some reason is my histogram showing that the max hue value of my image is around 339498 which doesn't make sense for me..

I am trying to create a mask, that recognizes the dominant color of the picture, and based on that creates a mask. I've converted my image to HSV , and created a histogram based on the Hue channel, for which i look at the highest value.

then I manually check each Hue-value in the picture, to create a binary image of the things that contains the dominant color.

But for some reason is my max Hue value too high no idea why.. here is the code.

#include <iostream>
#include "opencv2/opencv.hpp"

using namespace std;
using namespace cv;

int main(int argc, const char * argv[]) {
    std::cout << "Hello, World!\n";
    Mat src;
    src = imread("/Users/keerthikanratnarajah/Desktop/IMG_3607.jpg");
    Mat src_HSV;
    cvtColor(src, src_HSV, CV_RGB2HSV);
    //vector<Mat> HSV_planes;
    //split(src_HSV, HSV_planes);
    int hbins = 30;
    int histSize[] = {hbins};
    float hranges[] = { 0, 180 };
    const float* ranges[] = { hranges };
    Mat hist;
    int channels[] = {0};

    calcHist(&src_HSV, 1, channels, Mat(), hist, 1, histSize, ranges,true,false);
    double maxVal=0;
    minMaxLoc(hist, 0, &maxVal, 0, 0);
    cout << "highest Hue value: " << maxVal << endl;
    Mat histImg = Mat::zeros(hbins*10,hbins*10, CV_8UC3);
    Mat result(src_HSV.rows,src_HSV.cols,CV_8UC1);
    for (int i = 0; i<src_HSV.rows; i++) {
        for (int j = 0; j<src_HSV.cols; j++) {
            Vec3b HSV = src_HSV.at<Vec3b>(i,j);
            if (HSV[0]==maxVal)
            {
                cout << "HSV Lower: " << HSV[0] << endl;
                result.at<uchar>(i,j) = 0;
            }
            else
            {
                cout << "HSV Higher': " << HSV[0] << endl;
                result.at<uchar>(i,j) = 255;
            }
        }
    }

    /// Draw for each channel
    for( int h = 0; h < hbins; h++ )
        for( int s = 0; s < hbins; s++ )
        {
            float binVal = hist.at<float>(h, s);
            int intensity = cvRound(binVal*255/maxVal);
            rectangle( histImg, Point(h*10, s*10),
                      Point( (h+1)*10 - 1, (s+1)*10 - 1),
                      Scalar::all(intensity),
                      CV_FILLED );
        }

    while (waitKey(1)) {
        imshow("Hue-channel",  src_HSV);
        //imshow("S-channel", HSV_planes[1]);
        //imshow("V-channel", HSV_planes[2]);
        imshow("histimage",histImg);
        imshow("result", result);
    }



    return 0;
}

test image image description

Insane max Hue ranges?

I don't why.. but for some reason is my histogram showing that the max hue value of my image is around 339498 which doesn't make sense for me..

I am trying to create a mask, that recognizes the dominant color of the picture, and based on that creates a mask. I've converted my image to HSV , and created a histogram based on the Hue channel, for which i look at the highest value.

then I manually check each Hue-value in the picture, to create a binary image of the things that contains the dominant color.

But for some reason is my max Hue value too high no idea why.. here is the code.

#include <iostream>
#include "opencv2/opencv.hpp"

using namespace std;
using namespace cv;

int main(int argc, const char * argv[]) {
    std::cout << "Hello, World!\n";
    Mat src;
    src = imread("/Users/keerthikanratnarajah/Desktop/IMG_3607.jpg");
imread("/Users/x/Desktop/IMG_3607.jpg");
    Mat src_HSV;
    cvtColor(src, src_HSV, CV_RGB2HSV);
    //vector<Mat> HSV_planes;
    //split(src_HSV, HSV_planes);
    int hbins = 30;
    int histSize[] = {hbins};
    float hranges[] = { 0, 180 };
    const float* ranges[] = { hranges };
    Mat hist;
    int channels[] = {0};

    calcHist(&src_HSV, 1, channels, Mat(), hist, 1, histSize, ranges,true,false);
    double maxVal=0;
    minMaxLoc(hist, 0, &maxVal, 0, 0);
    cout << "highest Hue value: " << maxVal << endl;
    Mat histImg = Mat::zeros(hbins*10,hbins*10, CV_8UC3);
    Mat result(src_HSV.rows,src_HSV.cols,CV_8UC1);
    for (int i = 0; i<src_HSV.rows; i++) {
        for (int j = 0; j<src_HSV.cols; j++) {
            Vec3b HSV = src_HSV.at<Vec3b>(i,j);
            if (HSV[0]==maxVal)
            {
                cout << "HSV Lower: " << HSV[0] << endl;
                result.at<uchar>(i,j) = 0;
            }
            else
            {
                cout << "HSV Higher': " << HSV[0] << endl;
                result.at<uchar>(i,j) = 255;
            }
        }
    }

    /// Draw for each channel
    for( int h = 0; h < hbins; h++ )
        for( int s = 0; s < hbins; s++ )
        {
            float binVal = hist.at<float>(h, s);
            int intensity = cvRound(binVal*255/maxVal);
            rectangle( histImg, Point(h*10, s*10),
                      Point( (h+1)*10 - 1, (s+1)*10 - 1),
                      Scalar::all(intensity),
                      CV_FILLED );
        }

    while (waitKey(1)) {
        imshow("Hue-channel",  src_HSV);
        //imshow("S-channel", HSV_planes[1]);
        //imshow("V-channel", HSV_planes[2]);
        imshow("histimage",histImg);
        imshow("result", result);
    }



    return 0;
}

test image image description

Insane max Hue ranges?

I don't why.. but for some reason is my histogram showing that the max hue value of my image is around 339498 which doesn't make sense for me..

I am trying to create a mask, that recognizes the dominant color of the picture, and based on that creates a mask. I've converted my image to HSV , and created a histogram based on the Hue channel, for which i look at the highest value.

then I manually check each Hue-value in the picture, to create a binary image of the things that contains the dominant color.

But for some reason is my max Hue value too high no idea why.. here is the code.

#include <iostream>
#include "opencv2/opencv.hpp"

using namespace std;
using namespace cv;

int main(int argc, const char * argv[]) {
    std::cout << "Hello, World!\n";
    Mat src;
    src = imread("/Users/x/Desktop/IMG_3607.jpg");
    Mat src_HSV;
    cvtColor(src, src_HSV, CV_RGB2HSV);
    //vector<Mat> HSV_planes;
    //split(src_HSV, HSV_planes);
    int hbins = 30;
    int histSize[] = {hbins};
    float hranges[] = { 0, 180 };
    const float* ranges[] = { hranges };
    Mat hist;
    int channels[] = {0};

    calcHist(&src_HSV, 1, channels, Mat(), hist, 1, histSize, ranges,true,false);
    double maxVal=0;
    minMaxLoc(hist, 0, &maxVal, 0, 0);
    cout << "highest Hue value: " << maxVal << endl;
    Mat histImg = Mat::zeros(hbins*10,hbins*10, CV_8UC3);
    Mat result(src_HSV.rows,src_HSV.cols,CV_8UC1);
    for (int i = 0; i<src_HSV.rows; i++) {
        for (int j = 0; j<src_HSV.cols; j++) {
            Vec3b HSV = src_HSV.at<Vec3b>(i,j);
            if (HSV[0]==maxVal)
            {
                cout << "HSV Lower: " << HSV[0] << endl;
                result.at<uchar>(i,j) = 0;
            }
            else
            {
                cout << "HSV Higher': " << HSV[0] << endl;
                result.at<uchar>(i,j) = 255;
            }
        }
    }

    /// Draw for each channel
    for( int h = 0; h < hbins; h++ )
        for( int s = 0; s < hbins; s++ )
        {
            float binVal = hist.at<float>(h, s);
            int intensity = cvRound(binVal*255/maxVal);
            rectangle( histImg, Point(h*10, s*10),
                      Point( (h+1)*10 - 1, (s+1)*10 - 1),
                      Scalar::all(intensity),
                      CV_FILLED );
        }

    while (waitKey(1)) {
        imshow("Hue-channel",  src_HSV);
        //imshow("S-channel", HSV_planes[1]);
        //imshow("V-channel", HSV_planes[2]);
        imshow("histimage",histImg);
        imshow("result", result);
    }



    return 0;
}

test image image description