1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
#include <stdio.h>
#include <stdlib.h>
#include "mex.h"
#define res[i1][j1] res[i1*col+j1]
#define Iba[i1][j1] Ibas[i1*col+j1]
#define Ihaut[i1][j1] Ihaut[i1*col+j1]
/*#######################************ Programme C hysteresis***********************####################*/
void hysteresis(double *Ibas,double *Ihaut,double *res,int row, int col)
{
int i1,j1,k,count,MAXITERATION;
count = 1; k=0; MAXITERATION = 200;
while ( ( count != 0 ) && k < MAXITERATION )
{
count = 0;
for(i1=1; i1=row-1;i1++)
{
for(j1=1; j1=col-1;j1++)
{
if(res[i1][j1]>0)
{
if(Ibas[i1-1][j1-1]>0)
{
res[i1-1][j1-1]=1; count=count + 1;
}
if(Ibas[i1-1][j1]>0)
{
res[i1-1][j1]=1; count=count + 1;
}
if(Ibas[i1-1][j1+1]>0)
{
res[i1-1][j1+1]=1; count=count + 1;
}
if(Ibas[i1][j1-1]>0)
{
res[i1][j1-1]=1; count=count + 1;
}
if(Ibas[i1][j1+1]>0)
{
res[i1][j1+1]=1; count=count + 1;
}
if(Ibas[i1+1][j1-1]>0)
{
res[i1+1][j1-1]=1; count=count + 1;
}
if(Ibas[i1+1][j1]>0)
{
res[i1+1][j1]=1; count=count + 1;
}
if(Ibas[i1+1][j1+1]>0)
{
res[i1+1][j1+1]=1; count=count + 1;
}
}
}
}
k = k + 1; }
return;
}
/* nrhs nombre de parametre d'entre
nlhs nombre de parametre de sortie
prhs tableau de pointeur d'un element en entre
plhs tableau de pointeur de sortie
*/
void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
{
double *IsBas,*IsHaut, *Ihyst; /* Ibas et Ihaut sont les tableau en entre et res tableau en sortie Matlab*/
int row,col;
/* Check for proper number of inputs */
if (nrhs < 2)
{ mexErrMsgTxt("Not enough input arguments."); }
else if (nrhs > 2)
{ mexErrMsgTxt("Too many input arguments."); }
/* Check for proper number of outputs */
if (nlhs < 1)
{ mexErrMsgTxt("Not enough output arguments."); }
else if (nlhs > 1)
{ mexErrMsgTxt("Too many output arguments."); }
/* Get inputs */
row = mxGetM(prhs[0]);
col = mxGetN(prhs[0]);
IsBas = mxGetPr(prhs[0]); /* retourne la matrice pointée par prhs[0]*/
IsHaut = mxGetPr(prhs[1]);
/* Create a matrix for the return argument. */
plhs[0] = mxCreateDoubleMatrix(row, col, mxREAL);
Ihyst = mxGetPr(plhs[0]);
/* main computation */
hysteresis(IsBas,IsHaut,Ihyst,row,col);
} |
Partager