




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、图像理解与分析中灰度共生矩阵算法内容如下:共有matrix.cpp、 d_matrix.h、 d_exept.h、 mat.txt 四个文件/matrix.cpp/*Visual C+ 6.0 matrixdesigned by bfly*/#include #include #include #include #include #include d_matrix.htemplate void outputmat(const matrix& mat);template int classifymat(const matrix& mat);template void transformmat(c
2、onst matrix& formermat, matrix& lattermat);template void probablitymat(const matrix& mat,matrix& probmat);template void typicalarguement(const matrix& mat,const matrix& probmat);using namespace std;int main()/input matrixmatrix initMat;int numRows, numCols;int i, j;ifstream fin(mat.txt);if(!fin)cerr
3、 Cannot open mat.txt numRows numCols;initMat.resize(numRows, numCols);for(i = 0; i numRows; i+)for(j = 0; j initMatij;/transform matrix to tempMatint counter=classifymat(initMat); matrix tempMat;tempMat.resize(counter, counter);transformmat(initMat, tempMat);outputmat(tempMat);/transform matrix to p
4、robMatmatrix probMat;probMat.resize(counter, counter);probablitymat(tempMat, probMat);outputmat(probMat);cout endl;/output the typicalarguementstypicalarguement(tempMat, probMat);return 0;/outputmat matrix functriontemplate void outputmat(const matrix& mat)int i, j;for(i = 0; i mat.rows(); i+)for(j
5、= 0; j mat.cols(); j+)cout matij ;out endl;/classifymat matrix functiontemplate int classifymat(const matrix& mat)vector memoryval;memoryval.push_back(mat00);int counter=1;bool flag = false;int i, j;for(i = 0; i mat.rows(); i+)for(j = 0; j mat.cols(); j+)for(int m = 0; m memoryval.size(); m+)if(mati
6、j = memoryvalm)flag = true;if(!flag)memoryval.push_back(matij); counter+;flag = false;return counter;/transformmat matrix functiontemplate void transformmat(const matrix& formermat, matrix& lattermat)cout a b;int i, j, m, n;for(i = 0; i lattermat.rows(); i+)for(j = 0; j lattermat.cols(); j+)for(m =
7、0; m formermat.rows(); m+) for(n = 0; n formermat.cols(); n+) if(formermatmn=i) if(m+a) formermat.rows() & (n+b) formermat.cols() if(formermatm+an+b = j) matval+; lattermatij=matval;matval=0;/probablitymat matrix functiontemplate void probablitymat(const matrix& mat,matrix& probmat)T sum = T();int i
8、, j;for(i = 0; i mat.rows(); i+)for(j = 0; j mat.cols(); j+)sum += matij;for(i = 0; i mat.rows(); i+)for(j = 0; j mat.cols(); j+)probmatij = matij/sum;cout endl;/typicalarguementstemplate void typicalarguement(const matrix& mat,const matrix& probmat)T e = T(), H = T(), C = T(),I = T(), mean = T(), s
9、tdvar = T(), sum = T(), var = T();T M = T();int i, j;/typicalargument efor(i = 0; i probmat.rows(); i+)for(j = 0; j probmat.cols(); j+)e += probmatij*probmatij;/typicalargument Hfor(i = 0; i probmat.rows(); i+)for(j = 0; j probmat.cols(); j+)H += probmatij*log(probmatij)/log(10.0);H = -H;/typicalarg
10、ument sumfor(i = 0; i mat.rows(); i+)for(j = 0; j mat.cols(); j+)sum += matij;/typicalargument mean mean = sum/(mat.rows()*mat.cols();/typicalargument varfor(i = 0; i mat.rows(); i+)for(j = 0; j mat.cols(); j+)var += (matij-mean)*(matij-mean);/typicalargument stdvarstdvar=sqrt(var);/typicalargument
11、Cfor(i = 0; i probmat.rows(); i+)for(j = 0; j probmat.cols(); j+)C += (i - mean)*(j - mean)*probmatij;C /= (stdvar*stdvar);/typicalargument Mfor(i = 0; i probmat.rows(); i+)for(j = 0; j probmat.cols(); j+)M += (probmatij/ (1 + (i - j)*(i - j);/typicalargument Ifor(i = 0; i probmat.rows(); i+)for(j =
12、 0; j probmat.cols(); j+)I += (i - j)*(i -j)*probmatij;/output typicalargumentscout 能量e = e endl;cout 熵H = H endl;cout 相关性C = C endl;cout 局部均匀性M = M endl;cout 惯性I = I endl;/剩下内容请看下一页的图像理解与分析中灰度共生矩阵算法2/d_matrix.h#ifndef MATRIX_CLASS#define MATRIX_CLASS#include #include #include d_except.husing namesp
13、ace std;template class matrixpublic:matrix(int numRows = 1, int numCols = 1, const T& initVal = T();/ constructor./ Postcondition: create array having numRows x numCols elements/ all of whose elements have value initValvector& operator (int i);/ index operator./ Precondition: 0 = i nRows. a violatio
14、n of this/ precondition throws the indexRangeError exception./ Postcondition: if the operator is used on the left-hand/ side of an assignment statement, an element of row i / is changedconst vector& operator(int i) const;/ version for constant objects int rows() const;/ return number of rows int col
15、s() const;/ return number of columns void 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 value of type Tprivate: int nRows, nCols;/ number of rows and columns vectorvector mat;/ matrix is
16、 implemented as nRows vectors (rows),/ each having nCols elements (columns);template matrix:matrix(int numRows, int numCols, const T& initVal):nRows(numRows), nCols(numCols),mat(numRows, vector(numCols,initVal)/ non-constant version. provides general access to matrix/ elementstemplate vector& matrix
17、:operator (int i)if (i = nRows)throw indexRangeError(matrix: invalid row index, i, nRows); return mati;/ constant version. can be used with a constant object./ does not allow modification of a matrix elementtemplate const vector& matrix:operator (int i) constif (i = nRows)throw indexRangeError(matri
18、x: invalid row index, i, nRows); return 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 return if (numRows = nRows & numCols = nCols) return;/ assign t
19、he new matrix sizenRows = numRows;nCols = numCols;/ resize to nRows rowsmat.resize(nRows);/ resize each row to have nCols columnsfor (i=0; i nRows; i+)mati.resize(nCols);#endif/ MATRIX_CLASS/d_exept.h#ifndef EXCEPTION_CLASSES#define EXCEPTION_CLASSES#include #include using namespace std;class baseEx
20、ceptionpublic:baseException(const string& str = ):msgString(str)if (msgString = )msgString = Unspecified exception;string what() constreturn msgString;/ protected allows a derived class to access msgString./ chapter 13 discusses protected in detailprotected:string msgString;/ failure to allocate mem
21、ory (new() returns NULL)class memoryAllocationError: public baseExceptionpublic:memoryAllocationError(const string& msg = ):baseException(msg);/ function argument out of proper rangeclass rangeError: public baseExceptionpublic:rangeError(const string& msg = ):baseException(msg);/ index out of rangec
22、lass indexRangeError: public baseExceptionpublic:indexRangeError(const string& msg, int i, int size):baseException()char indexString80;ostrstream indexErr(indexString, 80);indexErr msg index i size = size ends;/ indexRangeError can modify msgString, since it is in/ the protected section of baseExcep
23、tionmsgString = indexString;/ attempt to erase from an empty containerclass underflowError: public baseExceptionpublic:underflowError(const string& msg = ):baseException(msg);/ attempt to insert into a full containerclass overflowError: public baseExceptionpublic:overflowError(const string& msg = ):
24、baseException(msg);/ error in expression evaluationclass expressionError: public baseExceptionpublic:expressionError(const string& msg = ):baseException(msg);/ bad object referenceclass referenceError: public baseExceptionpublic:referenceError(const string& msg = ):baseException(msg);/ feature not implementedclass notImplementedError: public baseExceptionpublic:notImplementedError(const string& msg = ):baseException(msg);/ date errorsclass dateError: public baseExceptionpublic:dateError(const string& first, int v, const string& last):baseException()char dateStr80;ostrstr
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年老年人护理员考试试卷及答案
- 第38届全国中学生物理竞赛复赛答案
- 微商家入驻合同协议
- 咨询服务合同补充协议
- 商业摄影套餐合同协议
- 吸塑冲床出售合同协议
- 商业入驻意向合同协议
- 2025仓库租赁合同范本参考
- 2025标准供货合同()
- 2025城市房地产市场合同
- 起重吊装作业安全管理培训
- 2025年山东省应急管理普法知识竞赛参考试题库大全-下(多选、判断题)
- 6.5 国家司法机关 课件-2024-2025学年统编版道德与法治八年级下册
- 语文-华大新高考联盟2025届高三3月教学质量测评试题+答案
- 2025年湖北行测试题及答案
- 闽教版四年级英语下册全册单元知识点
- 新高考背景下2025年高考物理命题趋势分析与复习备考策略讲座
- 2025年四川成都农业科技职业学院招聘工作人员16人高频重点模拟试卷提升(共500题附带答案详解)
- 2024年全国高考甲卷历史试题含答案解析
- 八年级数学下册 第4章 单元综合测试卷(北师版 2025年春)
- 《绿色建筑概论》整套教学课件
评论
0/150
提交评论