版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 厨房主食配料下料单(日报表)
- 云计算架构设计要领与实践指导
- 青海职业生涯发展规划方案
- 企业消防安全工作指南
- 2024-2025学年广东深圳红岭中学八年级(上)期中数学试题含答案
- 护理评估教学感悟与反思
- 2026重庆市永川区五间镇人民政府招聘公益性岗位人员1人备考题库有完整答案详解
- 2026浙江绍兴市上虞区教育体育局招聘高水平体育教练员3人备考题库及1套完整答案详解
- 2026福建三明市清流县应急管理局招聘县森林消防大队劳务派遣人员1人备考题库有完整答案详解
- 2026浙江衢州市开化县就业管理中心招聘“残疾人之家”公益性岗位人员6人备考题库(第一批)及1套完整答案详解
- 房屋租赁合同txt
- 加工中心点检表
- 水库清淤工程可行性研究报告
- THBFIA 0004-2020 红枣制品标准
- GB/T 25630-2010透平压缩机性能试验规程
- GB/T 19610-2004卷烟通风的测定定义和测量原理
- 精排版《化工原理》讲稿(全)
- 中层管理干部领导力提升课件
- 市场营销学-第12章-服务市场营销课件
- 小微型客车租赁经营备案表
- 风生水起博主的投资周记
评论
0/150
提交评论