




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、圖像理解與分析中灰度共生矩陣算法內(nèi)容如下:共有matrix.cpp、 d_matrix.h、 d_exept.h、 mat.txt 四個(gè)文件/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 相關(guān)性C = C endl;cout 局部均勻性M = M endl;cout 慣性I = I endl;/剩下內(nèi)容請(qǐng)看下一頁的圖像理解與分析中灰度共生矩陣算法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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 村民務(wù)工補(bǔ)貼管理辦法
- 因果復(fù)句的歷史演變與語言學(xué)分析
- 廢舊農(nóng)膜回收與處置制度困境與完善路徑探究
- 公共住房資產(chǎn)管理辦法
- 決策咨詢工作管理辦法
- 銀行金融產(chǎn)品的精準(zhǔn)營(yíng)銷策略
- 內(nèi)部孵化項(xiàng)目管理辦法
- 中水回用技術(shù)在建筑領(lǐng)域的應(yīng)用與實(shí)踐
- 工程停工方案參考模板
- 設(shè)計(jì)單位安全生產(chǎn)責(zé)任
- 知行合一-王陽明傳奇課件
- 鍋爐澆注料施工方案
- GB/T 17394.1-2014金屬材料里氏硬度試驗(yàn)第1部分:試驗(yàn)方法
- GB/T 1606-2008工業(yè)碳酸氫鈉
- 葛的栽培技術(shù)
- 《綠色建筑概論》整套教學(xué)課件
- 山東中醫(yī)藥大學(xué)2020-2021學(xué)年內(nèi)科護(hù)理學(xué)試題及答案2
- 2022年綿陽江油市社區(qū)工作者招聘考試模擬試題及答案解析
- 初中道德與法治學(xué)科教學(xué)經(jīng)驗(yàn)交流
- 工程測(cè)量、定位放線控制點(diǎn)復(fù)核記錄表
- 申辦出入境證件的函
評(píng)論
0/150
提交評(píng)論