圖像理解與分析中灰度共生矩陣算法new_第1頁
圖像理解與分析中灰度共生矩陣算法new_第2頁
圖像理解與分析中灰度共生矩陣算法new_第3頁
圖像理解與分析中灰度共生矩陣算法new_第4頁
圖像理解與分析中灰度共生矩陣算法new_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費閱讀

付費下載

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論