# distribution of color in 3d coordinates and diagonal of bounding box

As the title says I want to find the diagonal of bounding box of the ab-plane from an RGB to CIELab transformed image. I am not really sure how to achieve this but my fist idea is to get the distribution of color in 3d coordinates (how do I get that in 3d coordinates?) and then get a bounding box of that distribution from where I can extract the length of the diagonal (I don't know can I visualize this afterwards with the viz module, not that important though). Does anyone have any experience how to achieve that? Should I use histogram, EM (expectation maximization) and estimate color distribution with a gaussian mixture model, or to play with something simple like to find the mean and standard deviation of each channel? I searched a bit in the net but I couldn't find something straight forward.

//Load the images

//Convert to Lab space and CV_32F1
Mat lab;
cvtColor(src, lab, COLOR_BGR2Lab );

lab.convertTo(src_lab,CV_32FC1);

// Split into individual channels
vector<Mat> channels;
split( lab, channels );

then what.....?

edit retag close merge delete

for 3d histogram you can use this post

( 2015-12-29 06:37:16 -0500 )edit

Sort by ยป oldest newest most voted

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 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)

more

can you explain it from start i really did not get it .

( 2016-10-23 08:53:15 -0500 )edit

what you did not understand? It is quite simple. Have a look on the code.

( 2016-10-26 16:27:40 -0500 )edit

Official site

GitHub

Wiki

Documentation