View Full Version : Gamut errors programmaticaly detection
Valentin Nikin
24th February 2021, 09:15
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?
Valentin Nikin
24th February 2021, 09:20
Simple code example
#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;
}
Sharc
27th February 2021, 15:39
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/20120403123714/http://www.equasys.de/colorconversion.html
https://forum.doom9.org/showthread.php?p=1936762#post1936762https://forum.doom9.org/showthread.php?p=1936762#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'.
Valentin Nikin
15th March 2021, 10:04
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?
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.