本文整理汇总了C++中imatrix::size方法的典型用法代码示例。如果您正苦于以下问题:C++ imatrix::size方法的具体用法?C++ imatrix::size怎么用?C++ imatrix::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imatrix
的用法示例。
在下文中一共展示了imatrix::size方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeIntVecs
int writeIntVecs(imatrix & im, string fname, int buffsize) {
int i, j, nrows, fmt, ncols, nnz, v;
ostream *ofstr = open_out_buf(fname.c_str(), buffsize);
ncols = 2;
nnz = 0;
for (i = 0, nrows = 0; i < im.size(); i++) nrows += im[i].size();
fmt = 110;
ofstr->write((const char *)&fmt, 4);
ofstr->write((const char *)&nrows, 4);
ofstr->write((const char *)&ncols, 4);
ofstr->write((const char *)&nnz, 4);
for (i = 0; i < im.size(); i++) {
for (j = 0; j < im[i].size(); j++) {
ofstr->write((const char *)&i, 4);
}
}
for (i = 0; i < im.size(); i++) {
ivector & ivv = im[i];
for (j = 0; j < ivv.size(); j++) {
v = ivv[j];
ofstr->write((const char *)&v, 4);
}
}
closeos(ofstr);
return 0;
}
示例2: histogramMethodNoBoundary
// applies the histogramMethod for the type boundary NoBoundary
bool kNearestNeighFilter::histogramMethodNoBoundary(const imatrix& src,
imatrix& dest) const {
const int limit = sizeOfKernel/2; //half size of the kernel
int i,j,row,col;
ivector histogram(histoSize,0);
dest.resize(src.size(),0,false,false);
//runs through the src's columns,inside the image
const int lastRow = src.lastRow()-limit;
for(row=limit;row<=lastRow;++row) {
histogram.fill(0);
// first block per row
const int r = row+limit;
for(i=row-limit;i<=r;++i)
for(j=0;j<sizeOfKernel;++j)
++histogram.at(src.at(i,j));
dest.at(row,limit)=getMostLabel(histogram,src,row,limit);
// runs inside the image
histogramMethodMiddle(src,dest,histogram,row,col);
}
return true;
};
示例3: apply
bool regionMerge::apply(const imatrix& srcmask,
const dmatrix& simMat,
const dvector& thresholds,
imatrix& destmask) const {
int i,j;
const dvector& thrs = thresholds;
ivector eLab(simMat.rows());
for (i=0;i<eLab.size();++i)
eLab.at(i) = i;
double a;
for (j=0;j<simMat.rows();++j)
for (i=0;i<simMat.columns();++i) {
if (simMat.at(j,i) > (a=max(thrs.at(j),thrs.at(i))) ) {
// cout<<j<<" "<<i<<" "<<simMat.at(j,i)<<" "<<a<<endl;
if (eLab.at(j)>eLab.at(i)) {
eLab.at(j)=eLab.at(i);
} else {
eLab.at(i)=eLab.at(j);
}
}
}
// now correct the labels
for (j=eLab.size()-1;j>=0;--j) { //todo
i = j;
while (eLab.at(i) != i) {
i=eLab.at(i);
}
eLab.at(j) = i;
}
destmask.resize(srcmask.size(),0,false,false);
for (j=0;j<srcmask.rows();++j)
for (i=0;i<srcmask.columns();++i) {
destmask.at(j,i) = eLab.at(srcmask.at(j,i));
}
return true;
};
示例4: histogramMethodZero
// applies the histogramMethod for the type boundary Zero
bool kNearestNeighFilter::histogramMethodZero(const imatrix& src,
imatrix& dest) const {
int i,j,row,col;//index
const int limit = sizeOfKernel/2; //half size of the kernel
const int rowSize = src.rows();
const int columnSize = src.columns();
const int lastCol = src.lastColumn()-limit;
const int lastRow = src.lastRow()-limit;
ivector histogram(histoSize,0); //the histogram for a channel8
dest.resize(src.size(),ubyte(0),false,false);
//runs area 4,5,6
for(row=limit;row<=lastRow;++row) {
const int r = row+limit;
histogram.fill(0);
col=0;
//number of 0's are known
histogram.at(0) = sizeOfKernel*(sizeOfKernel-limit-1);
for(i=row-limit;i<=r;++i)
for(j=0;j<=limit;++j)
++histogram.at(src.at(i,j));
dest.at(row,col) = getMostLabel(histogram,src,row,col);
// the kernel at the position between the border and the image
while(col < limit) {
histogram.at(0) -= sizeOfKernel; // cut all the 0 in the leftmost column
++col;
j = col+limit; // for each pixel in the rightmost column
for(i=row-limit;i<=r;++i)
++histogram.at(src.at(i,j));
dest.at(row,col) = getMostLabel(histogram,src,row,col);
}
//runs area 5
histogramMethodMiddle(src,dest,histogram,row,col);
// area 6
col = lastCol;
while(col < (columnSize-1)) {
j = col-limit;
for(i=row-limit;i<=r;++i)
--histogram.at(src.at(i,j));
++col;
histogram.at(0) += sizeOfKernel;
dest.at(row,col) = getMostLabel(histogram,src,row,col);
}
}
// runs area 1,2,3
for(row=0;row<limit;++row) {
const int r=row+limit;
// runs middle top rows (area 2)
for(col=limit;col<=lastCol;++col) {
histogram.fill(0);
const int c=col+limit;
histogram.at(0) = sizeOfKernel*(sizeOfKernel-(limit+1)-row);
for(i=0;i<=r;++i)
for(j=col-limit;j<=c;++j)
++histogram.at(src.at(i,j));
dest.at(row,col) = getMostLabel(histogram,src,row,col) ;
}
// runs left top corner (area 1);
for(col=0;col<limit;++col) {
histogram.fill(0);
const int c=col+limit;
histogram.at(0) = sizeOfKernel*sizeOfKernel-(limit+1)*(limit+1+row+col)-col*row;
for(i=0;i<=r;++i)
for(j=0;j<=c;++j)
++histogram.at(src.at(i,j));
dest.at(row,col) = getMostLabel(histogram,src,row,col);
}
// runs top right corner (area 3)
for(col=lastCol+1;col<=columnSize-1;++col) {
histogram.fill(0);
const int c=columnSize-1;
histogram.at(0) = sizeOfKernel*sizeOfKernel
-(limit+1)*(limit+1+row+(columnSize-1-col))-row*(columnSize-1-col);
for(i=0;i<=r;++i)
for(j=col-limit;j<=c;++j)
++histogram.at(src.at(i,j));
dest.at(row,col) = getMostLabel(histogram,src,row,col);
}
}
//runs the rows at the bottom (area 7,8,9)
for(row=lastRow+1;row<=rowSize-1;++row) {
//runs middle bottom rows (area 8)
for(col=limit;col<=lastCol;++col) {
histogram.fill(0);
const int c=col+limit;
histogram.at(0) = sizeOfKernel*(sizeOfKernel-(limit+1)-(rowSize-1-row));
for(i=row-limit;i<=rowSize-1;++i)
for(j=col-limit;j<=c;++j)
++histogram.at(src.at(i,j));
dest.at(row,col) = getMostLabel(histogram,src,row,col);
//.........这里部分代码省略.........
示例5: histogramMethodMirror
// applies the histogramMethod for the type boundary Mirror
bool kNearestNeighFilter::histogramMethodMirror(const imatrix& src,
imatrix& dest) const {
int i,j,row,col;//index
const int limit = sizeOfKernel/2; //half size of the kernel
const int rowSize = src.rows();
const int columnSize = src.columns();
const int lastCol = src.lastColumn()-limit;
const int lastRow = src.lastRow()-limit;
ivector histogram(histoSize,0);
dest.resize(src.size(),0,false,false);
//runs through the src's columns,inside the image
for(row=limit;row<=lastRow;++row) {
histogram.fill(0);
col=0;
const int c=col+limit;
const int r = row+limit;
for(i=row-limit;i<=r;++i)
for(j=col-limit;j<=c;++j) {
if(j<0)
++histogram.at(src.at(i,-j-1));
else // if(j>=0)
++histogram.at(src.at(i,j));
}
dest.at(row,col) = getMostLabel(histogram,src,row,col);
while(col < limit) {
j = col-limit;
for(i=row-limit;i<=r;++i)
--histogram.at(src.at(i,-j-1));
++col;
j=col+limit;
for(i=row-limit;i<=r;++i)
++histogram.at(src.at(i,j));
dest.at(row,col) = getMostLabel(histogram,src,row,col);
}
// runs inside the image
histogramMethodMiddle(src,dest,histogram,row,col);
col=lastCol;
while(col < (columnSize-1)) {
j = col-limit;
for(i=row-limit;i<=r;++i)
--histogram.at(src.at(i,j));
++col;
j=col+limit;
for(i=row-limit;i<=r;++i)
++histogram.at(src.at(i,columnSize-1+(columnSize-j)));
dest.at(row,col) = getMostLabel(histogram,src,row,col);
}
}
// areas 1,2,3
for(row=0;row<limit;++row) {
const int r=row+limit;
// runs middle top rows (area 2)
for(col=limit;col<=lastCol;++col) {
histogram.fill(0);
const int c=col+limit;
for(i=row-limit;i<=r;++i)
for(j=col-limit;j<=c;++j) {
if(i<0)
++histogram.at(src.at(-i-1,j));
else //if(i>=0)
++histogram.at(src.at(i,j));
}
dest.at(row,col) = getMostLabel(histogram,src,row,col);
}
// runs top left corner (area 1)
for(col=0;col<limit;++col) {
histogram.fill(0);
const int c=col+limit;
for(i=row-limit;i<=r;++i)
for(j=col-limit;j<=c;++j) {
if(i<0 && j<0)
++histogram.at(src.at(-i-1,-j-1));
else if(i>=0 && j<0)
++histogram.at(src.at(i,-j-1));
else if(i<0 && j>=0)
++histogram.at(src.at(-i-1,j));
else //if(i>=0 && j>=0)
++histogram.at(src.at(i,j));
}
dest.at(row,col) = getMostLabel(histogram,src,row,col);
}
//runs top right corner (area 3)
for(col=lastCol+1;col<columnSize;++col) {
histogram.fill(0);
const int c=col+limit;
for(i=row-limit;i<=r;++i)
for(j=col-limit;j<=c;++j) {
if(i<0 && j<=columnSize-1)
++histogram.at(src.at(-i-1,j));
//.........这里部分代码省略.........
示例6: histogramMethodPeriodic
// applies the histogramMethod for the type boundary Periodic
bool kNearestNeighFilter::histogramMethodPeriodic(const imatrix& src,
imatrix& dest) const {
int i,j,row,col;//index
ivector histogram(histoSize,0);
const int limit = sizeOfKernel/2; //half size of the kernel
const int rowSize = src.rows();
const int columnSize = src.columns();
const int lastCol = src.lastColumn()-limit;
const int lastRow = src.lastRow()-limit;
dest.resize(src.size(),0,false,false);
//runs through the src's columns area 4,5,6
for(row=limit;row<=lastRow;++row) {
histogram.fill(0);
col=0;
const int c = col+limit;
const int r = row+limit;
for(i=row-limit;i<=r;++i)
for(j=col-limit;j<=c;++j) {
if(j<0)
++histogram.at(src.at(i,j+columnSize));
else // if(j>=0)
++histogram.at(src.at(i,j));
}
dest.at(row,col)=getMostLabel(histogram,src,row,col);
while(col < limit) {
j = col-limit;
for(i=row-limit;i<=r;++i)
--histogram.at(src.at(i,j+columnSize));
++col;
j=col+limit;
for(i=row-limit;i<=r;++i)
++histogram.at(src.at(i,j));
dest.at(row,col) = getMostLabel(histogram,src,row,col);
}
//runs inside the image
histogramMethodMiddle(src,dest,histogram,row,col);
col=lastCol;
while(col < (columnSize-1)) {
j = col-limit;
for(i=row-limit;i<=r;++i)
--histogram.at(src.at(i,j)); // column of intensity,take off in the histogram
++col;
j=col+limit;
for(i=row-limit;i<=r;++i)
++histogram.at(src.at(i,j-columnSize));
dest.at(row,col) = getMostLabel(histogram,src,row,col);
}
}
//runs top rows (area 1,2,3)
for(row=0;row<limit;++row) {
const int r=row+limit;
for(col=limit;col<=lastCol;++col) { // runs top middle rows (area 2)
histogram.fill(0);
const int c=col+limit;
for(i=row-limit;i<=r;++i)
for(j=col-limit;j<=c;++j) {
if(i<0)
++histogram.at(src.at(i+rowSize,j));
else //if(i>=0)
++histogram.at(src.at(i,j));
}
dest.at(row,col) = getMostLabel(histogram,src,row,col);
}
for(col=0;col<limit;++col) { // runs top left corner (area 1)
histogram.fill(0);
const int c=col+limit;
for(i=row-limit;i<=r;++i)
for(j=col-limit;j<=c;++j) {
if(i<0 && j<0)
++histogram.at(src.at(rowSize+i,columnSize+j));
else if(i>=0 && j<0)
++histogram.at(src.at(i,columnSize+j));
else if(i<0 && j>=0)
++histogram.at(src.at(rowSize+i,j));
else //if(i>=0 && j>=0)
++histogram.at(src.at(i,j));
}
dest.at(row,col) = getMostLabel(histogram,src,row,col);
}
for(col=lastCol+1;col<columnSize;++col) { //runs top right corner area 3
histogram.fill(0);
const int c=col+limit;
for(i=row-limit;i<=r;++i)
for(j=col-limit;j<=c;++j) {
if(i<0 && j<=columnSize-1)
++histogram.at(src.at(rowSize+i,j));
else if(i<0 && j>columnSize-1)
++histogram.at(src.at(rowSize+i,j-columnSize));
else if(i>=0 && j>columnSize-1)
//.........这里部分代码省略.........
示例7: histogramMethodConstant
// applies the histogramMethod for the type boundary Constant
bool kNearestNeighFilter::histogramMethodConstant(const imatrix& src,
imatrix& dest) const {
// image is divided in 9 areas, which are calc one by one
// 1| 2 |3
// ---------
// | |
// 4| 5 |6
// | |
// ----------
// 7| 8 |9
int i,j,row,col;//index
ivector histogram(histoSize,0);
const int rowSize = src.rows();
const int columnSize = src.columns();
const int limit = sizeOfKernel/2; //half size of the kernel
const int lastCol = src.lastColumn()-limit;
const int lastRow = src.lastRow()-limit;
dest.resize(src.size(),0,false,false);
//runs through the src's columns
// (area:4,5,6) only kernels with full kernel-height
for(row=limit;row<=lastRow;++row) {
histogram.fill(0);
// first full kernel (area4)
col=0;
const int r = row+limit;
const int c = col+limit;
for(i=row-limit;i<=r;++i)
for(j=col-limit;j<=c;++j) { //todo better
if(j<0)
++histogram.at(src.at(i,0));
else// if(j>=0)
++histogram.at(src.at(i,j));
}
dest.at(row,col)=getMostLabel(histogram,src,row,col);
// rest (area 4)
while(col < limit) {
for(i=row-limit;i<=r;++i)
--histogram.at(src.at(i,0));
++col;
j=col+limit;
for(i=row-limit;i<=r;++i)
++histogram.at(src.at(i,j));
dest.at(row,col)=getMostLabel(histogram,src,row,col);
}
// area 5
histogramMethodMiddle(src,dest,histogram,row,col);
// area 6
col=lastCol;
while(col < (columnSize-1)) {
j=col-limit;
for(i=row-limit;i<=r;++i)
--histogram.at(src.at(i,j));
++col;
j = columnSize-1;
for(i=row-limit;i<=r;++i)
++histogram.at(src.at(i,j));
dest.at(row,col)=getMostLabel(histogram,src,row,col);
}
} // area 4,5,6
// areas 1,2,3,7,8,9
for(row=0;row<limit;++row) { //runs top rows (1,2,3)
const int r=row+limit;
// runs middle top rows (area 2)
for(col=limit;col<=lastCol;++col) {
histogram.fill(0);
const int c=col+limit;
for(i=row-limit;i<=r;++i)
for(j=col-limit;j<=c;++j) {
if(i<0)
++histogram.at(src.at(0,j));
else//if(i>=0) {
++histogram.at(src.at(i,j));
}
dest.at(row,col)=getMostLabel(histogram,src,row,col);
}
// runs left top corner (area 1)
for(col=0;col<limit;++col) {
histogram.fill(0);
const int c=col+limit;
for(i=row-limit;i<=r;++i)
for(j=col-limit;j<=c;++j) {
if(i<0 && j<0)
++histogram.at(src.at(0,0));
else if(i>=0 && j<0)
++histogram.at(src.at(i,0));
else if(i<0 && j>=0)
++histogram.at(src.at(0,j));
else //if(i>=0 && j>=0)
++histogram.at(src.at(i,j));
//.........这里部分代码省略.........