Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Yes, it is possible. For the instance:

void ImageQualityController::calculateHist(const cv::Mat &input, float *blue, float *green, float *red)
{
    /* Calculates histograms of inputImage and copies them into input vectors,          *
     * it is caller responsibility to allocate memory for them, each needs float[256]   */

    int bins = 256;
    int histSize[] = { bins };
    float marginalRanges[] = { 0, 256 };
    const float* ranges[] = { marginalRanges };
    int channels[] = { 0 };
    cv::Mat hist;
    cv::calcHist(&input, 1, channels, cv::Mat(), // mask not used
        hist, 1, histSize, ranges,
        true, // the histogram is uniform
        false);
    auto pointer = hist.ptr<float>(0);
    for (auto i = 0; i < 256; i++) {
        blue[i] = pointer[i];
    }

    channels[0] = 1;
    cv::calcHist(&input, 1, channels, cv::Mat(), // mask not used
        hist, 1, histSize, ranges,
        true, // the histogram is uniform
        false);
    pointer = hist.ptr<float>(0);
    for (auto i = 0; i < 256; i++) {
        green[i] = pointer[i];
    }

    channels[0] = 2;
    cv::calcHist(&input, 1, channels, cv::Mat(), // mask not used
        hist, 1, histSize, ranges,
        true, // the histogram is uniform
        false);
    pointer = hist.ptr<float>(0);
    for (auto i = 0; i < 256; i++) {
        red[i] = pointer[i];
    }
}

Yes, it is possible. For the instance:

void ImageQualityController::calculateHist(const cv::Mat &input, float *blue, float *green, float *red)
{
    /* Calculates histograms of inputImage and copies them into input vectors,          *
     * it is caller responsibility to allocate memory for them, each needs float[256]   */

    int bins = 256;
    int histSize[] = { bins };
    float marginalRanges[] = { 0, 256 };
    const float* ranges[] = { marginalRanges };
     int channels[] = { 0 };
    cv::Mat hist;
    cv::calcHist(&input, 1, channels, cv::Mat(), // mask not used
        hist, 1, histSize, ranges,
        true, // the histogram is uniform
        false);
    auto pointer = hist.ptr<float>(0);
    for (auto i = 0; i < 256; i++) {
        blue[i] = pointer[i];
    }

    channels[0] = 1;
    cv::calcHist(&input, 1, channels, cv::Mat(), // mask not used
        hist, 1, histSize, ranges,
        true, // the histogram is uniform
        false);
    pointer = hist.ptr<float>(0);
    for (auto i = 0; i < 256; i++) {
        green[i] = pointer[i];
    }

    channels[0] = 2;
    cv::calcHist(&input, 1, channels, cv::Mat(), // mask not used
        hist, 1, histSize, ranges,
        true, // the histogram is uniform
        false);
    pointer = hist.ptr<float>(0);
    for (auto i = 0; i < 256; i++) {
        red[i] = pointer[i];
    }
}