Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To answer my own question, finally it was much simpler from what I thought. Simply I just needed to treat the LAB color space in 3D coordinates, and draw a 3D axis-aligned bounding box of all values in each channel of the input image. Imagine that you have the following bounding box that represents the Lab color space in 3d:

     B-------C          
    /|      /|  
  A--------D |    
  |  F-----|-G  
  |/       |/    
  E--------H

The bounding box is defined by a min (G) and a max point (A), where if we consider the two points as Point1(x1, y1, z1) and Point2(x2, y2, z2) respectively then:

minPoint = (min(L),min(a),min(b))
maxPoint = (max(L),max(a),max(b))

and then my diagonal is actually the distance between the point A and G:

diagonal = sqrt[(x2 - x1)^2 + (y2 - y1)^2 + (z2 - z1)^2]

and in code:

//Load the images
Mat src = imread("image.png");

Mat lab;
cvtColor(src, lab, COLOR_BGR2Lab );

// Split into individual channels
Mat LabChannels[3];
split(lab_image, LabChannels);

double min_L, min_a, min_b, max_L, max_a, max_b;

cv::minMaxLoc(LabChannels[0], &min_L, &max_L);
cv::minMaxLoc(LabChannels[1], &min_a, &max_a);
cv::minMaxLoc(LabChannels[2], &min_b, &max_b);

Point3f minPoint(min_L, min_a, min_b);
Point3f maxPoint(max_L, max_a, max_b);

Point3f diff = maxPoint - minPoint;
float diagonal = cv::sqrt(diff.x*diff.x + diff.y*diff.y + diff.z*diff.z); // or norm(diff)