《图像理解与分析中灰度共生矩阵算法》由会员分享,可在线阅读,更多相关《图像理解与分析中灰度共生矩阵算法(7页珍藏版)》请在金锄头文库上搜索。
1、图像理解与分析中灰度共生矩阵算法内容如下: 共有 matrix.cpp、 d_matrix.h、 d_exept.h、 mat.txt 四个文件 /matrix.cpp /* Visual C+ 6.0 matrix designed by bfly */ #include #include #include #include #include #include “d_matrix.h“ template void outputmat(const matrix template int classifymat(const matrix template void transformmat(co
2、nst matrix template void probablitymat(const matrix template void typicalarguement(const matrix using namespace std; int main() /input matrixmatrix initMat;int numRows, numCols;int i, j;ifstream fin(“mat.txt“);if(!fin)cerr numRows numCols;initMat.resize(numRows, numCols);for(i = 0; i initMatij;/tran
3、sform matrix to tempMatint counter=classifymat(initMat);matrix tempMat;tempMat.resize(counter, counter);transformmat(initMat, tempMat);outputmat(tempMat);/transform matrix to probMatmatrix probMat;probMat.resize(counter, counter);probablitymat(tempMat, probMat);outputmat(probMat);cout void outputmat
4、(const matrixfor(i = 0; i int classifymat(const matrixmemoryval.push_back(mat00);int counter=1;bool flag = false;int i, j;for(i = 0; i void transformmat(const matrixint i, j, m, n;for(i = 0; i void probablitymat(const matrixint i, j;for(i = 0; i void typicalarguement(const matrixT M = T();int i, j;
5、/typicalargument efor(i = 0; i #include #include “d_except.h“ using namespace std; template class matrix public:matrix(int numRows = 1, int numCols = 1, const T/ constructor./ Postcondition: create array having numRows x numCols elements/ all of whose elements have value initValvector/ index operato
6、r./ Precondition: 0 / version for constant objectsint rows() const;/ return number of rowsint cols() const;/ return number of columnsvoid resize(int numRows, int numCols);/ modify the matrix size./ Postcondition: the matrix has size numRows x numCols./ any new elements are filled with the default va
7、lue of type Tprivate:int nRows, nCols;/ number of rows and columnsvector mat;/ matrix is implemented as nRows vectors (rows),/ each having nCols elements (columns) ; template matrix:matrix(int numRows, int numCols, const Treturn mati; / constant version. can be used with a constant object. / does no
8、t allow modification of a matrix element template const vectorreturn mati; template int matrix:rows() const return nRows; template int matrix:cols() const return nCols; template void matrix:resize(int numRows, int numCols) int i;/ handle case of no size change with a returnif (numRows = nRows / assi
9、gn the new matrix sizenRows = numRows;nCols = numCols;/ resize to nRows rowsmat.resize(nRows);/ resize each row to have nCols columnsfor (i=0; i #include using namespace std; class baseException public:baseException(const stringstring what() constreturn msgString;/ protected allows a derived class t
10、o access msgString./ chapter 13 discusses protected in detailprotected:string msgString; ; / failure to allocate memory (new() returns NULL) class memoryAllocationError: public baseException public:memoryAllocationError(const string / function argument out of proper range class rangeError: public ba
11、seException public:rangeError(const string / index out of range class indexRangeError: public baseException public:indexRangeError(const stringostrstream indexErr(indexString, 80);indexErr msg “ index “ i “ size = “ size ends;/ indexRangeError can modify msgString, since it is in/ the protected sect
12、ion of baseExceptionmsgString = indexString; ; / attempt to erase from an empty container class underflowError: public baseException public:underflowError(const string / attempt to insert into a full container class overflowError: public baseException public:overflowError(const string / error in exp
13、ression evaluation class expressionError: public baseException public:expressionError(const string / bad object reference class referenceError: public baseException public:referenceError(const string / feature not implemented class notImplementedError: public baseException public:notImplementedError
14、(const string / date errors class dateError: public baseException public:dateError(const stringostrstream dateErr(dateStr, 80);dateErr first v last ends;/ dateError can modify msgString, since it is in/ the protected section of baseExceptionmsgString = dateStr; ; / error in graph class class graphEr
15、ror: public baseException public:graphError(const string/ file open error class fileOpenError: public baseException public:fileOpenError(const stringostrstream fileErr(errorStr, 80);fileErr “Cannot open “ fname “ ends;/ fileOpenError can modify msgString, since it is in/ the protected section of baseExceptionmsgString = errorStr; ;/ error in graph class class fileError: public baseException public:fileError(const string #endif / EXCEPTION_CLASSES/mat.txt 7 7 0 1 2 3 0 1 2 1 2 3 0 1 2 3 2 3 0 1 2 3 0 3 0 1 2 3 0 1 0 1 2 3 0 1