⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 erosion.c

📁 image processing including fourier,wavelet,segmentation etc.
💻 C
字号:
/*--------------------------- Commande MegaWave -----------------------------*//* mwcommand  name = {erosion};  version = {"2.5"};  author = {"Lionel Moisan"};  function = {"erosion/dilation of a Cimage"};  usage = {  'i'->i          "if set, a dilation is applied instead of an erosion",  's':s->s        "if set, the shape s is taken as structuring element",  'r':[r=1.0]->r  "otherwise, a disc of radius r (default 1.0) is used",  'n':[n=1]->n    "number of iterations (default: 1)",  in->u           "input Cimage",  out<-v          "output Cimage"          };*/#include <stdio.h>#include "mw.h"#define ABS(x) ((x)>0?(x):(-(x)))#define EROSION 0#define DILATION 1extern Curve disc();/*------------- one erosion/dilation of a cimage by a shape s -------------*/void erodilat1(u,v,s,action)     Cimage u,v;     Curve  s;     short  action;{  register int x,y,nx,ny,xx,yy;  register unsigned char new,curr;  Point_curve p;    nx=u->ncol;   ny=u->nrow;  for (x=0;x<nx;x++)    for (y=0;y<ny;y++) {      new = u->gray[y*nx+x];      for (p=s->first;p;p=p->next) {	xx = x+p->x;	yy = y+p->y;	if (xx>=0 && xx<nx && yy>=0 && yy<ny) {	  curr = u->gray[yy*nx+xx];	  if (action==EROSION) 	    {  if (curr<new) new=curr; } /*** erosion  -> inf ***/	  else if (curr>new) new=curr;   /*** dilation -> sup ***/	  	}      }      v->gray[y*nx+x]=new;    }}/*---------------------- Main function : erosion --------------------*/Cimage erosion(u, v, r, s, n, i)     Cimage u,v;     float  *r;     Curve  s;     int    *n;     char   *i;{  Cimage w,*src,*dst,*new;  Curve  shape;  short  action;  int    niter;    /* check options and allocate memory */    if (*n<=0) mwerror(FATAL,1,"The -n option parameter must be positive.");  else niter=*n;    if (*r<=0) mwerror(FATAL,1,"Radius parameter must be positive.");  if (s) shape = s; else shape = disc(*r,NULL);     v = mw_change_cimage(v,u->nrow,u->ncol);  if (!v) mwerror(FATAL,1,"Not enough memory.");  if (niter>1) {    w = mw_change_cimage(NULL,u->nrow,u->ncol);    if (!w) mwerror(FATAL,1,"Not enough memory.");  } else w=NULL;    action = (i?DILATION:EROSION);    src=&u;   if (niter&1) {  /* if niter is odd */    dst=&v;    new=&w;  } else {        /* if niter is even */    dst=&w;    new=&v;  }  while (niter--) {    erodilat1(*src,*dst,shape,action);    src=dst; dst=new; new=src;  }    if (!s) mw_delete_curve(shape);  if (w) mw_delete_cimage(w);    return v;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -