added hconcat & vconcat functions for joining matrices; moved some inline functions out of the headers; fixed several bugs in documentation; removed MatND from docs

This commit is contained in:
Vadim Pisarevsky
2010-11-23 16:39:20 +00:00
parent dd3c62a4fe
commit f5e5b677c9
10 changed files with 162 additions and 56 deletions

View File

@@ -162,6 +162,13 @@ void split(const Mat& src, Mat* mv)
mixChannels( &src, 1, mv, cn, &pairs[0], cn );
}
}
void split(const Mat& m, vector<Mat>& mv)
{
mv.resize(!m.empty() ? m.channels() : 0);
if(!m.empty())
split(m, &mv[0]);
}
/****************************************************************************************\
* merge *
@@ -298,7 +305,10 @@ void merge(const Mat* mv, size_t _n, Mat& dst)
}
}
void merge(const vector<Mat>& mv, Mat& dst)
{
merge(!mv.empty() ? &mv[0] : 0, mv.size(), dst);
}
/****************************************************************************************\
* Generalized split/merge: mixing channels *
@@ -437,6 +447,13 @@ void mixChannels( const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts, const in
}
void mixChannels(const vector<Mat>& src, vector<Mat>& dst,
const int* fromTo, int npairs)
{
mixChannels(!src.empty() ? &src[0] : 0, src.size(),
!dst.empty() ? &dst[0] : 0, dst.size(), fromTo, npairs);
}
/****************************************************************************************\
* convertScale[Abs] *
\****************************************************************************************/

View File

@@ -480,6 +480,15 @@ void repeat(const Mat& src, int ny, int nx, Mat& dst)
memcpy( dst.data + y*dst.step, dst.data + (y - ssize.height)*dst.step, dsize.width );
}
Mat repeat(const Mat& src, int ny, int nx)
{
if( nx == 1 && ny == 1 )
return src;
Mat dst;
repeat(src, ny, nx, dst);
return dst;
}
}
/* dst = src */

View File

@@ -2299,7 +2299,11 @@ double Mahalanobis( const Mat& v1, const Mat& v2, const Mat& icovar )
return std::sqrt(result);
}
double Mahalonobis(const Mat& v1, const Mat& v2, const Mat& icovar)
{
return Mahalanobis(v1, v2, icovar);
}
/****************************************************************************************\
* cvMulTransposed *
\****************************************************************************************/

View File

@@ -845,6 +845,80 @@ void scalarToRawData(const Scalar& s, void* _buf, int type, int unroll_to)
Matrix Operations
\*************************************************************************************************/
void hconcat(const Mat* src, size_t nsrc, Mat& dst)
{
if( nsrc == 0 || !src )
{
dst.release();
return;
}
int totalCols = 0, cols = 0;
size_t i;
for( i = 0; i < nsrc; i++ )
{
CV_Assert( !src[i].empty() && src[i].dims <= 2 &&
src[i].rows == src[0].rows &&
src[i].type() == src[0].type());
totalCols += src[i].cols;
}
dst.create( src[0].rows, totalCols, src[0].type());
for( i = 0; i < nsrc; i++ )
{
Mat dpart(dst, Rect(cols, 0, src[i].cols, src[i].rows));
src[i].copyTo(dpart);
cols += src[i].cols;
}
}
void hconcat(const Mat& src1, const Mat& src2, Mat& dst)
{
Mat src[] = {src1, src2};
hconcat(src, 2, dst);
}
void hconcat(const vector<Mat>& src, CV_OUT Mat& dst)
{
hconcat(!src.empty() ? &src[0] : 0, src.size(), dst);
}
void vconcat(const Mat* src, size_t nsrc, Mat& dst)
{
if( nsrc == 0 || !src )
{
dst.release();
return;
}
int totalRows = 0, rows = 0;
size_t i;
for( i = 0; i < nsrc; i++ )
{
CV_Assert( !src[i].empty() && src[i].dims <= 2 &&
src[i].cols == src[0].cols &&
src[i].type() == src[0].type());
totalRows += src[i].rows;
}
dst.create( totalRows, src[0].cols, src[0].type());
for( i = 0; i < nsrc; i++ )
{
Mat dpart(dst, Rect(0, rows, src[i].cols, src[i].rows));
src[i].copyTo(dpart);
rows += src[i].rows;
}
}
void vconcat(const Mat& src1, const Mat& src2, Mat& dst)
{
Mat src[] = {src1, src2};
vconcat(src, 2, dst);
}
void vconcat(const vector<Mat>& src, CV_OUT Mat& dst)
{
vconcat(!src.empty() ? &src[0] : 0, src.size(), dst);
}
//////////////////////////////////////// set identity ////////////////////////////////////////////
void setIdentity( Mat& m, const Scalar& s )
{

View File

@@ -657,6 +657,16 @@ RNG& theRNG()
#endif
void randu(CV_OUT Mat& dst, const Scalar& low, const Scalar& high)
{
theRNG().fill(dst, RNG::UNIFORM, low, high);
}
void randn(CV_OUT Mat& dst, const Scalar& mean, const Scalar& stddev)
{
theRNG().fill(dst, RNG::NORMAL, mean, stddev);
}
template<typename T> static void
randShuffle_( Mat& _arr, RNG& rng, double iterFactor )
{