opencv histPrepareImages
static void histPrepareImages( const Mat* images, int nimages, const int* channels, const Mat& mask, int dims, const int* histSize, const float** ranges, bool uniform, std::vector<uchar*>& ptrs, std::vector<int>& deltas, Size& imsize, std::vector<double>& uniranges ) { int i, j, c; CV_Assert( channels != 0 || nimages == dims ); imsize = images[0].size(); int depth = images[0].depth(), esz1 = (int)images[0].elemSize1(); bool isContinuous = true; ptrs.resize(dims + 1); deltas.resize((dims + 1)*2); for( i = 0; i < dims; i++ ) { if(!channels) { j = i; c = 0; CV_Assert( images[j].channels() == 1 ); } else { c = channels[i]; CV_Assert( c >= 0 ); for( j = 0; j < nimages; c -= images[j].channels(), j++ ) if( c < images[j].channels() ) break; CV_Assert( j < nimages ); } CV_Assert( images[j].size() == imsize && images[j].depth() == depth ); if( !images[j].isContinuous() ) isContinuous = false; ptrs[i] = images[j].data + c*esz1; deltas[i*2] = images[j].channels(); deltas[i*2+1] = (int)(images[j].step/esz1 - imsize.width*deltas[i*2]); } if( !mask.empty() ) { CV_Assert( mask.size() == imsize && mask.channels() == 1 ); isContinuous = isContinuous && mask.isContinuous(); ptrs[dims] = mask.data; deltas[dims*2] = 1; deltas[dims*2 + 1] = (int)(mask.step/mask.elemSize1()); } #ifndef HAVE_TBB if( isContinuous ) { imsize.width *= imsize.height; imsize.height = 1; } #endif if( !ranges ) { CV_Assert( depth == CV_8U ); uniranges.resize( dims*2 ); for( i = 0; i < dims; i++ ) { uniranges[i*2] = histSize[i]/256.; uniranges[i*2+1] = 0; } } else if( uniform ) { uniranges.resize( dims*2 ); for( i = 0; i < dims; i++ ) { CV_Assert( ranges[i] && ranges[i][0] < ranges[i][1] ); double low = ranges[i][0], high = ranges[i][1]; double t = histSize[i]/(high - low); uniranges[i*2] = t; uniranges[i*2+1] = -t*low; } } else { for( i = 0; i < dims; i++ ) { size_t n = histSize[i]; for(size_t k = 0; k < n; k++ ) CV_Assert( ranges[i][k] < ranges[i][k+1] ); } } }
代码参考:opencv-3.4.1modulesimgprocsrchistogram.cpp
######################################