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

📄 drawocclusion.c

📁 image processing including fourier,wavelet,segmentation etc.
💻 C
📖 第 1 页 / 共 2 页
字号:
	      a1 = c->x; b1 = c->y;	      DrawLinePoly(ImageWindow,a0,b0,a1,b1);	  	      a0 = a1; b0 = b1;	      if (!c->next) 		DrawLinePoly(ImageWindow,(p->first)->x,(p->first)->y,a0,b0);	    }	}  WFlushWindow(ImageWindow);}/*     A notify function must return a value ....      *//*       0 if there was no event caught               *//*     > 0 if there was an event caught (but Destroy) *//*      -1 if the event Destroy was caught (or 'Q')   */int readpoly_notify(ImageWindow)Wframe *ImageWindow;{  int ret;  int event,button_mask;    oldx1=x1; oldy1=y1;  event = WUserEvent(ImageWindow); /* User's event on ImageWindow */  if (event < 0) ret=1; else ret=event;  if (event != W_DESTROY)    {      WGetStateMouse(ImageWindow,&x1,&y1,&button_mask);      if ((first_point != 0) && ((x1 != oldx1) || (y1 != oldy1)))	{	  WSetTypePencil(W_XOR);	  WDrawLine(ImageWindow,x0,y0,oldx1,oldy1);	  WDrawLine(ImageWindow,x0,y0,x1,y1);	  WSetTypePencil(W_COPY);	  WFlushWindow(ImageWindow);	}    }  switch(event)    {    case W_MS_LEFT:      /* New point */      if (first_point == 0) first_point=1;            if ((pc->previous) && ((pc->previous)->x == x1) &&	  ((pc->previous)->y == y1))	mwerror(WARNING, 0, "Double point in (%d,%d) :  not created\n",x1,y1);      else	{	  pc->x = x1; pc->y = y1;	  x0=x1; y0=y1;	  npc = mw_new_point_curve();	  max_number_of_points_in_poly++;	  if (npc == NULL) mwerror(FATAL,0,"Not enough memory\n");	  pc->next = npc;	  npc->previous = pc;	  pc = npc;	  if (print_mode) printf("Created a point in (%d,%d)\n",x1,y1);	}      break;          case W_MS_MIDDLE:       /* Cancel */      npc = pc->previous;      if (npc != NULL)	{	  max_number_of_points_in_poly--;	  printf("Cancel point in (%d,%d)\n",npc->x,npc->y);	  WSetTypePencil(W_XOR); 	  WDrawLine(ImageWindow,x0,y0,oldx1,oldy1); 	  if (npc->previous)	    {	      x0 = (npc->previous)->x; y0 = (npc->previous)->y;	      x1 = npc->x; y1 = npc->y;	    }	  else first_point = 0;	  	  WSetTypePencil(W_COPY);	  WFlushWindow(ImageWindow);      	  free((void*)pc);	  pc = npc;	  pc->next = NULL;	  pc->x = pc->y = -1;	}      else mwerror(WARNING, 0, "Polygon completed: cannot delete\n");      break;    case W_MS_RIGHT:      /* Next polygon */      WSetTypePencil(W_XOR);       if (pc->x != -1)	{	  WDrawLine(ImageWindow,(pl->first)->x,(pl->first)->y,pc->x,pc->y);	  pc = mw_new_point_curve();	  if (pc == NULL) mwerror(FATAL,0,"Not enough memory\n");	}      else 	{	  if (!pc->previous) 	    {	      mwerror(WARNING, 0, "No polygon defined\n");	      break;	    }	  (pc->previous)->next = NULL;	  WDrawLine(ImageWindow,x0,y0,x1,y1);	  WDrawLine(ImageWindow,(pl->first)->x,(pl->first)->y,		    (pc->previous)->x,(pc->previous)->y);	}      WSetTypePencil(W_COPY);            WFlushWindow(ImageWindow);            npl = mw_change_polygon(NULL,NB_OF_CHANNELS);      if (npl == NULL)  mwerror(FATAL,0,"Not enough memory\n");            npl->channel[0] = 0.0;          /* Inside color is black 0.0 */      pl->next = npl;      npl->previous = pl;      pl = npl;      first_point = 0;      pl->first = pc;            pc->previous = NULL;      if (print_mode) printf("Next polygon\n");      Redraw(ImageWindow);      break;    case W_RESIZE:      Redraw(ImageWindow);      if (first_point != 0) 	{	  WSetTypePencil(W_XOR); 	  WDrawLine(ImageWindow,x0,y0,x1,y1);	}      break;    case W_DESTROY:      ret=-1;      break;    case W_KEYPRESS:      switch((char) WGetKeyboard())	{	case 'q': case 'Q': ret =-1;	  break;	case 'h': case 'H': Help();	  break;	case ' ': List_of_Poly();	  break;	case 'r': case 'R':  Redraw(ImageWindow);	  if (first_point != 0)	    {	      WSetTypePencil(W_XOR); 	      WDrawLine(ImageWindow,x0,y0,x1,y1);	    }	  break;	case 'p':case 'P':	  print_mode=1-print_mode;	  if (print_mode)  List_of_Poly();	  break;	}      break;    }  if (ret == -1)    {      if (pl->previous) (pl->previous)->next = NULL;      if (poly->first == pl) poly->first = NULL;      mw_delete_polygon(pl);      pl = NULL;      if (print_mode)	{	  List_of_Poly();	  printf("Soft Quit...\n");	}    }  return(ret);}/**************************************************************************/void drawocclusion(image,labelimage,hole_image,window,zoom,gray)Cimage image,*hole_image;Fimage labelimage;char *window;int *zoom;int *gray;{  Fimage interlabelimage;  Wframe *ImageWindow;  Polygon p;  Point_curve c;  int i,j,n,*Cx,*Cy;  Cimage image_zoom;  float fzoom;  register float *ptrlabel,*ptrinterlabel;  register unsigned char *ptrhole;  int interp=0;  int Number=0;  float foreground;  labelimage=mw_change_fimage(labelimage,image->nrow,image->ncol);  if (!labelimage) mwerror(FATAL,1,"Not enough memory !\n");  if (((interlabelimage=mw_new_fimage())==NULL) ||       (mw_alloc_fimage(interlabelimage,image->nrow+2,image->ncol+2)==NULL))    mwerror(FATAL,1,"Not enough memory !\n");  /* "interlabelimage" is 2 pixels higher and larger than "labelimage" in order     to deal properly with borders */  if (hole_image)    {      *hole_image=mw_change_cimage(*hole_image,image->nrow,image->ncol);      if (!*hole_image)  mwerror(FATAL,1,"Not enough memory !\n");      mw_copy_cimage(image,*hole_image);    }  if (zoom)    {      if ((*zoom<=0)||((double)(*zoom)/2!=(double)((*zoom)/2)))	mwerror(USAGE,1,"-z option parameter must be a stricly positive even integer !\n");      if ((image_zoom=mw_new_cimage())==NULL)	mwerror(FATAL,0,"Not enough memory\n");      fzoom=(float)*zoom;      czoom(image,image_zoom,(char*)NULL,(char*)NULL,&fzoom,&interp,(char *)NULL);    }  poly = mw_new_polygons();  if (poly == NULL) mwerror(FATAL,0,"Not enough memory\n");  pl = mw_change_polygon(NULL,NB_OF_CHANNELS);  if (pl == NULL) mwerror(FATAL,0,"Not enough memory\n");  pl->channel[0] = 0.0;          /* Inside color is black 0.0 */  poly->first = pl;  pc = mw_new_point_curve();  if (pc == NULL)  mwerror(FATAL,0,"Not enough memory\n");  pl->first = pc;  if (zoom)    ImageWindow = (Wframe *)      mw_get_window((Wframe *) window,image_zoom->ncol,image_zoom->nrow,100,100,		    image->name);  else  ImageWindow = (Wframe *)    mw_get_window((Wframe *) window,image->ncol,image->nrow,100,100,		  image->name);  if (ImageWindow == NULL)    mwerror(INTERNAL,1,"NULL window returned by mw_get_window\n");  if (zoom)    {      WLoadBitMapImage(ImageWindow,image_zoom->gray,image_zoom->ncol,image_zoom->nrow);       WRestoreImageWindow(ImageWindow,0,0,image_zoom->ncol,image_zoom->nrow);     }  else    {      WLoadBitMapImage(ImageWindow,image->gray,image->ncol,image->nrow);       WRestoreImageWindow(ImageWindow,0,0,image->ncol,image->nrow);     }  WFlushWindow(ImageWindow);  WSetUserEvent(ImageWindow,W_MS_BUTTON | W_KEYPRESS);   dx = image->ncol;  dy = image->nrow;  WSetColorPencil(ImageWindow,0);  printf("\nUse the mouse to draw the contours of your occlusions.\nType 'h' (while pointing in the image window) for more help\n");  mw_window_notify(ImageWindow,NULL,readpoly_notify);  mw_window_main_loop();  if (!(poly->first))    mwerror(FATAL,1,"No occlusion was defined. Aborted\n");  if (zoom)    {      Unzoom_Poly(*zoom);      if (print_mode) 	{	  printf("\t\tNew polygons coordinates after unzooming:\n");	  List_of_Poly();	}      mw_delete_cimage(image_zoom);      image_zoom=NULL;    }  mw_clear_fimage(interlabelimage,0.0);  /* Step 1 : draws lines between vertices within each polygon */  for (p=poly->first; p; p=p->next)    {      if (p->first->next)	{	  for (c=p->first; c->next; c=c->next)	    mw_draw_fimage(interlabelimage,c->x+1,c->y+1,c->next->x+1,c->next->y+1,1.0);	  mw_draw_fimage(interlabelimage,c->x+1,c->y+1,p->first->x+1,p->first->y+1,1.0);	}      else	/* In this case, the polygon reduces to a single point */	  mw_plot_fimage(interlabelimage,p->first->x+1,p->first->y+1,1.0);    }  /* Step 2 : occlusions are defined as those sets enclosed by the polygons */  foreground=0.0;  fconnected(interlabelimage->gray,interlabelimage->nrow,interlabelimage->ncol,	     foreground,&Number,(char*)NULL,(char*)NULL,(char*)1);   /* Remark that now only the background has value 1. The polygon borders have value 0      while the regions they enclose have value > 1. Thus it remains to compute the connected     components of the complement of the background. */    /* Step 3 : computation of connected components of occlusions */  foreground=1.0;  fconnected(interlabelimage->gray,interlabelimage->nrow,interlabelimage->ncol,	     foreground,&Number,(char*)NULL,(char*)1,(char*)NULL);   /* Step 4 : labelimage is written */  ptrinterlabel=interlabelimage->gray+interlabelimage->ncol+1;  for (i=0,ptrlabel=labelimage->gray;i<labelimage->nrow;i++,ptrinterlabel+=2)    for (j=0;j<labelimage->ncol;j++,ptrlabel++,ptrinterlabel++)      *ptrlabel=*ptrinterlabel;  mw_delete_fimage(interlabelimage);  interlabelimage=NULL;    /* Hole_image is now updated */  if (hole_image)    {      for (i=0,ptrlabel=labelimage->gray,ptrhole=(*hole_image)->gray;i<labelimage->nrow;i++)	for (j=0;j<labelimage->ncol;j++,ptrlabel++,ptrhole++)	  if (*ptrlabel) *ptrhole=(unsigned char)(*gray);    }  /* Removes polygons */  mw_delete_polygons(poly);  poly=NULL;}

⌨️ 快捷键说明

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