Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Programming and Hacking > Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 24th February 2021, 09:15   #1  |  Link
Valentin Nikin
Registered User
 
Join Date: Feb 2021
Posts: 4
Gamut errors programmaticaly detection

Hello!

I want to detect Gamut errors in file. And I try to use OpenCV to do it.
Accordinally EBU R 103 V3 (https://tech.ebu.ch/docs/r/r103.pdf)

Gamut Errors need detection if the RGB components and the corresponding Luminance (Y) signal exceed
the "Preferred Minimum/Maximum" range of digital sample levels

"Preferred Minimum/Maximum" range is [5, 246]

But any black pixels decoded with OpenCV has (0,0,0) values

Please help me. Maybe I'm misinterpreting the standard?

Last edited by Valentin Nikin; 24th February 2021 at 09:19.
Valentin Nikin is offline   Reply With Quote
Old 24th February 2021, 09:20   #2  |  Link
Valentin Nikin
Registered User
 
Join Date: Feb 2021
Posts: 4
Simple code example
Code:
 
#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdio.h>

using namespace cv;
using namespace std;

int main(int, char**) {
    Mat frame;
    VideoCapture cap("./video/Test_zapis_34.mp4");
    
    if (!cap.isOpened()) {
        cerr << "ERROR! Unable to open camera\n";
        return -1;
    }

    int min = 5;
    int max = 246;
    int frameCounter = 0;

    std::cout << "Start grabbing" << std::endl << "Press any key to terminate" << std::endl;
    for (;;) {
        cap.read(frame);
        if (frame.empty()) {
            cerr << "ERROR! blank frame grabbed\n";
            break;
        }

        int countPixelsOutsideGamut = 0;

        for (int i = 0; i < frame.rows; i++) {
            for (int j = 0; j < frame.cols; j++) {
                auto cmp = frame.at<Vec3b>(i, j);

                int r = cmp[0];
                int g = cmp[1];
                int b = cmp[2];

                std::cout << r << " " << g << " " << b << std::endl;

                if (r < min || r > max || g < min || g > max || b < min || b > max) {
                    countPixelsOutsideGamut++;
                }
            }
        }

        double percent = static_cast<double>(countPixelsOutsideGamut) / static_cast<double>(frame.rows * frame.cols) * 100;

        std::cout << frameCounter << " - " << percent << std::endl;

        imshow("Live", frame);

        frameCounter++;

        if (waitKey(5) >= 0) {
            break;
        }
    }
    return 0;
}
Valentin Nikin is offline   Reply With Quote
Old 27th February 2021, 15:39   #3  |  Link
Sharc
Registered User
 
Join Date: May 2006
Posts: 3,997
There exist different conversion matrices for converting between full and limited (TV) ranges of various color spaces.
See for example here:
https://software.intel.com/content/w...ml?language=en
https://web.archive.org/web/20120403...onversion.html
https://forum.doom9.org/showthread.p...62#post1936762

The EBU document just defines its "Preferred Range" which includes a typical (or practical) headroom/footroom to allow some overshoot/undershoot of the limited (TV) range. Something like halfway beteen 'limited' and 'full'.

Last edited by Sharc; 27th February 2021 at 15:53.
Sharc is offline   Reply With Quote
Old 15th March 2021, 10:04   #4  |  Link
Valentin Nikin
Registered User
 
Join Date: Feb 2021
Posts: 4
Sharc, thank you for reply. I implemented gamut detection algorithm using FFmpeg API and analyzing raw data from AVFrame.
But now I need to check corectness of my algorithm. Are there any free tools (or with trial version) to detection Gamut problems in video file?
Valentin Nikin is offline   Reply With Quote
Reply

Tags
ebur103, gamut, opencv

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 20:51.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.