Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

we'll do this in 2 steps, the 1st will find the maximum of the channels, the 2nd will reduce over rows to a single column:

Mat bgr(5,5,CV_8UC3);
//Fill Random Numbers
randn(bgr,Scalar::all(125),Scalar::all(100));
cout << "bgr\n" << bgr<< endl;


// no need to iterate, since there's a cv::max() overload for whole Mat's:    
Mat chn[3];
split(bgr, chn);

Mat oneChan = max(chn[0], max(chn[1], chn[2]));

cout << "oneChan\n" << oneChan << endl;

// reduce over rows:
Mat maxR;
reduce(oneChan, maxR, 0, REDUCE_MAX);

cout << "maxR\n" << maxR << endl;

 bgr
[125, 141,  55,  82, 249,  97,  60, 156, 177,  10, 202, 120, 255,   0,   0;
  71,  50, 255, 152,   0, 255,  46,   0,   0,   0, 119, 255, 205,  99,  73;
 255, 162, 254,  61,  39, 232, 130,  97, 110,  88, 230, 172, 114, 228,  50;
  64, 104, 241,   0, 195, 103, 135, 151,  41, 190, 108, 255,  96,  45, 196;
 184, 194,  76,  67, 137,  29,  29, 242, 190, 162,   8, 255, 253, 255,  75]
oneChan
[141, 249, 177, 202, 255;
 255, 255,  46, 255, 205;
 255, 232, 130, 230, 228;
 241, 195, 151, 255, 196;
 194, 137, 242, 255, 255]
maxR
[255, 255, 242, 255, 255]