The principle and C ++ Implementation of the PM model for the spread of the opposite sex, and the pm for the opposite sex
This article introduces the PM model for the spread of the opposite sex, and provides the C ++ code implementation.
I. PM model principles
Where,
II. C ++ code implementation MATLAB code can be referred: http://www.csse.uwa.edu.au /~ Pk/research/maid/Spatial/anisodiff. mhttp: // response
Void CImageObj: Perona_Malik (int iter, double dt, double kappa, int option) {int I, j; int nx = m_width, ny = m_height; double ** I _t = NewDoubleMatrix (nx, ny); double ** I _tmp = NewDoubleMatrix (nx, ny); for (I = 0; I <ny; I ++) for (j = 0; j <nx; j ++) I _t [I] [j] = I _tmp [I] [j] = m_imgData [I] [j]; for (int t = 0; t <iter; t ++) {for (I = 0; I <ny; I ++) {for (j = 0; j <nx; j ++) {int iUp = I-1, iDown = I + 1; int jLeft = j-1, jRight = j + 1; // boundary processing if (0 = I) iUp = I; if (ny-1 = I) iDown = I; if (0 = j) jLeft = j; if (nx-1 = j) jRight = j; double deltaN = I _t [iUp] [j]-I _t [I] [j]; double deltaS = I _t [iDown] [j]-I _t [I] [j]; double deltaE = I _t [I] [jRight]-I _t [I] [j]; double deltaW = I _t [I] [jLeft]-I _t [I] [j]; double cN, cS, cE, cW; if (1 = option) {cN = exp (-(deltaN/kappa) * (deltaN/kappa); cS = exp (-(deltaS/kappa) * (deltaS/kappa )); cE = exp (-(deltaE/kappa) * (deltaE/kappa); cW = exp (-(deltaW/kappa) * (deltaW/kappa ));} else if (2 = option) {cN = 1.0/(1 + (deltaN/kappa) * (deltaN/kappa )); cS = 1.0/(1 + (deltaS/kappa) * (deltaS/kappa); cE = 1.0/(1 + (deltaE/kappa) * (deltaE/kappa )); cW = 1.0/(1 + (deltaW/kappa) * (deltaW/kappa ));} I _tmp [I] [j] + = dt * (cN * deltaN + cS * deltaS + cE * deltaE + cW * deltaW );}} // One Iteration for (I = 0; I <ny; I ++) for (j = 0; j <nx; j ++) {I _t [I] [j] = I _tmp [I] [j] ;}/// iteration end // assign a value to the image for (I = 0; I <ny; I ++) for (j = 0; j <nx; j ++) {double tmp = I _t [I] [j]; tmp = max (0, min (tmp, 255); m_imgData [I] [j] = (unsigned char) tmp;} DeleteDoubleMatrix (I _t, nx, ny); DeleteDoubleMatrix (I _tmp, nx, ny );}