コード例 #1
0
ファイル: WlzRegCCor.c プロジェクト: VirtualFlyBrain/Woolz
/*!
* \return	Affine transform which brings the two objects into register.
* \ingroup	WlzRegistration
* \brief	Registers the two given objects using a frequency domain
*               cross correlation.
*
*		Registers the two given objects using a frequency domain
*               cross correlation.  An affine transform is computed,
*               which when applied to the source object takes it into
*		register with the target object.
*		Because frequency domain cross correlation (which relies on
*		the FFT) is used the objects are padded out to arrays which
*		are an integer power of two in size. This padding introduces
*		significant influence of the objects boundaries and in many
*		cases the registration will be dominated by the boundaries.
*		To avoid the boundary problem, two methods are available -
*		using a window function and adding Gaussian noise.
*		The window functions apply a weight to objects values
*		which is high at the objects centre of mass and decays
*		towards the object boundary. Gaussian noise is added by
*		placing the object on an array filled with with random
*		values that have the same mean and varience as the object's
*		values.
*
*		The objects are assumed to have high foreground values and
*		low background values. If this is no the case the invert
*		grey values parameter should be set.
* \param	tObj			The target object.
* \param	sObj			The source object to be registered
*					with target object.
* \param	initTr			Initial affine transform to be
*					applied to the source object prior to
*					registration. May be NULL.
* \param	trType			Required transform type.
* \param	maxTran			Maximum translation.
* \param	maxRot			Maximum rotation.
* \param	maxItr			Maximum number of iterations, if
*					\f$\leq\f$ 0 then infinite iterations
*					are allowed. 
* \param	winFn			The window function to use.
* \param	noise			Use Gaussian noise if non-zero.
* \param	dstConv			Destination ptr for the convergence
* 					flag (non zero on convergence), may be
* 					NULL.
* \param	inv			Invert values of both objects if
*					non-zero.
* \param	dstCCor			Destination ptr for the cross
* 					correlation value, may be NULL.
* \param	dstErr			Destination error pointer,
*                                       may be NULL.
*/
WlzAffineTransform *WlzRegCCorObjs(WlzObject *tObj, WlzObject *sObj,
				   WlzAffineTransform *initTr,
				   WlzTransformType trType,
				   WlzDVertex2 maxTran, double maxRot,
				   int maxItr,
				   WlzWindowFnType winFn, int noise, int inv,
				   int *dstConv, double *dstCCor,
				   WlzErrorNum *dstErr)
{
  WlzIVertex2	dummy;
  WlzObject	*tPObj = NULL,
  		*sPObj = NULL;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  WlzAffineTransform *regTr = NULL;

  dummy.vtX = dummy.vtY = 0;
  if((tObj == NULL) || (sObj == NULL))
  {
    errNum = WLZ_ERR_OBJECT_NULL;
  }
  else if((tObj->domain.core == NULL) || (sObj->domain.core == NULL))
  {
    errNum = WLZ_ERR_DOMAIN_NULL;
  }
  else if((tObj->values.core == NULL) || (sObj->values.core == NULL))
  {
    errNum = WLZ_ERR_VALUES_NULL;
  }
  else if(tObj->type != sObj->type)
  {
    errNum = WLZ_ERR_OBJECT_TYPE;
  }
  else
  {
    switch(tObj->type)
    {
      case WLZ_2D_DOMAINOBJ:
	tPObj = WlzAssignObject(
	        WlzRegCCorNormaliseObj2D(tObj,  inv, &errNum), NULL);
	if(errNum == WLZ_ERR_NONE)
	{
	  sPObj = WlzAssignObject(
	          WlzRegCCorNormaliseObj2D(sObj,  inv, &errNum), NULL);
	}
	if(errNum == WLZ_ERR_NONE)
	{
	  regTr = WlzRegCCorObjs2D(tPObj, sPObj, initTr, trType,
				   maxTran, maxRot, maxItr, winFn, noise,
				   dstConv, dstCCor, &errNum);
	}
        break;
      default:
	errNum = WLZ_ERR_OBJECT_TYPE;
	break;
    }
    (void )WlzFreeObj(tPObj);
    (void )WlzFreeObj(sPObj);
  }
  if(dstErr)
  {
    *dstErr = errNum;
  }
  return(regTr);
}
コード例 #2
0
ファイル: WlzJavaArray1D.c プロジェクト: dscho/Woolz
/************************************************************************
* Function:     WlzJavaArray1DWrap				
* Returns:      jobject:                New Java object.               
* Purpose:      Wraps up the given array as a new Java array.	
* Global refs:  -                                                      
* Parameters:   JNIEnv *jEnv:           Given JNI environment ptr.     
*               char *cObjName:         The Java woolz object class    
*                                       string.                        
*               char *jObjName:         The Java woolz Java object     
*                                       class string.                  
*               char *jniObjName:       The Java woolz JNI object      
*                                       class string.                  
*               int idrCnt:             Indirection count (ie 1 for *, 
*                                       2 for **, ...).                
*               int pKey:               Parameter key.                 
*		void *aVal:		C array to set values from.
*		int aSz:		Size of the 1D array.	
************************************************************************/
jobject		WlzJavaArray1DWrap(JNIEnv *jEnv,
				   char *cObjName,
				   char *jObjName,
				   char *jniObjName,
				   int idrCnt, int pKey,
				   void *aVal,
				   int aSz)
{
  int		isWlzObject,
  		idN0;
  char		*jWFqClassName;
  jclass	jWCls;
  jmethodID	mtdID;
  jfieldID	fldID;
  jobject	tObj0,
  		rtnJObj = NULL;

#ifdef JWLZ_DEBUG
  int hack = 1;
  while(hack)
  {
    sleep(2);
  }
#endif /* JWLZ_DEBUG */
  if(aVal && (aSz > 0))
  {
    switch(pKey)
    {
      case WLZ_JPM_KEY_BYTE_ARY1:
	if((rtnJObj = (jobject )((*jEnv)->NewByteArray(jEnv, aSz))) != NULL)
	{
	  (*jEnv)->SetByteArrayRegion(jEnv, (jbyteArray )rtnJObj, 0, aSz,
				      aVal);
	}
	break;
      case WLZ_JPM_KEY_SHORT_ARY1:
	if((rtnJObj = (jobject )((*jEnv)->NewShortArray(jEnv, aSz))) != NULL)
	{
	  (*jEnv)->SetShortArrayRegion(jEnv, (jshortArray )rtnJObj, 0, aSz,
				       aVal);
	}
	break;
      case WLZ_JPM_KEY_INT_ARY1:
	if((rtnJObj = (jobject )((*jEnv)->NewIntArray(jEnv, aSz))) != NULL)
	{
	  (*jEnv)->SetIntArrayRegion(jEnv, (jintArray )rtnJObj, 0, aSz,
				     aVal);
	}
	break;
      case WLZ_JPM_KEY_LONG_ARY1:
	if((rtnJObj = (jobject )((*jEnv)->NewLongArray(jEnv, aSz))) != NULL)
	{
	  (*jEnv)->SetLongArrayRegion(jEnv, (jlongArray )rtnJObj, 0, aSz,
				      aVal);
	}
	break;
      case WLZ_JPM_KEY_FLOAT_ARY1:
	if((rtnJObj = (jobject )((*jEnv)->NewFloatArray(jEnv, aSz))) != NULL)
	{
	  (*jEnv)->SetFloatArrayRegion(jEnv, (jfloatArray )rtnJObj, 0, aSz,
				       aVal);
	}
	break;
      case WLZ_JPM_KEY_DOUBLE_ARY1:
	if((rtnJObj = (jobject )((*jEnv)->NewDoubleArray(jEnv, aSz))) != NULL)
	{
	  (*jEnv)->SetDoubleArrayRegion(jEnv, (jdoubleArray )rtnJObj, 0, aSz,
					aVal);
	}
	break;
      case WLZ_JPM_KEY_WLZ_IVERTEX2_ARY1:
	if((jWFqClassName = WlzJavaBuildFQClassName(jObjName)) != NULL)
	{
	  jWCls = (*jEnv)->FindClass(jEnv, jWFqClassName);
	  rtnJObj = (jobject )(*jEnv)->NewObjectArray(jEnv, aSz, jWCls, NULL);
	  AlcFree(jWFqClassName);
	}
	if(rtnJObj)
	{
	  mtdID = (*jEnv)->GetMethodID(jEnv, jWCls, "<init>", "(II)V");
	  for(idN0 = 0; idN0 < aSz; ++idN0)
	  {
	    tObj0 = (*jEnv)->NewObject(jEnv, jWCls, mtdID,
	    			       ((WlzIVertex2 *)aVal + idN0)->vtX,
				       ((WlzIVertex2 *)aVal + idN0)->vtY);
	    (*jEnv)->SetObjectArrayElement(jEnv, (jobjectArray )rtnJObj,
					   idN0, tObj0);
	  }
	}
        break;
      case WLZ_JPM_KEY_WLZ_FVERTEX2_ARY1:
	if((jWFqClassName = WlzJavaBuildFQClassName(jObjName)) != NULL)
	{
	  jWCls = (*jEnv)->FindClass(jEnv, jWFqClassName);
	  rtnJObj = (jobject )(*jEnv)->NewObjectArray(jEnv, aSz, jWCls, NULL);
	  AlcFree(jWFqClassName);
	}
	if(rtnJObj)
	{
	  mtdID = (*jEnv)->GetMethodID(jEnv, jWCls, "<init>", "(FF)V");
	  for(idN0 = 0; idN0 < aSz; ++idN0)
	  {
	    tObj0 = (*jEnv)->NewObject(jEnv, jWCls, mtdID,
	    			       ((WlzFVertex2 *)aVal + idN0)->vtX,
				       ((WlzFVertex2 *)aVal + idN0)->vtY);
	    (*jEnv)->SetObjectArrayElement(jEnv, (jobjectArray )rtnJObj,
					   idN0, tObj0);
	  }
	}
        break;
      case WLZ_JPM_KEY_WLZ_DVERTEX2_ARY1:
	if((jWFqClassName = WlzJavaBuildFQClassName(jObjName)) != NULL)
	{
	  jWCls = (*jEnv)->FindClass(jEnv, jWFqClassName);
	  rtnJObj = (jobject )(*jEnv)->NewObjectArray(jEnv, aSz, jWCls, NULL);
	  AlcFree(jWFqClassName);
	}
	if(rtnJObj)
	{
	  mtdID = (*jEnv)->GetMethodID(jEnv, jWCls, "<init>", "(DD)V");
	  for(idN0 = 0; idN0 < aSz; ++idN0)
	  {
	    tObj0 = (*jEnv)->NewObject(jEnv, jWCls, mtdID,
	    			       ((WlzDVertex2 *)aVal + idN0)->vtX,
				       ((WlzDVertex2 *)aVal + idN0)->vtY);
	    (*jEnv)->SetObjectArrayElement(jEnv, (jobjectArray )rtnJObj,
					   idN0, tObj0);
	  }
	}
        break;
      case WLZ_JPM_KEY_WLZ_IVERTEX3_ARY1:
	if((jWFqClassName = WlzJavaBuildFQClassName(jObjName)) != NULL)
	{
	  jWCls = (*jEnv)->FindClass(jEnv, jWFqClassName);
	  rtnJObj = (jobject )(*jEnv)->NewObjectArray(jEnv, aSz, jWCls, NULL);
	  AlcFree(jWFqClassName);
	}
	if(rtnJObj)
	{
	  mtdID = (*jEnv)->GetMethodID(jEnv, jWCls, "<init>", "(III)V");
	  for(idN0 = 0; idN0 < aSz; ++idN0)
	  {
	    tObj0 = (*jEnv)->NewObject(jEnv, jWCls, mtdID,
	    			       ((WlzIVertex3 *)aVal + idN0)->vtX,
				       ((WlzIVertex3 *)aVal + idN0)->vtY,
				       ((WlzIVertex3 *)aVal + idN0)->vtZ);
	    (*jEnv)->SetObjectArrayElement(jEnv, (jobjectArray )rtnJObj,
					   idN0, tObj0);
	  }
	}
        break;
      case WLZ_JPM_KEY_WLZ_FVERTEX3_ARY1:
	if((jWFqClassName = WlzJavaBuildFQClassName(jObjName)) != NULL)
	{
	  jWCls = (*jEnv)->FindClass(jEnv, jWFqClassName);
	  rtnJObj = (jobject )(*jEnv)->NewObjectArray(jEnv, aSz, jWCls, NULL);
	  AlcFree(jWFqClassName);
	}
	if(rtnJObj)
	{
	  mtdID = (*jEnv)->GetMethodID(jEnv, jWCls, "<init>", "(FFF)V");
	  for(idN0 = 0; idN0 < aSz; ++idN0)
	  {
	    tObj0 = (*jEnv)->NewObject(jEnv, jWCls, mtdID,
	    			       ((WlzFVertex3 *)aVal + idN0)->vtX,
				       ((WlzFVertex3 *)aVal + idN0)->vtY,
				       ((WlzFVertex3 *)aVal + idN0)->vtZ);
	    (*jEnv)->SetObjectArrayElement(jEnv, (jobjectArray )rtnJObj,
					   idN0, tObj0);
	  }
	}
        break;
      case WLZ_JPM_KEY_WLZ_DVERTEX3_ARY1:
	if((jWFqClassName = WlzJavaBuildFQClassName(jObjName)) != NULL)
	{
	  jWCls = (*jEnv)->FindClass(jEnv, jWFqClassName);
	  rtnJObj = (jobject )(*jEnv)->NewObjectArray(jEnv, aSz, jWCls, NULL);
	  AlcFree(jWFqClassName);
	}
	if(rtnJObj)
	{
	  mtdID = (*jEnv)->GetMethodID(jEnv, jWCls, "<init>", "(DDD)V");
	  for(idN0 = 0; idN0 < aSz; ++idN0)
	  {
	    tObj0 = (*jEnv)->NewObject(jEnv, jWCls, mtdID,
	    			       ((WlzDVertex3 *)aVal + idN0)->vtX,
				       ((WlzDVertex3 *)aVal + idN0)->vtY,
				       ((WlzDVertex3 *)aVal + idN0)->vtZ);
	    (*jEnv)->SetObjectArrayElement(jEnv, (jobjectArray )rtnJObj,
					   idN0, tObj0);
	  }
	}
        break;
      case WLZ_JPM_KEY_WLZ_PTR1_ARY1:
	if((jWFqClassName = WlzJavaBuildFQClassName(cObjName)) != NULL)
	{
	  jWCls = (*jEnv)->FindClass(jEnv, jWFqClassName);
	  mtdID = (*jEnv)->GetMethodID(jEnv, jWCls, "<init>", "()V");
	  fldID = (*jEnv)->GetFieldID(jEnv, jWCls, "value", "J");
	  rtnJObj = (jobject )(*jEnv)->NewObjectArray(jEnv, aSz, jWCls, NULL);
	  AlcFree(jWFqClassName);
	}
	if(rtnJObj)
	{
	  isWlzObject = strcmp(cObjName, "WlzObject") == 0;
	  for(idN0 = 0; idN0 < aSz; ++idN0)
	  {
	    tObj0 = (*jEnv)->NewObject(jEnv, jWCls, mtdID);
	    if(isWlzObject)
	    {
	      (void )WlzAssignObject(*((WlzObject **)aVal + idN0), NULL);
	    }
	    (*jEnv)->SetLongField(jEnv, tObj0, fldID,
				  (jlong )(*((WlzObject **)aVal + idN0)));
	    (*jEnv)->SetObjectArrayElement(jEnv, (jobjectArray )rtnJObj,
					   idN0, tObj0);
	  }
	}
	break;
      default:
	break;
    }
  }
  return(rtnJObj);
}
コード例 #3
0
ファイル: WlzSplitObj.c プロジェクト: dscho/Woolz
/*!
* \return	Woolz error code.
* \ingroup	WlzBinaryOps
* \brief	Splits the reference object into component objects cliped
*		from the reference object, with the bounding box of each
*		of the component objects determined using the pre-processed
*		object. The component objects are returned in size order.
* \param	refObj			Reference object.
* \param	ppObj			Pre-processed object which is
*					normalised to values in the range
*					0 - 255 as WlzUByte greys.
* \param	bWidth			Border width.
* \param	bgdFrac			Minimum fraction of values which are
* 					background values, with range
*					[0.0+ - 1.0-].
* \param	sigma			Histogram smoothing parameter used
*					by WlzHistogramCnvGauss().
* \param	compThrMethod		Method for computing threshold, used
*					in call to WlzCompThresholdVT().
* \param	nReqComp		Number of required components.
* \param	dstNComp		Destination pointer for the number of
*					components extracted, must not be NULL.
* \param	dstComp			Destination pointer for the extracted
*					components, must not be NULL.
*/
WlzErrorNum	WlzSplitObj(WlzObject *refObj, WlzObject *ppObj,
			      int bWidth, double bgdFrac, double sigma,
			      WlzCompThreshType compThrMethod,
			      int nReqComp, int *dstNComp,
			      WlzObject ***dstComp)
{
  int		dim,
  		idC;
  WlzObject	*hObj = NULL,
  		*tObj = NULL;
  WlzObject 	**comp = NULL;
  WlzBox	box;
  WlzPixelV	tV;
  WlzSplitObjData split;
  WlzThresholdType tType;
  WlzConnectType lCon;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const int	maxComp = 1024;

  split.nLComp = 0;
  split.compI = NULL;
  split.lCompSz = NULL;
  split.lComp = NULL;
  if((refObj == NULL) || (ppObj == NULL))
  {
    errNum = WLZ_ERR_OBJECT_NULL;
  }
  else if((refObj->domain.core == NULL) || (ppObj->domain.core == NULL))
  {
    errNum = WLZ_ERR_DOMAIN_NULL;
  }
  else if((refObj->values.core == NULL) || (ppObj->values.core == NULL))
  {
    errNum = WLZ_ERR_VALUES_NULL;
  }
  else if(refObj->type != ppObj->type)
  {
    errNum = WLZ_ERR_OBJECT_TYPE;
  }
  else if((dstNComp == NULL) || (dstComp == NULL))
  {
    errNum = WLZ_ERR_PARAM_NULL;
  }
  else if((bgdFrac < DBL_EPSILON) || (bgdFrac > (1.0 - DBL_EPSILON)))
  {
    errNum = WLZ_ERR_PARAM_DATA;
  }
  else
  {
    switch(refObj->type)
    {
      case WLZ_2D_DOMAINOBJ:
	dim = 2;
        lCon = WLZ_8_CONNECTED;
	break;
      case WLZ_3D_DOMAINOBJ:
	dim = 3;
        lCon = WLZ_26_CONNECTED;
	break;
      default:
        errNum = WLZ_ERR_OBJECT_TYPE;
	break;
    }
  }
  /* Compute threshold value and type from histogram. */
  if(errNum == WLZ_ERR_NONE)
  {
    hObj = WlzAssignObject(
    	   WlzHistogramObj(ppObj, 256, 0.0, 1.0, &errNum), NULL);
  }
  if(errNum == WLZ_ERR_NONE)
  {
    errNum = WlzHistogramCnvGauss(hObj, sigma, 0);
  }
  if(errNum == WLZ_ERR_NONE)
  {
    errNum = WlzCompThresholdVT(hObj, compThrMethod, bgdFrac, 0.0,
    			        0.0, &tV, &tType);
  }
  (void )WlzFreeObj(hObj); hObj = NULL;
  /* Threshold object. */
  if(errNum == WLZ_ERR_NONE)
  {
    tObj = WlzAssignObject(
     	   WlzThreshold(ppObj, tV, tType, &errNum), NULL);
  }
  /* Label to get connected components. */
  if(errNum == WLZ_ERR_NONE)
  {
    errNum = WlzLabel(tObj, &(split.nLComp), &(split.lComp), maxComp, 0, lCon);
  }
  /* Sort connected components by size. */
  if(errNum == WLZ_ERR_NONE)
  {
    if(split.nLComp < nReqComp)
    {
      nReqComp = split.nLComp;
    }
    if(((split.compI = (int *)AlcMalloc(sizeof(int) *
                                        split.nLComp)) == NULL) ||
       ((split.lCompSz = (int *)AlcMalloc(sizeof(int) *
                                          split.nLComp)) == NULL))
    {
      errNum = WLZ_ERR_MEM_ALLOC;
    }
  }
  if(errNum == WLZ_ERR_NONE)
  {
    idC = 0; 
    while((errNum == WLZ_ERR_NONE) && (idC < split.nLComp))
    {
      split.compI[idC] = idC;
      split.lCompSz[idC] = (dim == 2)? WlzArea(split.lComp[idC], &errNum):
      				       WlzVolume(split.lComp[idC], &errNum);
      ++idC;
    }
  }
  if(errNum == WLZ_ERR_NONE)
  {
    /* Sort component indices by component size. */
    AlgQSort(split.compI, split.nLComp, sizeof(int), &split,
    	     WlzSplitObjSortSzFn);
    /* Allocate array for cliped component objects. */
    if((comp = (WlzObject **)AlcCalloc(sizeof(WlzObject *),
    				       split.nLComp)) == NULL)
    {
      errNum = WLZ_ERR_MEM_ALLOC;
    }
  }
  /* Compute bounding box and clip objects from the reference object. */
  if(errNum == WLZ_ERR_NONE)
  {
    idC = 0;
    while((errNum == WLZ_ERR_NONE) && (idC < nReqComp))
    {
      if(dim == 2)
      {
        box.i2 = WlzBoundingBox2I(split.lComp[split.compI[idC]], &errNum);
	if(errNum == WLZ_ERR_NONE)
	{
	  box.i2.xMin -= bWidth;
	  box.i2.yMin -= bWidth;
	  box.i2.xMax += bWidth;
	  box.i2.yMax += bWidth;
	  comp[idC] = WlzClipObjToBox2D(refObj, box.i2, &errNum);
	}
      }
      else /* dim == 3 */
      {
        box.i3 = WlzBoundingBox3I(split.lComp[split.compI[idC]], &errNum);
	if(errNum == WLZ_ERR_NONE)
	{
	  box.i3.xMin -= bWidth;
	  box.i3.yMin -= bWidth;
	  box.i3.zMin -= bWidth;
	  box.i3.xMax += bWidth;
	  box.i3.yMax += bWidth;
	  box.i3.zMax += bWidth;
	  comp[idC] = WlzClipObjToBox3D(refObj, box.i3, &errNum);
	}
      }
      ++idC;
    }
  }
  if(errNum == WLZ_ERR_NONE)
  {
    *dstNComp = nReqComp;
    *dstComp = comp;
  }
  /* Free temporary storage. */
  if(split.lComp)
  {
    for(idC = 0; idC < split.nLComp; ++idC)
    {
      (void )WlzFreeObj(split.lComp[idC]);
    }
    AlcFree(split.lComp);
  }
  AlcFree(split.compI);
  AlcFree(split.lCompSz);
  (void )WlzFreeObj(tObj);
  return(errNum);
}
コード例 #4
0
ファイル: WlzCMeshCurvToImage.c プロジェクト: ma-tech/Woolz
int             main(int argc, char **argv)
{
  int		option,
		meanCrv = 0,
  		ok = 1,
		usage = 0;
  double	scale = 1.0;
  WlzInterpolationType interp = WLZ_INTERPOLATION_LINEAR;
  WlzObject     *inObj = NULL,
  		*outObj = NULL;
  FILE		*fP = NULL;
  char		*inObjFileStr,
  		*outObjFileStr;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const char	*errMsg;
  static char	optList[] = "hmNLQo:s:",
  		fileStrDef[] = "-";

  opterr = 0;
  inObjFileStr = fileStrDef;
  outObjFileStr = fileStrDef;
  while((usage == 0) && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'N':
        interp = WLZ_INTERPOLATION_NEAREST;
	break;
      case 'L':
        interp = WLZ_INTERPOLATION_LINEAR;
	break;
      case 'Q':
        interp = WLZ_INTERPOLATION_ORDER_2;
	break;
      case 'm':
        meanCrv = 1;
	break;
      case 'o':
        outObjFileStr = optarg;
	break;
      case 's':
        if(sscanf(optarg, "%lg", &scale) != 1)
	{
	  usage = 1;
	}
	break;
      case 'h': /* FALLTHROUGH */
      default:
        usage = 1;
	break;
    }
  }
  if((usage == 0) && (optind < argc))
  {
    if((optind + 1) != argc)
    {
      usage = 1;
    }
    else
    {
      inObjFileStr = *(argv + optind);
    }
  }
  ok = (usage == 0);
  if(ok)
  {
    if((inObjFileStr == NULL) ||
	(*inObjFileStr == '\0') ||
	((fP = (strcmp(inObjFileStr, "-")?
	       fopen(inObjFileStr, "r"): stdin)) == NULL) ||
	((inObj = WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL) ||
	(errNum != WLZ_ERR_NONE))
    {
      ok = 0;
    }
    if(fP)
    {
      if(strcmp(inObjFileStr, "-"))
      {
	(void )fclose(fP);
      }
      fP = NULL;
    }
  }
  if(ok)
  {
    outObj = WlzCMeshCurvToImage(inObj, scale, meanCrv, interp, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
	     "%s: Failed to create contour from conforming mesh (%s).\n",
	     *argv, errMsg);

    }
  }
  if(ok)
  {
    errNum = WLZ_ERR_WRITE_EOF;
    if(((fP = (strcmp(outObjFileStr, "-")?
              fopen(outObjFileStr, "w"): stdout)) == NULL) ||
       ((errNum = WlzWriteObj(fP, outObj)) != WLZ_ERR_NONE))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
                     "%s: Failed to write output object (%s).\n",
		     *argv, errMsg);
    }
    if(fP && strcmp(outObjFileStr, "-"))
    {
      (void )fclose(fP);
    }
  }
  (void )WlzFreeObj(inObj);
  (void )WlzFreeObj(outObj);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%s%s%sExample: %s%s",
    *argv,
    " [-h] [-m] [-N] [-L] [-Q] [-o<output object>] [-s#]\n"
    "      [<input object>]\n"
    "Version: ",
    WlzVersion(),
    "\n"
    "Options:\n"
    "  -h  Help, prints usage message.\n"
    "  -N  Nearest neighbour interpolation from nearest element node value.\n"
    "  -L  Linear interpolation from element node values.\n"
    "  -Q  Interpolation from nodes surrounding element.\n"
    "  -m  Set image values to the mean rather than the Gaussian curvature.\n"
    "  -o  Output object file.\n"
    "  -s  Additional scale factor to be used in going from the mesh to the\n"
    "      spatial domain.\n"
    "Creates a 2D domain object with grey values (image) in which the values\n"
    "that are interpolated from the Gaussian curvature of the mesh. The 2D\n"
    "domain is created to cover the mesh following it's displacement. The\n"
    "displaced mesh must have been computed so that the displacements\n"
    "transform it to a plane (as by WlzCMeshSurfaceMap(1)).\n"
    "By default files are read from the standard input and written to the\n"
    "standard output.\n",
    *argv,
    " -o out.wlz in.wlz\n"
    "Reads a 2D5 conforming mesh from the file in.wlz, applies the meshes\n"
    "displacements to create a 2D domain object with the values set using\n"
    "the Gaussian curvature of the mesh prior to he application of it's\n"
    "displacements. The 2D domain object image is then writen to the file\n"
    "out.wlz.\n");
  }
  return(!ok);
}
コード例 #5
0
ファイル: WlzGreyMask.c プロジェクト: dscho/Woolz
/*! 
* \ingroup      WlzValuesUtils
* \brief        Set the value maskVal within the domain given by the	
*		mask object. The mask object can be a 2D, 3D, polygon	
*		or boundary object. A 3D mask with a 2D object is an	
*		error. A 2D mask with a 3D object will be applied to	
*		each plane in turn.			
*
* \return       New object with the same domain as the input object but
 with values in the intersection with the mask domain set to the mask
 value. NULL on error.
 * \param    obj	Input object
 * \param    mask	Mask object.
 * \param    maskVal	mask value.
 * \param    dstErr	Error return.
* \par      Source:
*                WlzGreyMask.c
*/
WlzObject *WlzGreyMask(
  WlzObject	*obj,
  WlzObject	*mask,
  WlzPixelV	maskVal,
  WlzErrorNum	*dstErr)
{
  WlzObject	*rtnObj=NULL;
  WlzObject	*tmpMask, *obj1;
  WlzValues	values;
  WlzPixelV	tmpMaskval;
  WlzIntervalWSpace	iwsp;
  WlzGreyWSpace		gwsp;
  WlzGreyP		gptr;
  int			i;
  WlzErrorNum	errNum=WLZ_ERR_NONE;

  /* check obj */
  if( obj == NULL ){
    errNum = WLZ_ERR_OBJECT_NULL;
  }
  else {
    switch( obj->type ){
    case WLZ_2D_DOMAINOBJ:
      if( obj->values.core == NULL ){
	errNum = WLZ_ERR_VALUES_NULL;
      }
      break;

    case WLZ_3D_DOMAINOBJ:
      return WlzGreyMask3d(obj, mask, maskVal, dstErr);

    case WLZ_TRANS_OBJ:
      if((values.obj = WlzGreyMask(obj->values.obj, mask, maskVal,
      				   &errNum)) != NULL){
	return WlzMakeMain(WLZ_TRANS_OBJ, obj->domain, values,
			   NULL, NULL, dstErr);
      }
      break;

    case WLZ_EMPTY_OBJ:
      return WlzMakeEmpty(dstErr);

    default:
      errNum = WLZ_ERR_OBJECT_TYPE;
      break;
    }
  }

  /* check the mask */
  if( errNum == WLZ_ERR_NONE ){
    if( mask == NULL ){
      errNum = WLZ_ERR_OBJECT_NULL;
    }
    else {
      values.core = NULL;
      switch( mask->type ){
      case WLZ_2D_DOMAINOBJ:
	tmpMask = WlzMakeMain(WLZ_2D_DOMAINOBJ, mask->domain, values,
			      NULL, NULL, &errNum);
	break;

      case WLZ_TRANS_OBJ:
	tmpMask = WlzMakeMain(WLZ_2D_DOMAINOBJ, mask->values.obj->domain,
			      values, NULL, NULL, &errNum);
	break;

      case WLZ_EMPTY_OBJ:
	return WlzMakeMain(WLZ_2D_DOMAINOBJ, obj->domain, obj->values,
			   NULL, NULL, dstErr);

      case WLZ_2D_POLYGON:
	tmpMask = WlzPolyToObj(mask->domain.poly, WLZ_SIMPLE_FILL, &errNum);
	break;

      case WLZ_BOUNDLIST:
	tmpMask = WlzBoundToObj(mask->domain.b, WLZ_SIMPLE_FILL, &errNum);
	break;

      default:
	errNum = WLZ_ERR_OBJECT_TYPE;
	break;
      }
      if( errNum == WLZ_ERR_NONE ){
	tmpMask = WlzAssignObject(tmpMask, NULL);
      }
    }
  }

  /* copy input obj and setvalues in the intersection */
  if(errNum == WLZ_ERR_NONE){
    if((rtnObj = WlzNewGrey(obj, &errNum)) != NULL){
      if((obj1 = WlzIntersect2(obj, tmpMask, &errNum)) != NULL){
	obj1->values = WlzAssignValues(rtnObj->values, NULL);
	errNum = WlzInitGreyScan(obj1, &iwsp, &gwsp);
	WlzValueConvertPixel(&tmpMaskval, maskVal, gwsp.pixeltype);
	while((errNum == WLZ_ERR_NONE) &&
	      ((errNum = WlzNextGreyInterval(&iwsp)) == WLZ_ERR_NONE)){
	  gptr = gwsp.u_grintptr;
	  switch( gwsp.pixeltype ){
	  case WLZ_GREY_INT:
	    for(i=0; i<iwsp.colrmn; i++, gptr.inp++){
	      *gptr.inp = tmpMaskval.v.inv;
	    }
	    break;
	  case WLZ_GREY_SHORT:
	    for(i=0; i<iwsp.colrmn; i++, gptr.shp++){
	      *gptr.shp = tmpMaskval.v.shv;
	    }
	    break;
	  case WLZ_GREY_UBYTE:
	    for(i=0; i<iwsp.colrmn; i++, gptr.ubp++){
	      *gptr.ubp = tmpMaskval.v.ubv;
	    }
	    break;
	  case WLZ_GREY_FLOAT:
	    for(i=0; i<iwsp.colrmn; i++, gptr.flp++){
	      *gptr.flp = tmpMaskval.v.flv;
	    }
	    break;
	  case WLZ_GREY_DOUBLE:
	    for(i=0; i<iwsp.colrmn; i++, gptr.dbp++){
	      *gptr.dbp = tmpMaskval.v.dbv;
	    }
	    break;
	  case WLZ_GREY_RGBA:
	    for(i=0; i<iwsp.colrmn; i++, gptr.rgbp++){
	      *gptr.rgbp = tmpMaskval.v.rgbv;
	    }
	    break;
	  default:
	    errNum = WLZ_ERR_GREY_TYPE;
	    break;
	  }
	}
	if( errNum == WLZ_ERR_EOO ){
	  errNum = WLZ_ERR_NONE;
	}
	WlzFreeObj(obj1);
      }
      else {
	WlzFreeObj(rtnObj);
	rtnObj = NULL;
      }
    }
    WlzFreeObj(tmpMask);
  }

  if( dstErr ){
    *dstErr = errNum;
  }
  return rtnObj;
}
コード例 #6
0
int             main(int argc, char **argv)
{
  int		option,
		ok = 1,
		usage = 0;
  LUTEntry	LUTEntries[256];
  int		LUTEntryCount;
  int		entryIdx, index;
  int		val = 0, indexGap, indexDist;
  WlzObject	*outObj = NULL;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  FILE		*fP = NULL;
  const char	*errMsg;
  char 		*outFileStr;
  char		*inFileStr;
  static char	optList[] = "ho:",
		outFileStrDef[] = "-",
  		inFileStrDef[] = "-";

  opterr = 0;
  outFileStr = outFileStrDef;
  inFileStr = inFileStrDef;
  /* Parse the command line. */
  while(ok && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
    case 'o':
      outFileStr = optarg;
      break;
    case 'h':
    default:
      usage = 1;
      break;
    }
  }
  if(usage == 0)
  {
    if((outFileStr == NULL) || (*outFileStr == '\0'))
    {
      usage = 1;
    }
    if(usage == 0)
    {
      if((argc - optind) > 0)
      {
	inFileStr = *(argv+optind);
      }
    }
  }
  ok = (usage == 0);
  /* Read  input LUT from infile or stdin. */
  if(ok)
  {
    if( *inFileStr == '-' ){
      fP = stdin;
    } else {
      if( (fP = fopen(inFileStr, "r")) == NULL ){
	 ok = 0;
	 (void) fprintf(stderr,
	                 "%s: failed to open input file %s\n",
			 *argv, inFileStr);
      }
    }
    if(ok){
      /* read the LUT index and values */
      for( LUTEntryCount=0; LUTEntryCount < 256; LUTEntryCount++){
	if( fscanf(fP, "%d,%d", &LUTEntries[LUTEntryCount].index, &LUTEntries[LUTEntryCount].value) < 2 ){
	  break;
	}
      }
      /* check for no data */
      if( LUTEntryCount == 0 ) {
	ok = 0;
	(void) fprintf(stderr,
		       "%s: No LUT entries found please check the input file\n",
		       *argv);
      } else {
	/* sort the LUTEntries */
	(void )AlgSort(LUTEntries, (size_t) LUTEntryCount, sizeof(LUTEntry),
		       ComparLUTEntry);

	/* check highest index add endpoint if needed */
	if( LUTEntries[LUTEntryCount-1].index < 255 ){
	  LUTEntries[LUTEntryCount].index = 255;
	  LUTEntries[LUTEntryCount].value = LUTEntries[LUTEntryCount - 1].value;
	  LUTEntryCount++;
	}
	
	/* check lowest index add startpoint if needed */
	if( LUTEntries[0].index > 0 ){
	  LUTEntries[LUTEntryCount].index = 0;
	  LUTEntries[LUTEntryCount].value = LUTEntries[0].value;
	  LUTEntryCount++;
	}

	/* re-sort the LUTEntries */
	(void )AlgSort(LUTEntries, (size_t) LUTEntryCount, sizeof(LUTEntry),
		       ComparLUTEntry);

      }
    }
  }

  /* Create a LUT object for the range 0-255 */
  if(ok)
  {
    outObj = WlzAssignObject(
             WlzMakeLUTObject(WLZ_GREY_INT, 0, 255, &errNum), NULL);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: failed to create new LUT object (%s)\n",
		     *argv, errMsg);
    }
  }
  /* Calculate the new LUT from the LUTEntries */
  if(ok){
    entryIdx = 0;
    for(index=0; index < 256; index++){
      if( index == LUTEntries[entryIdx].index ){
	val = LUTEntries[entryIdx].value;
	entryIdx++;
      }
      else if( index < LUTEntries[entryIdx].index ){
	indexGap = LUTEntries[entryIdx].index - LUTEntries[entryIdx-1].index;
	indexDist = index - LUTEntries[entryIdx-1].index;
	if( indexGap == 0 ){
	  /* shouldn't get here - something weird */
	  val =  LUTEntries[entryIdx].value;
	} else {
	  val = ((indexGap - indexDist) * LUTEntries[entryIdx-1].value + \
		 indexDist * LUTEntries[entryIdx].value) / indexGap;
	}
      }
      *((outObj->values.lut->val.inp) + index) = val;
    }
  }

  /* write object as required */
  if(ok)
  {
    if(((fP = (strcmp(outFileStr, "-")?
	      fopen(outFileStr, "w"): stdout)) == NULL) ||
	(WlzWriteObj(fP, outObj) != WLZ_ERR_NONE))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: failed to write LUT object to file %s (%s).\n",
		     *argv, outFileStr, errMsg);
    }
    if(fP && strcmp(outFileStr, "-"))
    {
      fclose(fP);
      fP = NULL;
    }
  }
  WlzFreeObj(outObj);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%s",
    *argv,
    " [-o<output object>] [-h]\n" 
    "Options:\n"
    "  -h  Help, prints this usage message.\n"
    "  -o  Output object.\n"
    "Reads the LUT values from a text file or from standard input. Assumes\n"
    "value-pairs (index, value) and in this version a LUT will be created\n"
    "with 0 <= index <= 255. If the \"-f\" flag is used then values wil be\n"
    "interpolated from 0-255 using the values that are set. Values below\n"
    "the minimum index value and above the maximum index value are set to\n"
    "the min and max values respectively.\n");
  }
  return(!ok);
}
コード例 #7
0
ファイル: WlzXORObj.c プロジェクト: ma-tech/Woolz
int             main(int argc, char **argv)
{
  int		option,
		ok = 1,
		usage = 0;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  FILE		*fP = NULL;
  WlzObject	*oObj = NULL;
  WlzObject	*iObj[2];
  char 		*oObjFileStr;
  char  	*iObjFileStr[2];
  const char	*errMsg;
  static char	optList[] = "o:h",
		fileStrDef[] = "-";

  opterr = 0;
  iObj[0] = NULL;
  iObj[1] = NULL;
  oObjFileStr = fileStrDef;
  iObjFileStr[0] = fileStrDef;
  iObjFileStr[1] = fileStrDef;
  while((usage == 0) && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'o':
	oObjFileStr = optarg;
	break;
      case 'h':
      default:
	usage = 1;
	break;
    }
  }
  if((iObjFileStr[0] == NULL) || (*iObjFileStr[0] == '\0') ||
     (iObjFileStr[1] == NULL) || (*iObjFileStr[1] == '\0') ||
     (oObjFileStr == NULL) || (*oObjFileStr == '\0'))
  {
    usage = 1;
  }
  if((usage == 0) && (optind < argc))
  {
    int 	i;

    i = 0;
    while((i < 2) && (optind < argc))
    {
      iObjFileStr[i] = *(argv + optind);
      ++optind;
      ++i;
    }
  }
  if((usage == 0) && (optind != argc))
  {
    usage = 1;
  }
  ok = !usage;
  if(ok)
  {
    int		i;

    i = 0;
    while((errNum == WLZ_ERR_NONE) && (i < 2))
    {
      errNum = WLZ_ERR_READ_EOF;
      if((iObjFileStr[i] == NULL) ||
	  (*iObjFileStr[i] == '\0') ||
	  ((fP = (strcmp(iObjFileStr[i], "-")?
		  fopen(iObjFileStr[i], "r"): stdin)) == NULL) ||
	  ((iObj[i]= WlzAssignObject(WlzReadObj(fP,
	  					   &errNum), NULL)) == NULL))
      {
	ok = 0;
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: Failed to read object %d from file %s (%s).\n",
		       *argv, i, iObjFileStr[i], errMsg);
      }
      if(fP && strcmp(iObjFileStr[i], "-"))
      {
	fclose(fP);
      }
      ++i;
    }
  }
  if(ok)
  {
    oObj = WlzXORDom(iObj[0], iObj[1], &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: Failed to compute set xor object (%s).\n",
		     *argv, errMsg);
    }
  }
  if(ok)
  {
    errNum = WLZ_ERR_WRITE_EOF;
    if(((fP = (strcmp(oObjFileStr, "-")? fopen(oObjFileStr, "w"):
	      				 stdout)) == NULL) ||
       ((errNum = WlzWriteObj(fP, oObj)) != WLZ_ERR_NONE))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: Failed to write output object (%s).\n",
		     *argv, errMsg);
    }
    if(fP && strcmp(oObjFileStr, "-"))
    {
      fclose(fP);
    }
  }
  WlzFreeObj(iObj[0]);
  WlzFreeObj(iObj[1]);
  WlzFreeObj(oObj);
  if(usage)
  {

    (void )fprintf(stderr,
	"Usage: %s"
	" [-o <out file>] [-h] [<in file 0>] [<in file 1>]\n"
	"Version: %s\n"
	"Options:\n"
	"  -o        Output file name.\n"
	"  -h        Help, prints this usage message.\n"
	"Computes the set exclusive or of the two given objects.\n"
	"The input objects are read from stdin and values are written\n"
	"to stdout unless the filenames are given.\n"
	"Example:\n%s -o out.wlz in0.wlz in1.wlz\n"
	"The exclusive of the the domains objects read from in0.wlz\n"
	"and in1.wlz is computed and written to out.wlz\n",
	*argv,
	WlzVersion(),
	*argv);
  }
  return(!ok);
}
コード例 #8
0
ファイル: WlzRegisterICPWSD.c プロジェクト: dscho/Woolz
int             main(int argc, char **argv)
{
  int		idN,
		option,
		useRadians = 0,
		ok = 1,
		usage = 0;
  double	minDistWgt = 0.25,
  		rMin = 0.0,
  		rMax = 20.0,
		rStep = 1.0,
		xMin = 0.0,
		xMax = 20.0,
		xStep = 1.0,
		yMin = 0.0,
		yMax = 20.0,
		yStep = 1.0;
  char		*comma,
  		*colon;
  double	*range[3];
  char		*buf[3];
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  WlzObject	*inTrObj = NULL,
  		*outObj = NULL;
  WlzObject	*inObj[2];
  FILE		*fP = NULL;
  char 		*inTrObjFileStr = NULL,
  		*outObjFileStr;
  char  	*inObjFileStr[2];
  const char	*errMsg;
  static char	optList[] = "M:i:o:r:x:y:Rh",
		outObjFileStrDef[] = "-",
  		inObjFileStrDef[] = "-";

  opterr = 0;
  inObj[0] = NULL;
  inObj[1] = NULL;
  outObjFileStr = outObjFileStrDef;
  inObjFileStr[0] = inObjFileStrDef;
  inObjFileStr[1] = inObjFileStrDef;
  while(ok && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'R':
        useRadians = 1;
	break;
      case 'M':
        if((sscanf(optarg, "%lg", &minDistWgt) != 1) ||
	   (minDistWgt < 0.0) || (minDistWgt > 1.0))
	{
	  usage = 1;
	  ok = 0;
	}
	break;
      case 'i':
        inTrObjFileStr = optarg;
	break;
      case 'o':
        outObjFileStr = optarg;
	break;
      case 'r': /* FALLTHROUGH */
      case 'x': /* FALLTHROUGH */
      case 'y':
	if(optarg)
	{
	  comma = strchr(optarg, ',');
	  colon = strchr(optarg, ':');
	  if(comma && colon)
	  {
	    *comma = *colon = '\0';
	    switch(option)
	    {
	      case 'r':
		range[0] = &rMin; 
		range[1] = &rMax; 
		range[2] = &rStep; 
		break;
	      case 'x':
		range[0] = &xMin; 
		range[1] = &xMax; 
		range[2] = &xStep; 
		break;
	      case 'y':
		range[0] = &yMin; 
		range[1] = &yMax; 
		range[2] = &yStep; 
		break;
	    }
	    buf[0] = optarg;
	    buf[1] = comma + 1;
	    buf[2] = colon + 1;
	    for(idN = 0; (idN < 3) && (usage == 0); ++idN)
	    {
	      while(*buf[idN] && isspace(*buf[idN]))
	      {
	        ++buf[idN];
	      }
	      if(*buf[idN])
	      {
	        if(sscanf(buf[idN], "%lg", range[idN]) != 1)
		{
		  usage = 1;
		}
	      }
	    }
	  }
	  else
	  {
	    usage = 1;
	  }
	}
        break;
      case 'h':
      default:
        usage = 1;
	break;
    }
  }
  if(useRadians == 0)
  {
    rMin *= ALG_M_PI / 180.0;
    rMax *= ALG_M_PI / 180.0;
    rStep *= ALG_M_PI / 180.0;
  }
  if((inObjFileStr[0] == NULL) || (*inObjFileStr[0] == '\0') ||
     (inObjFileStr[1] == NULL) || (*inObjFileStr[1] == '\0') ||
     (outObjFileStr == NULL) || (*outObjFileStr == '\0'))
  {
    usage = 1;
  }
  ok = !usage;
  if(ok && (optind < argc))
  {
    idN = 0;
    while((idN < 2) && (optind < argc))
    {
      inObjFileStr[idN] = *(argv + optind);
      ++optind;
      ++idN;
    }
  }
  if(ok && (optind != argc))
  {
    usage = 1;
    ok = 0;
  }
  if(ok && inTrObjFileStr)
  {
    /* Read initial affine transform. */
    if(((fP = (strcmp(inTrObjFileStr, "-")?
               fopen(inTrObjFileStr, "r"): stdin)) == NULL) ||
       ((inTrObj = WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
	     "%s: Failed to read initial affine transform from file %s (%s)\n",
	     *argv, inTrObjFileStr, errMsg);
    }
    if(fP && strcmp(inTrObjFileStr, "-"))
    {
      fclose(fP);
    }
    if(inTrObj &&
       ((inTrObj->type != WLZ_AFFINE_TRANS) || (inTrObj->domain.core == NULL)))
    {
      ok = 0;
      (void )fprintf(stderr,
      		     "%s: Initial affine transform object invalid type\n",
		     *argv);
    }
  }
  if(ok)
  {
    /* Read objects. */
    idN = 0;
    while((errNum == WLZ_ERR_NONE) && (idN < 2))
    {
      errNum = WLZ_ERR_READ_EOF;
      if((inObjFileStr[idN] == NULL) ||
	  (*inObjFileStr[idN] == '\0') ||
	  ((fP = (strcmp(inObjFileStr[idN], "-")?
		  fopen(inObjFileStr[idN], "r"): stdin)) == NULL) ||
	  ((inObj[idN] = WlzAssignObject(WlzReadObj(fP,
	  					    &errNum), NULL)) == NULL))
      {
	ok = 0;
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: Failed to read object %d from file %s (%s)\n",
		       *argv, idN, inObjFileStr[idN], errMsg);
      }
      if(fP && strcmp(inObjFileStr[idN], "-"))
      {
	fclose(fP);
      }
      ++idN;
    }
  }
  if(ok)
  {
    /* Check object types. */
    if(inObj[0]->type != inObj[1]->type)
    {
      errNum = WLZ_ERR_OBJECT_TYPE;
    }
    else if((inObj[0]->domain.core == NULL) ||
            (inObj[1]->domain.core == NULL))
    {
      errNum = WLZ_ERR_DOMAIN_NULL;
    }
    else
    {
      switch(inObj[0]->type)
      {
        case WLZ_2D_DOMAINOBJ:
          break;
        case WLZ_CONTOUR:
          if((inObj[0]->domain.core == NULL) ||
             (inObj[0]->domain.ctr->model == NULL))
          {
            errNum = WLZ_ERR_DOMAIN_NULL;
          }
          else
          {
            switch(inObj[0]->domain.ctr->model->type)
            {
              case WLZ_GMMOD_2I: /* FALLTHROUGH */
              case WLZ_GMMOD_2D:
              case WLZ_GMMOD_2N:
                break;
              default:
                errNum = WLZ_ERR_DOMAIN_TYPE;
                ok = 0;
                break;
            }
          }
          break;
        default:
          errNum = WLZ_ERR_OBJECT_TYPE;
          ok = 0;
          break;
      }
    }
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr, "%s: Input object(s) not appropriate (%s).\n",
		     *argv, errMsg);
    }
  }
  if(ok)
  {
    outObj = WlzRegICPObjWSD2D(inObj[0], inObj[1],
    			       inTrObj? inTrObj->domain.t: NULL,
			       xMin, xMax, xStep,
			       yMin, yMax, yStep,
			       rMin, rMax, rStep,
			       minDistWgt, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		   "%s: Failed to compute weighted sums of distances (%s).\n",
		   *argv, errMsg);
    }
  }
  if(ok)
  {
    errNum = WLZ_ERR_WRITE_EOF;
    if(((fP = (strcmp(outObjFileStr, "-")?  fopen(outObjFileStr, "w"):
	      				    stdout)) == NULL) ||
       ((errNum = WlzWriteObj(fP, outObj)) != WLZ_ERR_NONE))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: Failed to write output object (%s).\n",
		     *argv, errMsg);
    }
    if(fP && strcmp(outObjFileStr, "-"))
    {
      fclose(fP);
    }
  }
  if(inObj[0])
  {
    (void )WlzFreeObj(inObj[0]);
  }
  if(inObj[1])
  {
    (void )WlzFreeObj(inObj[1]);
  }
  if(outObj)
  {
    (void )WlzFreeObj(outObj);
  }
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%sExample: %s%s",
    *argv,
    " [-M #] [-R] [-i <init tr>] [-o<out obj>]\n"
    "                      [-r #,#:#] [-x #,#:#] [-y #,#:#]\n"
    "                      [<in obj 0>] [<in obj 1>]\n"
    "Options:\n"
    "  -M  Minimum distance weight, range [0.0-1.0]: Useful values are\n"
    "      0.25 (default) for global matching and 0.0 for local matching.\n"
    "  -R  Rotations are in radians not degrees.\n"
    "  -i  Initial affine transform object.\n"
    "  -o  Output file name.\n"
    "  -r  Range and step size for rotation in degrees.\n"
    "  -x  Range and step size for translation through columns.\n"
    "  -y  Range and step size for translation through lines.\n"
    "  -h  Help, prints this usage message.\n"
    "Computes a 3D double precission valued object in which the values\n"
    "are the weighted sums of distances as used for ICP registration.\n"
    "In specifying the ranges the defaults are 0.0 -> 20.0, step 1.0.\n"
    "The input objects are read from stdin and values are written to stdout\n"
    "unless the filenames are given.\n",
    *argv,
    " -o out.wlz -r 0,90:0.5 -x 100,200: -y ,200: in0.wlz in1.wlz\n"
    "A weighted sums of distances object is computed for rotations of\n"
    "0 to 90 degrees with a step size of 0.5 degrees, the x and y\n"
    "translations are from 100 to 200 and 0 to 200 in unit steps.\n"
    "The weighted sums of distances object is then written to out.wlz.\n");
  }
  return(!ok);
}
コード例 #9
0
ファイル: WlzScalarFnObj.c プロジェクト: dscho/Woolz
int             main(int argc, char **argv)
{
  int		option,
		ok = 1,
		usage = 0;
  WlzObject	*inObj = NULL,
		*outObj = NULL;
  FILE		*fP = NULL;
  WlzFnType	fn = WLZ_FN_SCALAR_MOD;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  char 		*inObjFileStr,
  		*outObjFileStr;
  const char    *errMsg;
  static char	optList[] = "ehlmsSo:",
  		inObjFileStrDef[] = "-",
		outObjFileStrDef[] = "-";

  opterr = 0;
  outObjFileStr = outObjFileStrDef;
  inObjFileStr = inObjFileStrDef;
  while(ok && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'o':
        outObjFileStr = optarg;
	break;
      case 'e':
        fn = WLZ_FN_SCALAR_EXP;
	break;
      case 'm':
        fn = WLZ_FN_SCALAR_MOD;
	break;
      case 'l':
	fn = WLZ_FN_SCALAR_LOG;
	break;
      case 's':
	fn = WLZ_FN_SCALAR_SQRT;
	break;
      case 'S':
	fn = WLZ_FN_SCALAR_INVSQRT;
	break;
      case 'h':
      default:
        usage = 1;
	ok = 0;
	break;
    }
  }
  if((inObjFileStr == NULL) || (*inObjFileStr == '\0') ||
     (outObjFileStr == NULL) || (*outObjFileStr == '\0'))
  {
    ok = 0;
    usage = 1;
  }
  if(ok && (optind < argc))
  {
    if((optind + 1) != argc)
    {
      usage = 1;
      ok = 0;
    }
    else
    {
      inObjFileStr = *(argv + optind);
    }
  }
  if(ok)
  {
    errNum = WLZ_ERR_READ_EOF;
    if((inObjFileStr == NULL) ||
	(*inObjFileStr == '\0') ||
	((fP = (strcmp(inObjFileStr, "-")?
		fopen(inObjFileStr, "r"): stdin)) == NULL) ||
	((inObj= WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL) ||
	(errNum != WLZ_ERR_NONE))
    {
      ok = 0;
      (void )fprintf(stderr,
		     "%s: failed to read object from file %s\n",
		     *argv, inObjFileStr);
    }
    if(fP)
    {
      if(strcmp(inObjFileStr, "-"))
      {
	fclose(fP);
      }
      fP = NULL;
    }
  }
  if(ok)
  {
    outObj = WlzScalarFn(inObj, fn, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: failed to apply scalar function to object (%s).\n",
		     *argv, errMsg);
    }
  }
  if(ok)
  {
    if(errNum == WLZ_ERR_NONE)
    {
      errNum = WLZ_ERR_WRITE_EOF;
      if(((fP = (strcmp(outObjFileStr, "-")?
		fopen(outObjFileStr, "w"):
		stdout)) == NULL) ||
	 ((errNum = WlzWriteObj(fP, outObj)) != WLZ_ERR_NONE))
      {
	ok = 0;
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: failed to write output object (%s).\n",
		       *argv, errMsg);
      }
      if(fP && strcmp(outObjFileStr, "-"))
      {
	fclose(fP);
      }
    }
  }
  (void )WlzFreeObj(inObj);
  (void )WlzFreeObj(outObj);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%s",
    *argv,
    " [-o<out object>] [-h>]\n"
    "                  [-e] [-m] [-l]\n"
    "                  [<in object>]\n"
    "Options:\n"
    "  -e  Exponential function (g_out = exp(g_in)).\n"
    "  -m  Mudulus function (g_out = |g_in|).\n"
    "  -l  Log function (g_out = log(g_in)).\n"
    "  -s  Square root function (g_out = sqrt(g_in)).\n"
    "  -S  Inverse square root function (g_out = 1.0 / sqrt(g_in)).\n"
    "  -o  Output object file name.\n"
    "  -h  Help, prints this usage message.\n"
    "Applies a scalar function to the values of a Woolz object.\n");
  }
  return(!ok);
}
コード例 #10
0
int             main(int argc, char **argv)
{
  int		option,
		cVal = 0,
		ok = 1,
		usage = 0;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const char    *errMsg;
  FILE		*fP = NULL;
  WlzObject	*inObj = NULL,
		*outObj = NULL;
  char 		*outObjFileStr,
  		*inObjFileStr;
  static char	optList[] = "o:c:h",
		outObjFileStrDef[] = "-",
  		inObjFileStrDef[] = "-";

  opterr = 0;
  outObjFileStr = outObjFileStrDef;
  inObjFileStr = inObjFileStrDef;
  while(ok && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'c':
	if(sscanf(optarg, "%d", &cVal) != 1)
	{
	  usage = 1;
	  ok = 0;
	}
        break;
      case 'o':
        outObjFileStr = optarg;
	break;
      case 'h':
      default:
        usage = 1;
	ok = 0;
	break;
    }
  }
  if((inObjFileStr == NULL) || (*inObjFileStr == '\0') ||
     (outObjFileStr == NULL) || (*outObjFileStr == '\0'))
  {
    ok = 0;
    usage = 1;
  }
  if(ok && (optind < argc))
  {
    if((optind + 1) != argc)
    {
      usage = 1;
      ok = 0;
    }
    else
    {
      inObjFileStr = *(argv + optind);
    }
  }
  if(ok)
  {
    errNum = WLZ_ERR_READ_EOF;
    if((inObjFileStr == NULL) ||
       (*inObjFileStr == '\0') ||
       ((fP = (strcmp(inObjFileStr, "-")?
	      fopen(inObjFileStr, "r"): stdin)) == NULL) ||
       ((inObj= WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: failed to read object from file %s (%s).\n",
		     *argv, inObjFileStr, errMsg);
    }
    if(fP && strcmp(inObjFileStr, "-"))
    {
      fclose(fP);
    }
  }
  if(ok)
  {
    if((outObj = WlzGreyCrossing(inObj, 0, cVal, &errNum)) == NULL)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
      		     "%s: failed to compute grey crossing object (%s).\n",
		     *argv, errMsg);
    }
  }
  if(ok)
  {
    errNum = WLZ_ERR_WRITE_EOF;
    if(((fP = (strcmp(outObjFileStr, "-")?
              fopen(outObjFileStr, "w"):
	      stdout)) == NULL) ||
       ((errNum = WlzWriteObj(fP, outObj)) != WLZ_ERR_NONE))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
      		     "%s: failed to write output object (%s).\n",
		     *argv, errMsg);
    }
    if(fP && strcmp(outObjFileStr, "-"))
    {
      fclose(fP);
    }
  }
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%s%s%s%d%sExample: %s%s",
    *argv,
    " [-o<out object>] [-c #] [-h] [<in object>]\n"
    "Version: ",
    WlzVersion(),
    "\n"
    "Options:\n"
    "  -o  Output object file name.\n"
    "  -c  grey crossing value, set to ",
    cVal,
    ".\n"
    "  -h  Help, prints this usage message.\n"
    "Computes a grey value crossing image from a 2D domain object with\n"
    "integral grey values.\n"
    "Objects are read from stdin and written to stdout unless the filenames\n"
    "are given.\n",
    *argv,
    " -o crossing.wlz myobj.wlz\n"
    "The input Woolz object is read from myobj.wlz, filtered and written\n"
    "to crossing.wlz.\n");
  }
  return(!ok);
}
コード例 #11
0
int		main(int argc, char *argv[])
{
  int		option,
  		ok = 1,
		usage = 0;
  WlzPixelV	a,
  		m;
  WlzGreyType	gType = WLZ_GREY_UBYTE;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  FILE		*fP = NULL;
  WlzObject	*inObj = NULL,
  		*outObj = NULL;
  char		*inFileStr,
		*outFileStr;
  const char	*errMsg;
  static char	optList[] = "a:g:hm:o:",
  		inFileStrDef[] = "-",
		outFileStrDef[] = "-";

  opterr = 0;
  a.type = WLZ_GREY_DOUBLE;
  a.v.dbv = 0.0;
  m.type = WLZ_GREY_DOUBLE;
  m.v.dbv = 1.0;
  inFileStr = inFileStrDef;
  outFileStr = outFileStrDef;
  while(ok && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'a':
	if(sscanf(optarg, "%lg", &(a.v.dbv)) != 1)
	{
	  usage = 1;
	}
	break;
      case 'g':
        switch(*optarg)
	{
	  case 'i':
	    gType = WLZ_GREY_INT;
	    break;
	  case 's':
	    gType = WLZ_GREY_SHORT;
	    break;
	  case 'u':
	    gType = WLZ_GREY_UBYTE;
	    break;
	  case 'f':
	    gType = WLZ_GREY_FLOAT;
	    break;
	  case 'd':
	    gType = WLZ_GREY_DOUBLE;
	    break;
	  case 'r':
	    gType = WLZ_GREY_RGBA;
	    break;
	  default:
	    usage = 1;
	    break;
	}
	break;
      case 'o':
        outFileStr = optarg;
	break;
      case 'm':
	if(sscanf(optarg, "%lg", &(m.v.dbv)) != 1)
	{
	  usage = 1;
	}
	break;
      case 'h': /* FALLTHROUGH */
      default:
	usage = 1;
	break;
    }
  }
  if((usage == 0) && (optind < argc))
  {
    if((optind + 1) != argc)
    {
      usage = 1;
    }
    else
    {
      inFileStr = *(argv + optind);
    }
  }
  ok = !usage;
  if(ok)
  {
    fP = NULL;
    errNum = WLZ_ERR_READ_EOF;
    if(((fP = (strcmp(inFileStr, "-")? fopen(inFileStr, "r"):
                                       stdin)) == NULL) ||
       ((inObj= WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
                     "%s: Failed to read object from file %s (%s).\n",
		     *argv, inFileStr, errMsg);
    }
    if(fP && strcmp(inFileStr, "-"))
    {
      (void )fclose(fP);
    }
  }
  if(ok)
  {
    outObj = WlzScalarMulAdd(inObj, m, a, gType, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
                     "%s: Failed to create scaled object (%s).\n",
		     *argv, errMsg);
    }
  }
  if(ok && (outFileStr != NULL))
  {
    if(((fP = (strcmp(outFileStr, "-")? fopen(outFileStr, "w"):
                                        stdout)) == NULL) ||
       ((errNum = WlzWriteObj(fP, outObj)) != WLZ_ERR_NONE))
    
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: Failed to write scaled object to file %s (%s).\n",
		     *argv, outFileStr, errMsg);
    }
    if(fP!= NULL)
    {
      (void )fclose(fP);
    }
  }
  (void )WlzFreeObj(outObj);
  (void )WlzFreeObj(inObj);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%s%s%s",
    *argv,
    " [-a#] [-g#] [-h] [-o<output object>] [-m #]\n"
    "                      [<input object>]\n"
    "Scales the grey values of an object using a linear scaling with\n"
    "v_out = m v_{in} + a.\n"
    "Version: ",
    WlzVersion(),
    "\n"
    "Options:\n"
    "  -a  Value for addition.\n"
    "  -g  Grey type specified using one of the characters:\n"
    "      i, s, u, f, d, r for int, short, unsigned byte, float, double\n"
    "      or RGBA.\n"
    "  -h  Prints this usage information.\n"
    "  -o  Output tiled object.\n"
    "  -m Value for product.\n");
  }
  return(!ok);
}
コード例 #12
0
ファイル: WlzRegCCor.c プロジェクト: VirtualFlyBrain/Woolz
/*!
* \return	Angle of roatation.
* \ingroup	WlzRegistration
* \brief	Polar samples then registers the given 2D domain objects
*               using a frequency domain cross correlation, to find
*               the angle of rotation about the given centre of rotation
*               which has the highest cross correlation value.
*		The rotation is always about the objects cente of mass.
* \param	tObj			The target object. Must have
*                                       been assigned.
* \param	sObj			The source object to be
*                                       registered with target object.
*                                       Must have been assigned.
* \param	initTr			Initial affine transform
*                                       to be applied to the source
*                                       object prior to registration.
* \param	maxRot			Maximum rotation.
* \param	winFn			Window function.
* \param	noise			Use Gaussian noise if non-zero.
* \param	dstErr			Destination error pointer,
*                                       may be NULL.
*/
static double	WlzRegCCorObjs2DRot(WlzObject *tObj, WlzObject *sObj,
				    WlzAffineTransform *initTr, double maxRot,
				    WlzWindowFnType winFn, int noise,
				    WlzErrorNum *dstErr)
{
  int		oIdx,
  		angCnt;
  double	angInc,
  		dstRot = 0.0;
  WlzIBox2	aBox;
  WlzIBox2	oBox[2];
  WlzIVertex2	rot,
  		aSz,
  		aOrg,
		winRad,
		winOrg,
		rotPad,
		rotCentreI;
  double	**oAr[2];
  WlzObject	*oObj[2],
  		*pObj[2],
		*wObj[2];
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const int	rotCnt = 500;
  const double	distInc = 1.0;

  /* Assign the target and transform source objects. */
  oAr[0] = oAr[1] = NULL;
  oAr[0] = oAr[1] = NULL;
  oObj[0] = oObj[1] = NULL;
  pObj[0] = pObj[1] = NULL;
  wObj[0] = wObj[1] = NULL;
  oObj[0] = WlzAssignObject(tObj, NULL);
  if((initTr == NULL) || WlzAffineTransformIsIdentity(initTr, NULL))
  {
    oObj[1] = WlzAssignObject(sObj, NULL);
  }
  else
  {
    oObj[1] = WlzAssignObject(
    	      WlzAffineTransformObj(sObj, initTr, WLZ_INTERPOLATION_NEAREST,
				   &errNum), NULL);
  }
  if(errNum == WLZ_ERR_NONE)
  {
    oIdx = 0;
    while((errNum == WLZ_ERR_NONE) && (oIdx < 2))
    {
      tObj = WlzAutoCor(oObj[oIdx], &errNum);
      (void )WlzFreeObj(oObj[oIdx]);
      oObj[oIdx] = WlzAssignObject(tObj, NULL);
      ++oIdx;
    }
  }
  /* Compute rectangular to polar transformation. */
  if(errNum == WLZ_ERR_NONE)
  {
    angInc = (2.0 * (maxRot + WLZ_M_PI)) / rotCnt;
    angCnt = (2.0 * WLZ_M_PI) / angInc;
    oIdx = 0;
    while((errNum == WLZ_ERR_NONE) && (oIdx < 2))
    {
      rotCentreI.vtX = 0;
      rotCentreI.vtY = 0;
      if(errNum == WLZ_ERR_NONE)
      {
	pObj[oIdx] = WlzAssignObject(
		     WlzPolarSample(oObj[oIdx], rotCentreI, angInc, distInc,
				    angCnt, 0, &errNum), NULL);
      }
      ++oIdx;
    }
  }
  /* Preproccess the objects using windows or noise. */
  if(errNum == WLZ_ERR_NONE)
  {
    oIdx = 0;
    while((errNum == WLZ_ERR_NONE) && (oIdx < 2))
    {
      oBox[oIdx] = WlzBoundingBox2I(pObj[oIdx], &errNum);
      if(errNum == WLZ_ERR_NONE)
      {
	winOrg.vtX = (oBox[oIdx].xMax + oBox[oIdx].xMin) / 2;
	winOrg.vtY = (oBox[oIdx].yMax + oBox[oIdx].yMin) / 2;
	winRad.vtX = (oBox[oIdx].xMax - oBox[oIdx].xMin) / 2;
	winRad.vtY = (oBox[oIdx].yMax - oBox[oIdx].yMin) / 2;
	wObj[oIdx] = WlzAssignObject(
		     WlzRegCCorPProcessObj2D(pObj[oIdx], winFn,
					     winOrg, winRad, 
					     &errNum), NULL);
      }
      ++oIdx;
    }
  }
  /* Create 2D double arrays from the polar sampled objects. */
  if(errNum == WLZ_ERR_NONE)
  {
    oIdx = 0;
    while((errNum == WLZ_ERR_NONE) && (oIdx < 2))
    {
      oBox[oIdx] = WlzBoundingBox2I(wObj[oIdx], &errNum);
      ++oIdx;
    }
  }
  if(errNum == WLZ_ERR_NONE)
  {
    aBox.xMin = WLZ_MIN(oBox[0].xMin, oBox[1].xMin);
    aBox.yMin = WLZ_MIN(oBox[0].yMin, oBox[1].yMin);
    aBox.xMax = WLZ_MAX(oBox[0].xMax, oBox[1].xMax);
    aBox.yMax = WLZ_MAX(oBox[0].yMax, oBox[1].yMax);
    rotPad.vtX = (aBox.xMax - aBox.xMin) / 2;
    rotPad.vtY = 1 + WLZ_NINT(maxRot / angInc);
    aBox.yMin -= rotPad.vtY;
    aBox.yMax += rotPad.vtY;
    aOrg.vtX = aBox.xMin;
    aOrg.vtY = aBox.yMin;
    aSz.vtX = aBox.xMax - aBox.xMin + 1;
    aSz.vtY = aBox.yMax - aBox.yMin + 1;
    (void )AlgBitNextPowerOfTwo((unsigned int *)&(aSz.vtX), aSz.vtX);
    (void )AlgBitNextPowerOfTwo((unsigned int *)&(aSz.vtY), aSz.vtY);
    oIdx = 0;
    while((errNum == WLZ_ERR_NONE) && (oIdx < 2))
    {
      errNum = WlzToArray2D((void ***)&(oAr[oIdx]), wObj[oIdx], aSz, aOrg,
      			    noise, WLZ_GREY_DOUBLE);
      ++oIdx;
    }
  }
#ifdef WLZ_REGCCOR_DEBUG
  if(errNum == WLZ_ERR_NONE)
  {
    FILE	*fP = NULL;
    WlzObject	*aObj = NULL;

    aObj = WlzFromArray2D((void **)(oAr[0]), aSz, aOrg,
    			  WLZ_GREY_DOUBLE, WLZ_GREY_DOUBLE, 0.0, 1.0,
			  0, 0, &errNum);
    if((fP = fopen("cObjR0.wlz", "w")) != NULL) 
    {
      (void )WlzWriteObj(fP, aObj); 
      (void )fclose(fP);
    }
    WlzFreeObj(aObj);
    aObj = WlzFromArray2D((void **)(oAr[1]), aSz, aOrg,
    			  WLZ_GREY_DOUBLE, WLZ_GREY_DOUBLE, 0.0, 1.0,
			  0, 0, &errNum);
    if((fP = fopen("cObjR1.wlz", "w")) != NULL)
    {
      (void )WlzWriteObj(fP, aObj);
      (void )fclose(fP);
    }
    WlzFreeObj(aObj);
  }
#endif /* WLZ_REGCCOR_DEBUG */
  /* Cross correlate. */
  if(errNum == WLZ_ERR_NONE)
  {
    (void )AlgCrossCorrelate2D(oAr[0], oAr[1], aSz.vtX, aSz.vtY);
    AlgCrossCorrPeakXY(&(rot.vtX), &(rot.vtY), NULL, oAr[0],
		       aSz.vtX, aSz.vtY, rotPad.vtX, rotPad.vtY);
    dstRot = rot.vtY * angInc;
    /* dstRot = -(rot.vtY) * angInc; */
  }
#ifdef WLZ_REGCCOR_DEBUG
  if(errNum == WLZ_ERR_NONE)
  {
    double	sSq[2];
    FILE	*fP = NULL;
    WlzObject	*cCObjR = NULL;
    
    oIdx = 0;
    while((errNum == WLZ_ERR_NONE) && (oIdx < 2))
    {
      (void )WlzGreyStats(wObj[oIdx], NULL, NULL, NULL, NULL, &(sSq[oIdx]),
			  NULL, NULL, &errNum);
      ++oIdx;
    }
    if(errNum == WLZ_ERR_NONE)
    {
      cCObjR = WlzFromArray2D((void **)(oAr[0]), aSz, aOrg,
			      WLZ_GREY_DOUBLE, WLZ_GREY_DOUBLE,
			      0.0,
			      255.0 / (1.0 + (sqrt(sSq[0] * sSq[1]) *
			      		      aSz.vtX * aSz.vtY)),
			      0, 0, &errNum);
    }
    if(cCObjR)
    {
      if((fP = fopen("cCObjR.wlz", "w")) != NULL)
      {
	(void )WlzWriteObj(fP, cCObjR);
	(void )fclose(fP);
      }
      (void )WlzFreeObj(cCObjR);
    }
  }
#endif /* WLZ_REGCCOR_DEBUG */
  for(oIdx = 0; oIdx < 2; ++oIdx)
  {
    (void )WlzFreeObj(oObj[oIdx]);
    (void )WlzFreeObj(pObj[oIdx]);
    (void )WlzFreeObj(wObj[oIdx]);
    AlcDouble2Free(oAr[oIdx]);
  }
  if(dstErr)
  {
    *dstErr = errNum;
  }
  return(dstRot);
}
コード例 #13
0
ファイル: WlzRegCCor.c プロジェクト: VirtualFlyBrain/Woolz
/*!
* \return	Translation.
* \ingroup	WlzRegistration
* \brief	Registers the given 2D domain objects using a
*               frequency domain cross correlation, to find
*               the translation which has the highest cross
*               correlation value.
* \param	tObj			The target object. Must have
*                                       been assigned.
* \param	sObj			The source object to be
*                                       registered with target object.
*                                       Must have been assigned.
* \param	initTr			Initial affine transform
*                                       to be applied to the source
*                                       object prior to registration.
* \param        maxTran    		Maximum translation.
* \param	maxTran			Maximum translation.
* \param	winFn			Window function.
* \param	noise			Use Gaussian noise if non-zero.
* \param	dstCCor			Destination ptr for the cross
*                                       correlation value, may be NULL.
* \param	dstErr			Destination error pointer,
*                                       may be NULL.
*/
static WlzDVertex2 WlzRegCCorObjs2DTran(WlzObject *tObj, WlzObject *sObj,
					WlzAffineTransform *initTr,
					WlzDVertex2 maxTran,
					WlzWindowFnType winFn, int noise,
					double *dstCCor, WlzErrorNum *dstErr)
{
  int		oIdx;
  double	cCor = 0.0;
  double	sSq[2];
  double	**oAr[2];
  WlzIBox2	aBox;
  WlzIBox2	oBox[2],
  		pBox[2];
  WlzIVertex2	aSz,
  		aOrg,
		centre,
		radius,
		tran;
  WlzDVertex2	dstTran;
  WlzObject	*oObj[2],
  		*pObj[2];
  WlzErrorNum	errNum = WLZ_ERR_NONE;

  dstTran.vtX = 0.0;
  dstTran.vtY = 0.0;
  oAr[0] = oAr[1] = NULL;
  oObj[0] = oObj[1] = NULL;
  pObj[0] = pObj[1] = NULL;
  oObj[0] = WlzAssignObject(tObj, NULL);
  /* Transform source object. */
  if((initTr == NULL) || WlzAffineTransformIsIdentity(initTr, NULL))
  {
    oObj[1] = WlzAssignObject(sObj, NULL);
  }
  else
  {
    oObj[1] = WlzAssignObject(
              WlzAffineTransformObj(sObj, initTr, WLZ_INTERPOLATION_NEAREST,
				    &errNum), NULL);
  }
  /* Preprocess the objects. */
  if(errNum == WLZ_ERR_NONE)
  {
    oIdx = 0;
    while((errNum == WLZ_ERR_NONE) && (oIdx < 2))
    {
      oBox[oIdx] = WlzBoundingBox2I(oObj[oIdx], &errNum);
      ++oIdx;
    }
  }
  if(errNum == WLZ_ERR_NONE)
  {
    oIdx = 0;
    while((errNum == WLZ_ERR_NONE) && (oIdx < 2))
    {
      centre.vtX = (oBox[oIdx].xMin + oBox[oIdx].xMax) / 2;
      centre.vtY = (oBox[oIdx].yMin + oBox[oIdx].yMax) / 2;
      radius.vtX = (oBox[oIdx].xMax - oBox[oIdx].xMin) / 2;
      radius.vtY = (oBox[oIdx].yMax - oBox[oIdx].yMin) / 2;
      pObj[oIdx] = WlzAssignObject(
                   WlzRegCCorPProcessObj2D(oObj[oIdx], winFn, centre, radius,
      					   &errNum), NULL);
      ++oIdx;
    }
  }
  /* Create double arrays. */
  if(errNum == WLZ_ERR_NONE)
  {
    oIdx = 0;
    while((errNum == WLZ_ERR_NONE) && (oIdx < 2))
    {
      pBox[oIdx] = WlzBoundingBox2I(pObj[oIdx], &errNum);
      ++oIdx;
    }
  }
  if(errNum == WLZ_ERR_NONE)
  {
    aBox.xMin = WLZ_MIN(pBox[0].xMin, pBox[1].xMin) - (int )(maxTran.vtX) + 1;
    aBox.yMin = WLZ_MIN(pBox[0].yMin, pBox[1].yMin) - (int )(maxTran.vtY) + 1;
    aBox.xMax = WLZ_MAX(pBox[0].xMax, pBox[1].xMax) + (int )(maxTran.vtX) + 1;
    aBox.yMax = WLZ_MAX(pBox[0].yMax, pBox[1].yMax) + (int )(maxTran.vtY) + 1;
    aOrg.vtX = aBox.xMin;
    aOrg.vtY = aBox.yMin;
    aSz.vtX = aBox.xMax - aBox.xMin + 1;
    aSz.vtY = aBox.yMax - aBox.yMin + 1;
    (void )AlgBitNextPowerOfTwo((unsigned int *)&(aSz.vtX), aSz.vtX);
    (void )AlgBitNextPowerOfTwo((unsigned int *)&(aSz.vtY), aSz.vtY);
    oIdx = 0;
    while((errNum == WLZ_ERR_NONE) && (oIdx < 2))
    {
      errNum = WlzToArray2D((void ***)&(oAr[oIdx]), pObj[oIdx], aSz, aOrg,
      			    noise, WLZ_GREY_DOUBLE);
      ++oIdx;
    }
  }
  if((dstCCor != NULL) && (errNum == WLZ_ERR_NONE))
  {
    oIdx = 0;
    while((errNum == WLZ_ERR_NONE) && (oIdx < 2))
    {
      WlzArrayStats2D((void **)(oAr[oIdx]), aSz, WLZ_GREY_DOUBLE, NULL, NULL,
		      NULL, &(sSq[oIdx]), NULL, NULL);
      ++oIdx;
    }
  }
#ifdef WLZ_REGCCOR_DEBUG
  if(errNum == WLZ_ERR_NONE)
  {
    FILE	*fP = NULL;
    WlzObject	*cCObjT = NULL;
    
    cCObjT = WlzFromArray2D((void **)(oAr[0]), aSz, aOrg,
			    WLZ_GREY_DOUBLE, WLZ_GREY_DOUBLE,
			    0.0, 1.0, 0, 0, &errNum);
    if(cCObjT)
    {
      if((fP = fopen("oObjT0.wlz", "w")) != NULL)
      {
	(void )WlzWriteObj(fP, cCObjT);
	(void )fclose(fP);
      }
      (void )WlzFreeObj(cCObjT);
    }
  }
  if(errNum == WLZ_ERR_NONE)
  {
    FILE	*fP = NULL;
    WlzObject	*cCObjT = NULL;
    
    cCObjT = WlzFromArray2D((void **)(oAr[1]), aSz, aOrg,
			    WLZ_GREY_DOUBLE, WLZ_GREY_DOUBLE,
			    0.0, 1.0, 0, 0, &errNum);
    if(cCObjT)
    {
      if((fP = fopen("oObjT1.wlz", "w")) != NULL)
      {
	(void )WlzWriteObj(fP, cCObjT);
	(void )fclose(fP);
      }
      (void )WlzFreeObj(cCObjT);
    }
  }
#endif /* WLZ_REGCCOR_DEBUG */
  /* Cross correlate. */
  if(errNum == WLZ_ERR_NONE)
  {
    (void )AlgCrossCorrelate2D(oAr[0], oAr[1], aSz.vtX, aSz.vtY);
    AlgCrossCorrPeakXY(&(tran.vtX), &(tran.vtY), &cCor, oAr[0],
		       aSz.vtX, aSz.vtY, maxTran.vtX, maxTran.vtY);
  }
#ifdef WLZ_REGCCOR_DEBUG
  if(errNum == WLZ_ERR_NONE)
  {
    FILE	*fP = NULL;
    WlzObject	*cCObjT = NULL;
    
    oIdx = 0;
    while((errNum == WLZ_ERR_NONE) && (oIdx < 2))
    {
      (void )WlzGreyStats(pObj[oIdx], NULL, NULL, NULL, NULL, &(sSq[oIdx]),
			  NULL, NULL, &errNum);
      ++oIdx;
    }
    if(errNum == WLZ_ERR_NONE)
    {
      cCObjT = WlzFromArray2D((void **)(oAr[0]), aSz, aOrg,
			      WLZ_GREY_DOUBLE, WLZ_GREY_DOUBLE,
			      0.0,
			      255.0 / (1.0 + (sqrt(sSq[0] * sSq[1]) *
			      		      aSz.vtX * aSz.vtY)),
			      0, 0, &errNum);
    }
    if(cCObjT)
    {
      if((fP = fopen("cCObjT.wlz", "w")) != NULL)
      {
	(void )WlzWriteObj(fP, cCObjT);
	(void )fclose(fP);
      }
      (void )WlzFreeObj(cCObjT);
    }
  }
#endif /* WLZ_REGCCOR_DEBUG */
  for(oIdx = 0; oIdx < 2; ++oIdx)
  {
    (void )WlzFreeObj(oObj[oIdx]);
    (void )WlzFreeObj(pObj[oIdx]);
    AlcDouble2Free(oAr[oIdx]);
  }
  if(errNum == WLZ_ERR_NONE)
  {
    dstTran.vtX = tran.vtX;
    dstTran.vtY = tran.vtY;
    if(dstCCor)
    {
      cCor = cCor / (1.0 + (sqrt(sSq[0] * sSq[1]) * aSz.vtX * aSz.vtY));
      *dstCCor = cCor;
    }
  }
  if(dstErr)
  {
    *dstErr = errNum;
  }
  return(dstTran);
}
コード例 #14
0
ファイル: WlzRegCCor.c プロジェクト: VirtualFlyBrain/Woolz
/*!
* \return	Affine transform which brings the two objects into register.
* \ingroup	WlzRegistration
* \brief	Registers the two given 2D domain objects using a
*               frequency domain cross correlation.  An affine transform
*               is computed, which when applied to the source object
*               takes it into register with the target object.
*               A resolution pyramid is built from the given objects
*               and used to register the objects, progressing from
*               a low resolution towards the full resolution objects.
* \param	tObj			The target object. Must have
*                                       been assigned.
* \param	sObj			The source object to be
*                                       registered with target object.
* \param	initTr			Initial affine transform
*                                       to be applied to the source
*                                       object prior to registration.
*                                       Only translations in x and y
*                                       and rotation about the z axis
*                                       are used. May be NULL which is
*                                       equivalent to an identity transform.
* \param	trType			Required transform type.
* \param	maxTran			Maximum translation.
* \param	maxRot			Maximum rotation.
* \param	maxItr			Maximum number of iterations,
*                                       if \f$leq\f$ 0 then infinite iterations
*                                       are allowed.
* \param	winFn			Window function.
* \param	noise			Use Gaussian noise if non-zero.
* \param	dstConv			Destination ptr for the
*                                       convergence flag (non zero
*                                       on convergence), may be NULL.
* \param	dstCCor			Destination ptr for the cross
*                                       correlation value, may be NULL.
* \param	dstErr			Destination error pointer,
*                                       may be NULL.
*/
static WlzAffineTransform *WlzRegCCorObjs2D(WlzObject *tObj, WlzObject *sObj,
					    WlzAffineTransform *initTr,
					    WlzTransformType trType,
					    WlzDVertex2 maxTran, double maxRot,
					    int maxItr,
					    WlzWindowFnType winFn, int noise,
					    int *dstConv, double *dstCCor,
					    WlzErrorNum *dstErr)
{
  int		tI1,
		samIdx,
		conv,
  		nSam = 0;
  double	rot0,
		rot1,
		sMaxRot,
  		cCor = 0.0;
  WlzPixelV	gV[4];
  WlzIVertex2	tIV0,
  		tIV1;
  WlzIVertex3	samFacV;
  WlzDVertex2	tran0,
  		tran1,
		sMaxTran;
  WlzIBox2	sBox,
  		tBox;
  int		*samFac = NULL;
  WlzObject	**sTObj = NULL,
  		**sSObj = NULL;
  WlzAffineTransform *samRegTr0 = NULL,
  		*samRegTr1 = NULL,
		*regTr = NULL;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  WlzAffineTransformPrim trPrim;
  WlzPixelV	zeroBgd;
  const int	samFacStep = 4,
  		maxSam = 16,
  		minSamSz = 100;

  zeroBgd.type = WLZ_GREY_INT;
  zeroBgd.v.inv = 0;
  gV[0].type = gV[1].type = gV[2].type = gV[3].type = WLZ_GREY_DOUBLE;
  /* Compute the number of x4 subsampling operations to use. */
  sBox = WlzBoundingBox2I(sObj, &errNum);
  if(errNum == WLZ_ERR_NONE)
  {
    tBox = WlzBoundingBox2I(tObj, &errNum);
  }
  if(errNum == WLZ_ERR_NONE)
  {
    tIV0.vtX = sBox.xMax - sBox.xMin + 1;
    tIV0.vtY = sBox.yMax - sBox.yMin + 1;
    tIV1.vtX = tBox.xMax - tBox.xMin + 1;
    tIV1.vtY = tBox.yMax - tBox.yMin + 1;
    tIV0.vtX = WLZ_MIN(tIV0.vtX, tIV1.vtX);
    tIV0.vtY = WLZ_MIN(tIV0.vtY, tIV1.vtY);
    nSam = 1;
    tI1 = WLZ_MIN(tIV0.vtX, tIV0.vtY);
    while((nSam < maxSam) && (tI1 > minSamSz))
    {
      ++nSam;
      tI1 /= samFacStep;
    }
  }
  /* Allocate space for subsampled objects. */
  if(errNum == WLZ_ERR_NONE)
  {
    if(((samFac = (int *)AlcMalloc(nSam * sizeof(int))) == NULL) ||
       ((sTObj = (WlzObject **)AlcCalloc(nSam,
    				         sizeof(WlzObject *))) == NULL) ||
       ((sSObj = (WlzObject **)AlcCalloc(nSam,
       					 sizeof(WlzObject *))) == NULL))
    {
      errNum = WLZ_ERR_MEM_ALLOC;
    }
  }
  /* Compute subsampled objects and make sure the background value is zero. */
  if(errNum == WLZ_ERR_NONE)
  {
    samIdx = 0;
    *samFac = 1;
    samFacV.vtX = samFacV.vtY = samFacStep;
    *(sTObj + 0) = WlzAssignObject(tObj, NULL);
    *(sSObj + 0) = WlzAssignObject(sObj, NULL);
    while((errNum == WLZ_ERR_NONE) && (++samIdx < nSam))
    {
      *(samFac + samIdx) = *(samFac + samIdx - 1) * samFacStep;
      *(sTObj + samIdx) = WlzAssignObject(
      			  WlzSampleObj(*(sTObj + samIdx - 1), samFacV,
      				       WLZ_SAMPLEFN_GAUSS, &errNum), NULL);
      if(errNum == WLZ_ERR_NONE)
      {
	(void )WlzSetBackground(*(sTObj + samIdx), zeroBgd);
        *(sSObj + samIdx) = WlzAssignObject(
			    WlzSampleObj(*(sSObj + samIdx - 1), samFacV,
			       	         WLZ_SAMPLEFN_GAUSS, &errNum), NULL);
      }
      if(errNum == WLZ_ERR_NONE)
      {
        (void )WlzSetBackground(*(sSObj + samIdx), zeroBgd);
      }
    }
  }
  /* Register the subsampled objects starting with the lowest resolution
   * (highest subsampling) and progressing to the unsampled objects. */
  if(errNum == WLZ_ERR_NONE)
  {
    if(initTr == NULL)
    {
      rot0 = 0.0;
      tran0.vtX = 0.0;
      tran0.vtY = 0.0;
    }
    else
    {
      errNum = WlzAffineTransformPrimGet(initTr, &trPrim);
      rot0 = trPrim.theta;
      tran0.vtX = trPrim.tx;
      tran0.vtY = trPrim.ty;
    }
    conv = 1;
    samIdx = nSam - 1;
    sMaxRot = maxRot;
    sMaxTran.vtX =  maxTran.vtX / *(samFac + nSam - 1);
    sMaxTran.vtY =  maxTran.vtY / *(samFac + nSam - 1);
    while((errNum == WLZ_ERR_NONE) && conv && (samIdx >= 0))
    {
      /* Compute initial transform. */
      rot1 = rot0;
      tran1.vtX = tran0.vtX / *(samFac + samIdx);
      tran1.vtY = tran0.vtY / *(samFac + samIdx);
      samRegTr0 = WlzAffineTransformFromPrimVal(WLZ_TRANSFORM_2D_AFFINE,
      					        tran1.vtX, tran1.vtY, 0.0, 1.0, 
						rot1, 0.0, 0.0, 0.0, 0.0, 0,
						&errNum);
      /* Compute registration transform. */
      if(errNum == WLZ_ERR_NONE)
      {
	samRegTr1 = WlzRegCCorObjs2D1(*(sTObj + samIdx), *(sSObj + samIdx),
				      samRegTr0,
				      trType, sMaxTran, sMaxRot, maxItr,
				      winFn, noise,
				      &conv, &cCor, &errNum);
        
      }
      if(samRegTr0)
      {
        (void )WlzFreeAffineTransform(samRegTr0);
	samRegTr0 = NULL;
      }
      if(samRegTr1)
      {
        samRegTr0 = samRegTr1;
	samRegTr1 = NULL;
      }
      if(errNum == WLZ_ERR_NONE)
      {
        errNum = WlzAffineTransformPrimGet(samRegTr0, &trPrim);
      }
      if(errNum == WLZ_ERR_NONE)
      {
	rot0 = trPrim.theta;
	tran0.vtX = trPrim.tx * *(samFac + samIdx);
	tran0.vtY = trPrim.ty * *(samFac + samIdx);
      }
      /* Set registration limits. */
      sMaxRot = WLZ_M_PI / 24.0;
      sMaxTran.vtX = samFacStep * 3;
      sMaxTran.vtY = samFacStep * 3;
      --samIdx;
    }
  }
  if(errNum == WLZ_ERR_NONE)
  {
    if(dstConv)
    {
      *dstConv = conv;
    }
    if(dstCCor)
    {
      *dstCCor = cCor;
    }
    regTr = samRegTr0;
  }
  AlcFree(samFac);
  /* Free subsampled objects. */
  if(sTObj)
  {
    for(samIdx = 0; samIdx < nSam; ++samIdx)
    {
      (void )WlzFreeObj(*(sTObj + samIdx));
    }
    AlcFree(sTObj);
  }
  if(sSObj)
  {
    for(samIdx = 0; samIdx < nSam; ++samIdx)
    {
      (void )WlzFreeObj(*(sSObj + samIdx));
    }
    AlcFree(sSObj);
  }
  if(dstErr)
  {
    *dstErr = errNum;
  }
  return(regTr);
}
コード例 #15
0
ファイル: WlzExtFFAffineTrFitBox.c プロジェクト: omsai/Woolz
int             main(int argc, char **argv)
{
  int           option,
                ok = 1,
                usage = 0,
		dim = 0,
		transform = 0;
  WlzIBox3	bBox[2];
  WlzEffFormat  outFmt = WLZEFF_FORMAT_NONE;
  WlzEffFormat  inFmt[2] = {WLZEFF_FORMAT_NONE};
  WlzObject     *outObj = NULL;
  WlzObject	*inObj[2] = {NULL};
  char          *outFileStr;
  char		*inFileStr[2] = {NULL};
  WlzAffineTransform *tr = NULL;
  WlzErrorNum   errNum = WLZ_ERR_NONE;
  const char    *errMsg;
  static char   optList[] = "s:t:o:u:hT",
                fileStrDef[] = "-";

  opterr = 0;
  inFileStr[0] = fileStrDef;
  inFileStr[1] = fileStrDef;
  outFileStr = fileStrDef;
  while((usage == 0) && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 's':
	if((inFmt[0] = WlzEffStringExtToFormat(optarg)) == 0)
	{
	  usage = 1;
	  ok = 0;
	}
	break;
      case 't':
	if((inFmt[1] = WlzEffStringExtToFormat(optarg)) == 0)
	{
	  usage = 1;
	  ok = 0;
	}
	break;
      case 'u':
	if((outFmt = WlzEffStringExtToFormat(optarg)) == 0)
	{
	  usage = 1;
	  ok = 0;
	}
	break;
      case 'o':
	outFileStr = optarg;
	break;
      case 'T':
	transform = 1;
	break;
      case 'h': /* FALLTHROUGH */
      default:
	usage = 1;
	break;
    }
  }
  if(usage == 0)
  {
    usage = (optind + 2 != argc);
  }
  if(usage == 0)
  {
    inFileStr[0] = *(argv + optind);
    inFileStr[1] = *(argv + optind + 1);
  }
  if(usage == 0)
  {
    if(inFmt[0] == WLZEFF_FORMAT_NONE)
    {
      inFmt[0] = WlzEffStringFormatFromFileName(inFileStr[0]);
    }
    if(inFmt[1] == WLZEFF_FORMAT_NONE)
    {
      inFmt[1] = WlzEffStringFormatFromFileName(inFileStr[1]);
    }
    if(outFmt == WLZEFF_FORMAT_NONE)
    {
      outFmt = WlzEffStringFormatFromFileName(outFileStr);
    }
    if((inFmt[0] == WLZEFF_FORMAT_NONE) || (inFmt[1] == WLZEFF_FORMAT_NONE) ||
       (outFmt == WLZEFF_FORMAT_NONE))
    {
      usage = 1;
    }
  }
  ok = (usage == 0);
  /* Read source and target objects. */
  if(ok)
  {
    int		idx;

    for(idx = 0; ok && (idx < 2); ++idx)
    {
      char *fStr;
      FILE *fP;

      if(strcmp(inFileStr[idx], "-") == 0)
      {
        fP = stdin;
	fStr = NULL;
      }
      else
      {
        fP = NULL;
	fStr = inFileStr[idx];
      }
      if((inObj[idx] = WlzAssignObject(WlzEffReadObj(fP, fStr, inFmt[idx],
                                       0, 0, 0, &errNum), NULL)) == NULL)
      {
	ok = 0;
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
	    "%s: Failed to read object from file(s) %s (%s)\n",
	    *argv, inFileStr[idx], errMsg);
      }
    }
  }
  /* Check object dimension */
  if(ok)
  {
    int		idx;
    int		d[2];

    d[0] = 0;
    for(idx = 0; ok && (idx < 2); ++idx)
    {
      d[idx] = WlzObjectDimension(inObj[idx], &errNum);
      ok = (errNum == WLZ_ERR_NONE);
    }
    if(errNum == WLZ_ERR_NONE)
    {
      if((d[0] == 0) || (d[0] != d[1]))
      {
	ok = 0;
        errNum = WLZ_ERR_OBJECT_TYPE;
      }
    }
    dim = d[0];
    if(errNum != WLZ_ERR_NONE)
    {
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
          "%s: Failed to establish object dimensions (%s)\n",
	  *argv, errMsg);
    }
  }
  /* Compute the bounding box of the source and target objects. */
  if(ok)
  {
    int		idx;

    for(idx = 0; ok && (idx < 2); ++idx)
    {
      bBox[idx] = WlzBoundingBox3I(inObj[idx], &errNum);
      if(errNum != WLZ_ERR_NONE)
      {
        ok = 0;
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
	    "%s: Failed to compute bounding box of object read from file\n"
	    "%s (%s).\n",
	    *argv, inFileStr[idx], errMsg);
      }
    }
  }
  /* Compute affine transform which will register the source to target
   * bounding box. */
  if(ok)
  {
    int		idx,
    		nVtx;
    WlzVertexType vType;
    WlzTransformType tType;
    WlzVertexP vP[2];
    WlzDVertex3	wSp[48];

    vP[0].d3 = wSp;
    vP[1].d3 = wSp + 24;
    if(dim == 2)
    {
      nVtx = 4;
      vType = WLZ_VERTEX_D2;
      tType = WLZ_TRANSFORM_2D_AFFINE;
      for(idx = 0; idx < 2; ++idx)
      {
        (vP[idx].d2)[0].vtX = bBox[idx].xMin;
	(vP[idx].d2)[0].vtY = bBox[idx].yMin;
        (vP[idx].d2)[1].vtX = bBox[idx].xMax;
	(vP[idx].d2)[1].vtY = bBox[idx].yMin;
        (vP[idx].d2)[2].vtX = bBox[idx].xMax;
	(vP[idx].d2)[2].vtY = bBox[idx].yMax;
        (vP[idx].d2)[3].vtX = bBox[idx].xMin;
	(vP[idx].d2)[3].vtY = bBox[idx].yMax;
      }
    }
    else /* dim == 3 */
    {
      nVtx = 8;
      vType = WLZ_VERTEX_D3;
      tType = WLZ_TRANSFORM_3D_AFFINE;
      for(idx = 0; idx < 2; ++idx)
      {
        (vP[idx].d3)[0].vtX = bBox[idx].xMin;
	(vP[idx].d3)[0].vtY = bBox[idx].yMin;
	(vP[idx].d3)[0].vtZ = bBox[idx].zMin;
        (vP[idx].d3)[1].vtX = bBox[idx].xMax;
	(vP[idx].d3)[1].vtY = bBox[idx].yMin;
	(vP[idx].d3)[1].vtZ = bBox[idx].zMin;
        (vP[idx].d3)[2].vtX = bBox[idx].xMax;
	(vP[idx].d3)[2].vtY = bBox[idx].yMax;
	(vP[idx].d3)[2].vtZ = bBox[idx].zMin;
        (vP[idx].d3)[3].vtX = bBox[idx].xMin;
	(vP[idx].d3)[3].vtY = bBox[idx].yMax;
	(vP[idx].d3)[3].vtZ = bBox[idx].zMin;
        (vP[idx].d3)[4].vtX = bBox[idx].xMin;
	(vP[idx].d3)[4].vtY = bBox[idx].yMin;
	(vP[idx].d3)[4].vtZ = bBox[idx].zMax;
        (vP[idx].d3)[5].vtX = bBox[idx].xMax;
	(vP[idx].d3)[5].vtY = bBox[idx].yMin;
	(vP[idx].d3)[5].vtZ = bBox[idx].zMax;
        (vP[idx].d3)[6].vtX = bBox[idx].xMax;
	(vP[idx].d3)[6].vtY = bBox[idx].yMax;
	(vP[idx].d3)[6].vtZ = bBox[idx].zMax;
        (vP[idx].d3)[7].vtX = bBox[idx].xMin;
	(vP[idx].d3)[7].vtY = bBox[idx].yMax;
	(vP[idx].d3)[7].vtZ = bBox[idx].zMax;
      }
    }
    tr = WlzAffineTransformLSq(vType, nVtx, vP[1], nVtx, vP[0], 0, NULL,
                               tType, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
	  "%s: Failed to compute affine transform (%s).\n",
	  *argv, errMsg);
    }
  }
  /* Create affine transform object or affine transform the source object
   * as required. */
  if(ok)
  {
    int		idx,
    		idy;
    const double eps = 1.0e-12;

    /* Tidy up the transform, |t_{ij}| < eps => t_{ij} = 0.0. */
    for(idy = 0; idy < 4; ++idy)
    {
      for(idx = 0; idx < 4; ++idx)
      {
        if(fabs(tr->mat[idy][idx]) < eps)
	{
	  tr->mat[idy][idx] = 0.0;
	}
      }
    }
    if(transform)
    {
      outObj = WlzAffineTransformObj(inObj[0], tr, WLZ_INTERPOLATION_NEAREST,
                                     &errNum);
      if(outObj)
      {
        tr = NULL;
      }
    }
    else
    {
      WlzDomain dom;
      WlzValues val;

      dom.t = tr;
      val.core = NULL;
      outObj = WlzMakeMain(WLZ_AFFINE_TRANS, dom, val, NULL, NULL, &errNum);
    }
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
                     "%s: Failed to %saffine transform object (%s).\n",
		     *argv, (transform)? "create ": "", errMsg);
    }
  }
  /* Write the output object. */
  if(ok)
  {
    char *fStr;
    FILE *fP;

    if(strcmp(outFileStr, "-") == 0)
    {
      fP = stdout;
      fStr = NULL;
    }
    else
    {
      fP = NULL;
      fStr = outFileStr;
    }
    errNum = WlzEffWriteObj(fP, fStr, outObj, outFmt);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
	  "%s: Failed to write object to file %s (%s)\n",
	  *argv, outFileStr, errMsg);
    }
  }
  (void )WlzFreeObj(inObj[0]);
  (void )WlzFreeObj(inObj[1]);
  (void )WlzFreeObj(outObj);
  if(usage)
  {
    char *fmtStr = NULL;

    fmtStr = WlzEffFormatTable(2, 50, 10, NULL);
    (void )fprintf(
        stderr,
	"Usage: %s%s%s%s%s%s%s%s\n",
	*argv,
	" [-h] [-T]\n"
	"\t\t[-o<out file>] [-s<src fmt>] [-t<tgt fmt>] [-u<out fmt>]\n"
	"\t\t<source object> <target object>\n"
        "Computes the Woolz affine transform which makes the bounding box of\n"
	"the source object equal to that of the target object.\n"
	"Version: ",
	WlzVersion(),
	"\n"
	"  -h Help, prints this usage information.\n"
	"  -o Output file.\n"
	"  -s Source file format.\n"
	"  -t Target file format.\n"
	"  -u Output file format.\n"
	"  -T Transform the source object and write it to the output file\n"
	"     rather than the affine transform.\n"
        "The known file formats are:\n"
	"  Description                                       Extension\n"
	"  ***********                                       *********\n",
	fmtStr,
	"Simple example:\n  ",
	*argv,
	"-o out.wlz small.vtk big.stl\n"
	"Reads the source object from the file small.vtk and the target\n"
	"object from big.stl then computes the affine transform which scales\n"
	"the source objects bounding box to fit that of the target object.\n"
	"The output transform is written to the file out.wlz.\n");
  }
  return(!ok);
}
コード例 #16
0
ファイル: WlzSetVoxelSize.c プロジェクト: dscho/Woolz
int main(int	argc,
	 char	**argv)
{

  WlzObject	*obj;
  FILE		*inFile;
  char 		optList[] = "x:y:z:hv";
  int		option;
  int		xFlg=0, yFlg=0, zFlg=0;
  float		x_size=1.0, y_size=1.0, z_size=1.0;
  int		verboseFlg=0;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const char	*errMsg;
    
  /* read the argument list and check for an input file */
  opterr = 0;
  
  while( (option = getopt(argc, argv, optList)) != EOF ){
    switch( option ){

    case 'x':
      x_size = atof(optarg);
      xFlg = 1;
      break;

    case 'y':
      y_size = atof(optarg);
      yFlg = 1;
      break;

    case 'z':
      z_size = atof(optarg);
      zFlg = 1;
      break;

    case 'v':
      verboseFlg = 1;
      break;

    case 'h':
    default:
      usage(argv[0]);
      return 1;

    }
  }

  if( (x_size <= 0.0) || (y_size <= 0.0) || (z_size <= 0.0) ){
    fprintf(stderr, "%s: voxel sizes must be non-zero and positive\n",
	    argv[0]);
    return 1;
  }

  inFile = stdin;
  if( optind < argc ){
    if( (inFile = fopen(*(argv+optind), "r")) == NULL ){
      fprintf(stderr, "%s: can't open file %s\n", argv[0], *(argv+optind));
      usage(argv[0]);
      return 1;
    }
  }

  /* read objects and threshold if possible */
  while(((obj = WlzAssignObject(WlzReadObj(inFile, NULL), NULL)) != NULL) &&
        (errNum == WLZ_ERR_NONE))
  {
    switch( obj->type )
    {
    case WLZ_3D_DOMAINOBJ:
      if( obj->domain.p && (obj->domain.p->type == WLZ_2D_DOMAINOBJ) ){
	if( xFlg ){
	  obj->domain.p->voxel_size[0] = x_size;
	}
	if( yFlg ){
	  obj->domain.p->voxel_size[1] = y_size;
	}
	if( zFlg ){
	  obj->domain.p->voxel_size[2] = z_size;
	}
      }
      if((errNum = WlzWriteObj(stdout, obj)) != WLZ_ERR_NONE) {
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: failed to write object (%s).\n",
		       argv[0], errMsg);
	return(1);
      }
      break;

    default:
      if((errNum = WlzWriteObj(stdout, obj)) != WLZ_ERR_NONE) {
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: failed to write object (%s).\n",
		       argv[0], errMsg);
	return(1);
      }
      break;
    }
    WlzFreeObj(obj);
  }

  return 0;
}
コード例 #17
0
int		main(int argc, char *argv[])
{
  int		idN,
		eIdx = -1,
		nIdx = -1,
  		ok = 1,
		exhaustive = 0,
  		option,
		repeats = 1,
  		usage = 0;
  WlzDVertex3	vtx;
  FILE		*fP = NULL;
  char		*inObjFileStr,
  		*outFileStr;
  const char	*errMsgStr;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  WlzObject	*inObj = NULL;
  WlzCMeshP 	mesh;
  static char   optList[] = "eho:p:R:";
  const char    inObjFileStrDef[] = "-",
  	        outFileStrDef[] = "-";

  opterr = 0;
  mesh.v = NULL;
  inObjFileStr = (char *)inObjFileStrDef;
  outFileStr = (char *)outFileStrDef;
  while((usage == 0) && ((option = getopt(argc, argv, optList)) != EOF))
  {
    switch(option)
    {
      case 'e':
        exhaustive = 1;
	break;
      case 'o':
        outFileStr = optarg;
	break;
      case 'p':
	if(sscanf(optarg, "%lg,%lg,%lg",
		  &(vtx.vtX), &(vtx.vtY), &(vtx.vtZ)) != 3)
	{
	  usage = 1;
	}
	break;
      case 'R':
        if(sscanf(optarg, "%d", &repeats) != 1)
	{
	  usage = 1;
	}
	break;
      case 'h':
      default:
	usage = 1;
	break;
    }
  }
  if(usage == 0)
  {
    if((inObjFileStr == NULL) || (*inObjFileStr == '\0') ||
       (outFileStr == NULL) || (*outFileStr == '\0'))
    {
      usage = 1;
    }
    if((usage == 0) && (optind < argc))
    {
      if((optind + 1) != argc)
      {
        usage = 1;
      }
      else
      {
        inObjFileStr = *(argv + optind);
      }
    }
  }
  ok = usage == 0;
  if(ok)
  {
    if((inObjFileStr == NULL) ||
       (*inObjFileStr == '\0') ||
       ((fP = (strcmp(inObjFileStr, "-")?
              fopen(inObjFileStr, "r"): stdin)) == NULL) ||
       ((inObj = WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL) ||
       (errNum != WLZ_ERR_NONE))
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Failed to read object from file (%s)\n",
                     *argv, inObjFileStr);
    }
    if(fP && strcmp(inObjFileStr, "-"))
    {
      (void )fclose(fP); fP = NULL;
    }
  }
  if(ok)
  {
    switch(inObj->type)
    {
      case WLZ_CMESH_2D:
        mesh.m2 = inObj->domain.cm2;
	break;
      case WLZ_CMESH_3D:
        mesh.m3 = inObj->domain.cm3;
	break;
      default:
        ok = 0;
	errNum = WLZ_ERR_OBJECT_TYPE;
        (void )WlzStringFromErrorNum(errNum, &errMsgStr);
	(void )fprintf(stderr,
		   "%s: Invalid object type, must be WLZ_CMESH_[23]D (%s),\n",
		       argv[0],
		       errMsgStr);
        break;
    }
  }
  if(ok)
  {
    for(idN = 0; idN < repeats; ++idN)
    {
      eIdx = WlzCMeshElmEnclosingPos(mesh, -1, vtx.vtX, vtx.vtY, vtx.vtZ,
                                     exhaustive, &nIdx);
    }
    if((fP = (strcmp(outFileStr, "-")?
	     fopen(outFileStr, "w"): stdout)) == NULL)
    {
      ok = 0;
      (void )fprintf(stderr,
		     "%s: Failed to open output file %s.\n",
		     argv[0], outFileStr);
    }
  }
  if(ok)
  {
    if(fprintf(fP, "%d %d\n", eIdx, nIdx) <= 0)
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Failed to write to file %s.\n",
		     argv[0], outFileStr);
    }
  }
  (void )WlzFreeObj(inObj);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s [-h] [-o<output file>] [-p<position>] [-R<repeats>]\n"
    "       [<input cmesh object>]\n"
    "Reads a conforming mesh and then searches for the element which\n"
    "contains the given vertex.\n"
    "The output is either:\n"
    "  <element index> <node index>\n"
    "where the element index is the index of the mesh element enclosing the\n"
    "given vertex and the node index is the index of the node closest to\n"
    "the given vertex. If the vertex is not within a mesh element then the\n"
    "index will be a negative value. If the element index is not negative\n"
    "then the node index may not be the closest node.\n"
    "Options are:\n"
    "  -e  Exhaustive search (slow), every element in the mesh searched.\n"
    "  -h  Help, prints this usage message.\n"
    "  -o  Output file.\n"
    "  -p  Given vertex position given as <vx>,<vy>,<vz>.\n"
    "  -R  number of times to repeat the computation.\n",
    argv[0]);

  }
  return(!ok);
}
コード例 #18
0
ファイル: WlzDistanceTransform.c プロジェクト: dscho/Woolz
int		main(int argc, char *argv[])
{
  int		ok,
		bnd = 0,
  		con,
  		option,
		usage = 0;
  char		*inFileStr,
  		*forFileStr,
  		*refFileStr,
		*outFileStr;
  double	dParam = 10.0;
  FILE		*fP = NULL;
  WlzObject	*tObj0,
  		*tObj1,
		*forObj = NULL,
		*refObj = NULL,
		*dstObj = NULL;
  WlzDistanceType dFn;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const char	*errMsgStr;
  static char	optList[] = "bhd:f:p:o:";
  const char    fileStrDef[] = "-";
  const WlzConnectType defDFn = WLZ_OCTAGONAL_DISTANCE;

  /* Parse the argument list and check for input files. */
  opterr = 0;
  inFileStr = (char *)fileStrDef;
  forFileStr = (char *)fileStrDef;
  outFileStr = (char *)fileStrDef;
  dFn = defDFn;
  while((option = getopt(argc, argv, optList)) != EOF)
  {
    switch(option)
    {
      case 'b':
        bnd = 1;
	break;
      case 'd':
	if(sscanf(optarg, "%d", &con) != 1)
	{
	  usage = 1;
	}
	else
	{
	  switch(con)
	  {
	    case 0:
	      dFn = WLZ_EUCLIDEAN_DISTANCE;
	      break;
	    case 1:
	      dFn = WLZ_OCTAGONAL_DISTANCE;
	      break;
	    case 2:
	      dFn = WLZ_APX_EUCLIDEAN_DISTANCE;
	      break;
	    case 4:
	      dFn = WLZ_4_DISTANCE;
	      break;
	    case 6:
	      dFn = WLZ_6_DISTANCE;
	      break;
	    case 8:
	      dFn = WLZ_8_DISTANCE;
	      break;
	    case 18:
	      dFn = WLZ_18_DISTANCE;
	      break;
	    case 26:
	      dFn = WLZ_26_DISTANCE;
	      break;
	    default:
	      usage = 1;
	      break;
	  }
	}
	break;
      case 'f':
	forFileStr = optarg;
	break;
      case 'p':
	if(sscanf(optarg, "%lg", &dParam) != 1)
	{
	  usage = 1;
	}
	break;
      case 'o':
	outFileStr = optarg;
	break;
      case 'h':
      default:
	usage = 1;
	break;
    }
  }
  ok = !usage;
  if(ok && (optind < argc))
  {
    if((optind + 1) != argc)
    {
      usage = 1;
      ok = 0;
    }
    else
    {
      refFileStr = argv[optind];
    }
  }
  /* Read the reference object. */
  if(ok)
  {
    if((refFileStr == NULL) ||
       (*refFileStr == '\0') ||
       ((fP = (strcmp(refFileStr, "-")?
              fopen(refFileStr, "r"): stdin)) == NULL) ||
       ((refObj = WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL))
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Failed to read reference object from file %s.\n",
                     argv[0], refFileStr);
    }
    if(fP && strcmp(refFileStr, "-"))
    {
      (void )fclose(fP); fP = NULL;
    }
  }
  /* Read the foreground object. */
  if(ok)
  {
    if((forFileStr == NULL) ||
       (*forFileStr == '\0') ||
       ((fP = (strcmp(forFileStr, "-")?
              fopen(forFileStr, "r"): stdin)) == NULL) ||
       ((forObj = WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL))
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Failed to read foreground object from file %s.\n",
                     argv[0], forFileStr);
    }
    if(fP && strcmp(forFileStr, "-"))
    {
      (void )fclose(fP); fP = NULL;
    }
  }
  /* Check object types and parse the promote the default distance function
   * if required. */
  if(ok)
  {
    if(refObj->type != forObj->type)
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Foreground and reference object types differ.\n",
		     argv[0]);
    }
  }
  if((errNum == WLZ_ERR_NONE) && bnd)
  {
    tObj0 = tObj1 = NULL;
    tObj0 = WlzObjToBoundary(refObj, 1, &errNum);
    if(errNum == WLZ_ERR_NONE)
    {
      tObj1 = WlzBoundaryToObj(tObj0, WLZ_VERTEX_FILL, &errNum);
    }
    if(errNum == WLZ_ERR_NONE)
    {
      (void )WlzFreeObj(refObj);
      refObj = tObj1;
      tObj1 = NULL;
    }
    (void )WlzFreeObj(tObj0);
    (void )WlzFreeObj(tObj1);
  }
  /* Compute the distance transform object. */
  if(ok)
  {
    dstObj = WlzAssignObject(
    	     WlzDistanceTransform(forObj, refObj, dFn, dParam, &errNum), NULL);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsgStr);
      (void )fprintf(stderr,
      		     "%s: Failed to compute distance object, %s.\n",
		     argv[0], errMsgStr);
    }
  }
  /* Output the distance transform object. */
  if(ok)
  {
    if((fP = (strcmp(outFileStr, "-")?
             fopen(outFileStr, "w"): stdout)) == NULL)
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Failed to open output file %s.\n",
                     argv[0], outFileStr);
    }
  }
  if(ok)
  {
    errNum = WlzWriteObj(fP, dstObj);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsgStr);
      (void )fprintf(stderr,
                     "%s: Failed to write output object, %s.\n",
                     argv[0], errMsgStr);
    }
  }
  (void )WlzFreeObj(forObj);
  (void )WlzFreeObj(refObj);
  (void )WlzFreeObj(dstObj);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s [-b] [-d#] [-f#] [-p#] [-o#] [-h] [<Reference input file>]\n"
    "Computes a distance transform object which has the domain of the\n"
    "foreground object and values which are the distance from the reference\n"
    "object.\n"
    "Options are:\n"
    "  -b  Use the boundary of the reference object.\n"
    "  -d  Distance function:\n"
    "              0: Euclidean (2D and 3D, unimplemented)\n"
    "              1: octagonal (2D and 3D) - default\n"
    "              2: approximate Euclidean (2D and 3D)\n"
    "              4: 4-connected (2D)\n"
    "              8: 8-connected (2D)\n"
    "              6: 6-connected (3D)\n"
    "             18: 18-connected (3D)\n"
    "             26: 26-connected (3D)\n"
    "  -f  The foreground object file.\n" 
    "  -p  Distance function parameter, which is curently only used for\n"
    "      approximate Euclidean distance transforms. The value should\n"
    "      be >= 1, with larger values giving greater accuracy at the\n"
    "      cost of increased time. Default value - 10.0.\n"
    "  -o  Output object file.\n"
    "  -h  Help - prints this usage message\n",
    argv[0]);
  }
  return(!ok);
}
コード例 #19
0
ファイル: WlzRGBAThreshold.c プロジェクト: dscho/Woolz
/*! 
* \ingroup      WlzThreshold
* \brief        Apply independent thresholds to each colour channel
 independently and combine according to the settings encoded in
 combineMode. Each channel can have one of two modes: WLZ_BO_AND
 and WLZ_BO_OR. These are encoded into a single mode variable using
 the RGBA macro, e.g.:
 WLZ_RGBA_RGBA_SET(combineMode, redMode, greenMode, blueMode, 255);

 The macro WLZ_RGBA_RED_GET(combineMode) will return redMode and
 similarly for green and blue.
*
* \return       Thresholded object
* \param    obj	Object to be thresholded
* \param    lowVal	RGB low values
* \param    highVal	RGB high values
* \param    combineMode	Combination rules as an RGBA encoded unsigned integer
* \param    dstErr	Error return
* \par      Source:
*                WlzRGBAThreshold.c
*/
WlzObject *WlzRGBAMultiThreshold(
  WlzObject	*obj,
  WlzPixelV	lowVal,
  WlzPixelV	highVal,
  WlzUInt	combineMode,
  WlzErrorNum	*dstErr)
{
  WlzErrorNum	errNum=WLZ_ERR_NONE;
  WlzObject	*rtnObj=NULL;
  WlzObject	*obj1, *obj2;
  WlzValues	values;
  WlzCompoundArray	*cobj=NULL;
  int		low[3], high[3];
  WlzUInt	mode[3]; 

  /* check inputs */
  if( obj == NULL ){
    errNum = WLZ_ERR_OBJECT_NULL;
  }
  else {
    /* must be grey-type RGBA or compound with at least three channels */
    switch( obj->type ){
    case WLZ_2D_DOMAINOBJ:
    case WLZ_3D_DOMAINOBJ:
      if( obj->values.core == NULL ){
	errNum = WLZ_ERR_VALUES_NULL;
      }
      else {
	/* create compound object */
	if((cobj = WlzRGBAToCompound(obj, WLZ_RGBA_SPACE_RGB,
	                             &errNum)) != NULL){
	  cobj = (WlzCompoundArray *) WlzAssignObject((WlzObject *) cobj,
						      &errNum);
	}
      }
      break;

    case WLZ_TRANS_OBJ:
      if((obj1 = WlzRGBAMultiThreshold(obj->values.obj, lowVal, highVal,
				       combineMode, &errNum)) != NULL){
	values.obj = WlzAssignObject(obj1, NULL);
	rtnObj = WlzMakeMain(obj->type, obj->domain, values,
			     NULL, obj, &errNum);
      }
      break;

    case WLZ_COMPOUND_ARR_1:
    case WLZ_COMPOUND_ARR_2:
      cobj = (WlzCompoundArray *) WlzAssignObject(obj, &errNum);
      if( cobj->n < 3 ){
	errNum = WLZ_ERR_OBJECT_DATA;
	WlzFreeObj((WlzObject *) cobj);
      }
      else if((cobj->o[0]->values.core == NULL) ||
	      (cobj->o[1]->values.core == NULL) ||
	      (cobj->o[2]->values.core == NULL)){
	errNum = WLZ_ERR_VALUES_NULL;
      }
      break;

    case WLZ_EMPTY_OBJ:
      rtnObj = WlzMakeEmpty(&errNum);
      break;

    default:
      errNum = WLZ_ERR_OBJECT_TYPE;
      break;
    }
  }

  if((errNum == WLZ_ERR_NONE) && (rtnObj == NULL)){
    if((lowVal.type != WLZ_GREY_RGBA) ||
       (highVal.type != WLZ_GREY_RGBA)){
      errNum = WLZ_ERR_PARAM_TYPE;
    }
    else {
      low[0] = WLZ_RGBA_RED_GET(lowVal.v.rgbv);
      low[1] = WLZ_RGBA_GREEN_GET(lowVal.v.rgbv);
      low[2] = WLZ_RGBA_BLUE_GET(lowVal.v.rgbv);
      high[0] = WLZ_RGBA_RED_GET(highVal.v.rgbv);
      high[1] = WLZ_RGBA_GREEN_GET(highVal.v.rgbv);
      high[2] = WLZ_RGBA_BLUE_GET(highVal.v.rgbv);
    }
  }

  if((errNum == WLZ_ERR_NONE) && (rtnObj == NULL)){
    mode[0] = WLZ_RGBA_RED_GET(combineMode);
    mode[1] = WLZ_RGBA_GREEN_GET(combineMode);
    mode[2] = WLZ_RGBA_BLUE_GET(combineMode);
  }

  /* get thresholded channels */
  if((errNum == WLZ_ERR_NONE) &&
     (cobj != NULL) && (rtnObj == NULL)){
    WlzObject	*objs[3];
    int		i;
    WlzPixelV	threshV;

    for(i=0; i < 3; i++){
      threshV.type = WLZ_GREY_INT;
      threshV.v.inv = low[i];
      if((obj1 = WlzThreshold(cobj->o[i], threshV, WLZ_THRESH_HIGH,
      			      &errNum)) != NULL){
	obj1 = WlzAssignObject(obj1, &errNum);
	threshV.v.inv = high[i] + 1;
	if((obj2 = WlzThreshold(obj1, threshV, WLZ_THRESH_LOW,
	                        &errNum)) != NULL){
	  objs[i] = WlzAssignObject(obj2, &errNum);
	}
	else {
	  objs[i] = NULL;
	}
	WlzFreeObj(obj1);
      }
      else {
	objs[i] = NULL;
      }
    }

    /* combine according to mode
       what to do here? AND against a channel implies that the threshold
       constraint must be satisfied, OR implies it may be satisfied so
       all AND implies intersection, all OR implies union. Otherwise union
       of ORs and intersect with the ANDs. What about XOR? */
    /* find union of all then intersect with ANDs */
    obj1 = WlzAssignObject(WlzMakeEmpty(&errNum), NULL);
    for(i=0; (i < 3) && (errNum == WLZ_ERR_NONE); i++){
      if( objs[i] ){
	obj2 = WlzUnion2(obj1, objs[i], &errNum);
	WlzFreeObj(obj1);
	obj1 = WlzAssignObject(obj2, &errNum);
      }
    }
    for(i=0; i < 3; i++){
      if( objs[i] ){
	if( (mode[i] == WLZ_BO_AND) && (errNum == WLZ_ERR_NONE) ){
	  obj2 = WlzIntersect2(obj1, objs[i], &errNum);
	  WlzFreeObj(obj1);
	  obj1 = WlzAssignObject(obj2, &errNum);
	}
	WlzFreeObj(objs[i]);
      }
    }

    /* create the return object and add grey-table if possible */
    if( obj1 ){
      if( WlzIsEmpty(obj1, &errNum) ){
	rtnObj = WlzMakeMain(obj1->type, obj1->domain, obj1->values,
			     NULL, NULL, &errNum);
      }
      else {
	if( obj1->type == obj->type ){
	  rtnObj = WlzMakeMain(obj1->type, obj1->domain, obj->values,
			       NULL, NULL, &errNum);
	}
	else {
	  rtnObj = WlzMakeMain(obj1->type, obj1->domain, obj1->values,
			       NULL, NULL, &errNum);
	}
      }
      WlzFreeObj(obj1);
    }
  }

  if( cobj ){
    WlzFreeObj((WlzObject *) cobj);
  }

  /* check error and return */
  if( dstErr ){
    *dstErr = errNum;
  }
  return rtnObj;
}
コード例 #20
0
ファイル: WlzDistanceMetric.c プロジェクト: dscho/Woolz
int             main(int argc, char **argv)
{
  int		idx,
		hFlag = 0,
		mFlag = 0,
		nFlag = 0,
		iFlag = 0,
		option,
		ok = 1,
		usage = 0;
  double	hDist,
  		mDist,
		nDist,
		iDist;
  char		hStr[64],
  		mStr[64],
		nStr[64],
		iStr[64];
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  WlzObject	*inObj[2];
  FILE		*fP = NULL;
  char 		*outFileStr;
  char  	*inObjFileStr[2];
  const char	*errMsg;
  static char	optList[] = "ho:HMNI",
		fileStrDef[] = "-";

  opterr = 0;
  inObj[0] = NULL;
  inObj[1] = NULL;
  inObjFileStr[0] = inObjFileStr[1] = outFileStr = fileStrDef;
  while(ok && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'o':
        outFileStr = optarg;
	break;
      case 'H':
        hFlag = 1;
	break;
      case 'M':
        mFlag = 1;
	break;
      case 'N':
        nFlag = 1;
	break;
      case 'I':
        iFlag = 1;
	break;
      case 'h':
      default:
        usage = 1;
	ok = 0;
	break;
    }
  }
  if((inObjFileStr[0] == NULL) || (*inObjFileStr[0] == '\0') ||
     (inObjFileStr[1] == NULL) || (*inObjFileStr[1] == '\0') ||
     (outFileStr == NULL) || (*outFileStr == '\0'))
  {
    ok = 0;
    usage = 1;
  }
  if(ok && (optind < argc))
  {
    idx = 0;
    while((idx < 2) && (optind < argc))
    {
      inObjFileStr[idx] = *(argv + optind);
      ++optind;
      ++idx;
    }
  }
  if(ok && (optind != argc))
  {
    usage = 1;
    ok = 0;
  }
  if(ok)
  {
    /* Set default to all metrics if none have been specified. */
    if((hFlag == 0) && (mFlag == 0) && (nFlag == 0) && (iFlag == 0))
    {
      hFlag = mFlag = nFlag = iFlag = 1;
    }
    /* Read objects. */
    idx = 0;
    while((errNum == WLZ_ERR_NONE) && (idx < 2))
    {
      errNum = WLZ_ERR_READ_EOF;
      if((inObjFileStr[idx] == NULL) ||
	  (*inObjFileStr[idx] == '\0') ||
	  ((fP = (strcmp(inObjFileStr[idx], "-")?
		  fopen(inObjFileStr[idx], "r"): stdin)) == NULL) ||
	  ((inObj[idx] = WlzAssignObject(WlzReadObj(fP,
	  					    &errNum), NULL)) == NULL))
      {
	ok = 0;
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: Failed to read object %d from file %s (%s)\n",
		       *argv, idx, inObjFileStr[idx], errMsg);
      }
      if(fP && strcmp(inObjFileStr[idx], "-"))
      {
	fclose(fP);
      }
      ++idx;
    }
  }
  if(ok)
  {
    /* Check object types. */
    if(inObj[0]->type != inObj[1]->type)
    {
      errNum = WLZ_ERR_OBJECT_TYPE;
    }
    else if((inObj[0]->domain.core == NULL) ||
            (inObj[1]->domain.core == NULL))
    {
      errNum = WLZ_ERR_DOMAIN_NULL;
    }
    else
    {
      switch(inObj[0]->type)
      {
        case WLZ_CONTOUR:
          if((inObj[0]->domain.core == NULL) ||
             (inObj[0]->domain.core == NULL) ||
             (inObj[0]->domain.ctr->model == NULL) ||
             (inObj[1]->domain.ctr->model == NULL))
          {
            errNum = WLZ_ERR_DOMAIN_NULL;
          }
          else
          {
	    errNum = WlzDistMetricGM(inObj[0]->domain.ctr->model,
	    			     inObj[1]->domain.ctr->model,
				     (hFlag)? &hDist: NULL,
				     (mFlag)? &mDist: NULL,
				     (nFlag)? &nDist: NULL,
				     (iFlag)? &iDist: NULL);
          }
          break;
        default:
          errNum = WLZ_ERR_OBJECT_TYPE;
          ok = 0;
          break;
      }
    }
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr, "%s: Failed to compute distance metric (%s).\n",
		     *argv, errMsg);
    }
  }
  if(ok)
  {
    if(((fP = (strcmp(outFileStr, "-")?
              fopen(outFileStr, "w"): stdout)) == NULL))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: Failed open output file (%s).\n",
		     *argv, errMsg);
    }
    else
    {
      hStr[0] = mStr[0] = nStr[0] = iStr[0] = '\0';
      if(hFlag)
      {
        (void )sprintf(hStr, " %g", hDist);
      }
      if(mFlag)
      {
        (void )sprintf(mStr, " %g", mDist);
      }
      if(nFlag)
      {
        (void )sprintf(nStr, " %g", nDist);
      }
      if(iFlag)
      {
        (void )sprintf(iStr, " %g", iDist);
      }
      (void )fprintf(fP, "%s%s%s%s\n", hStr, mStr, nStr, iStr);
    }
    if(fP && strcmp(outFileStr, "-"))
    {
      fclose(fP);
    }
  }
  (void )WlzFreeObj(inObj[0]);
  (void )WlzFreeObj(inObj[1]);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%sExample: %s%s",
    *argv,
    " [-h] [-o <output file>] [-H] [-M] [-N] [-I]\n"
    "                         [<in obj 0>] [<in obj 1>]\n"
    "Options:\n"
    "  -h  Help, prints this usage message.\n"
    "  -o  Output file for distance metrics.\n"
    "  -H  Hausdorff distance metric.\n"
    "  -M  Mean of nearest neighbours distance metrics.\n"
    "  -N  Median of nearest neighbours distance metrics.\n"
    "  -I  Minimum nearest neighbour distance.\n"
    "Computes distance metrics for the given pair of objects.\n"
    "If no distance metrics are specified on the command line then all\n"
    "the metrics will be be computed and output, but if any metrics are\n"
    "specified on the computed line then only those metrics will be\n"
    "computed and output.\n"
    "The selected distance metrics are written on a single line as,\n"
    "ascii floating point values, separated by white spaces characters\n"
    "and in the order: Hausdorff; mean; median and minimum distance.\n"
    "The input objects are read from stdin and the distances are written\n"
    "to stdout unless the filenames are given.\n",
    *argv,
    " -H -N -o out.num in0.wlz in1.wlz\n"
    "Two objects are read from in0.wlz and in1.wlz, the Hausdorff and\n"
    "median of nearest neighbours distance metrics are computed and\n"
    "written to the file out.num on a single line in that order.\n");
  }
  return(!ok);
}
コード例 #21
0
int		main(int argc, char *argv[])
{
  int		ok,
		binFlg = 0,
  		nAng = 360,
		maxRFlg = 0,
  		option,
		usage = 0;
  double	cen = 0.0,
  		maxR = 0.0;
  char		*fFileStr,
  		*rFileStr,
		*oFileStr;
  FILE		*fP = NULL;
  WlzObject	*fObj = NULL,
		*rObj = NULL;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const char	*errMsgStr;
  static char	optList[] = "bhn:o:R";
  const char    fileStrDef[] = "-";

  /* Parse the argument list and check for input files. */
  opterr = 0;
  fFileStr = (char *)fileStrDef;
  rFileStr = (char *)fileStrDef;
  oFileStr = (char *)fileStrDef;
  while((option = getopt(argc, argv, optList)) != EOF)
  {
    switch(option)
    {
      case 'b':
        binFlg = 1;
	break;
      case 'n':
	if((sscanf(optarg, "%d", &nAng) != 1) || (nAng <= 0))
	{
	  usage = 1;
	}
	break;
      case 'o':
	oFileStr = optarg;
	break;
      case 'R':
        maxRFlg = 1;
	break;
      case 'h':
      default:
	usage = 1;
	break;
    }
  }
  ok = !usage;
  if(ok && (optind < argc))
  {
    if((optind + 1) == argc)
    {
      fFileStr = argv[optind];
    }
    else if((optind + 2) == argc)
    {
      fFileStr = argv[optind];
      rFileStr = argv[optind + 1];
    }
    else
    {
      usage = 1;
    }
  }
  ok = !usage;
  /* Read the feature object. */
  if(ok)
  {
    if((fFileStr == NULL) ||
       (*fFileStr == '\0') ||
       ((fP = (strcmp(fFileStr, "-")?
              fopen(fFileStr, "r"): stdin)) == NULL) ||
       ((fObj = WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL))
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Failed to read feature object from file %s.\n",
                     argv[0], fFileStr);
    }
    if(fP && strcmp(fFileStr, "-"))
    {
      (void )fclose(fP); fP = NULL;
    }
  }
  /* Read the reference object. */
  if(ok)
  {
    if((rFileStr == NULL) ||
       (*rFileStr == '\0') ||
       ((fP = (strcmp(rFileStr, "-")?
              fopen(rFileStr, "r"): stdin)) == NULL) ||
       ((rObj = WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL))
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Failed to read reference object from file %s.\n",
                     argv[0], rFileStr);
    }
    if(fP && strcmp(rFileStr, "-"))
    {
      (void )fclose(fP); fP = NULL;
    }
  }
  /* Check object types and parse the promote the default distance function
   * if required. */
  if(ok)
  {
    if(rObj->type != fObj->type)
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Feature and reference object types differ.\n",
		     argv[0]);
    }
  }
  /* Compute centrality feature. */
  if(ok)
  {
    cen = WlzCentrality(fObj, rObj, nAng, binFlg, &maxR, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsgStr);
      (void )fprintf(stderr,
                     "%s: Failed to compute centrality feature value (%s).\n",
                     argv[0], errMsgStr);
    }
  }
  /* Output the centrality feature value. */
  if(ok)
  {
    if((fP = (strcmp(oFileStr, "-")?
             fopen(oFileStr, "w"): stdout)) == NULL)
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Failed to open output file %s.\n",
                     argv[0], oFileStr);
    }
  }
  if(ok)
  {
    if(((maxRFlg == 0) && (fprintf(fP, "%lg\n", cen) <= 0)) ||
       ((maxRFlg != 0) && (fprintf(fP, "%lg %lg\n", cen, maxR) <= 0)))
    {
      ok = 0;
      errNum = WLZ_ERR_WRITE_INCOMPLETE;
      (void )WlzStringFromErrorNum(errNum, &errMsgStr);
      (void )fprintf(stderr,
                     "%s: Failed to write output feature value (%s).\n",
                     argv[0], errMsgStr);
    }
  }
  (void )WlzFreeObj(fObj);
  (void )WlzFreeObj(rObj);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s [-b] [-h] [-n#] [-o <output file>] [-R]\n"
    "                        [<feat obj>] [<ref obj>]\n"
    "Version: %s\n"
    "Computes the centrality of the feature object's domain with respect to\n"
    "the reference object's domain.\n"
    "\n"
    "Options are:\n"
    "  -b  Treat the feature object as a binary object with constant values.\n"
    "  -h  Help - prints this usage message\n"
    "  -n  Number of angle increments to use (default 360).\n"
    "  -o  Output file for centrality feature value.\n"
    "  -R  Output maximum radius value after centrality value.\n"
    "By default the feature and reference objects are read from the standard\n"
    "input. This may be made explicit if only one of these is given by using\n"
    "- to specify the standard input.\n",
    argv[0],
    WlzVersion());
  }
  return(!ok);
}
コード例 #22
0
ファイル: WlzTensor.c プロジェクト: dscho/Woolz
/*!
* \return	Compound array.
* \ingroup	WlzTransform
* \brief	Computes a compound array of three objects, the objects 
                representing the t11, t12 qnd t22 componemts of a tensor.
* \param	inobj			Given object.
* \param        basisTensorTr           Basis Function tensor transform
* \param	dstErr			Destination error pointer, may be
*					NULL.
*/
static WlzCompoundArray *WlzBasisFnTensorTransformObjPrv(WlzObject *inObj, 
					 WlzBasisFnTransform *basisTr, 
					 WlzErrorNum *dstErr)
{
  WlzObject 		*objT11 = NULL,
                        *objT12 = NULL,
                        *objT22 = NULL;
  WlzCompoundArray	*cArray = NULL;
  WlzValues		valuesT11,
                        valuesT12,
                        valuesT22;
  WlzIntervalWSpace     iWsp,
                        iWspT11,
                        iWspT12,
                        iWspT22;
  WlzGreyWSpace	        gWspT11,
                        gWspT12,
                        gWspT22;
  WlzDVertex2           sVtx;
  WlzErrorNum		errNum=WLZ_ERR_NONE;
  WlzObjectType           vType;
  WlzGreyP	        gPixT11,
                        gPixT12,
                        gPixT22;
  WlzPixelV 		backgrnd;
  WlzFnType             basisFnType;
  double                t11Partial,
                        t12APartial,
                        t12BPartial,
                        t22Partial;
  int 		        k,
                        l;
 
  valuesT11.core = NULL;
  valuesT12.core = NULL;  
  valuesT22.core = NULL;
  basisFnType = basisTr->basisFn->type;
  /* Create value tables for the two objects */
  vType = WlzGreyTableType(WLZ_GREY_TAB_RAGR, WLZ_GREY_FLOAT, NULL);
  backgrnd.type = WLZ_GREY_FLOAT;
  backgrnd.v.inv = 0;
  if((valuesT11.v = WlzNewValueTb(inObj, vType, backgrnd, &errNum)) != NULL)
  {
    if((valuesT12.v = WlzNewValueTb(inObj, vType, backgrnd, &errNum)) != NULL)
    {
      valuesT22.v = WlzNewValueTb(inObj, vType, backgrnd, &errNum);
    }
    else
    {
      WlzFreeValueTb(valuesT11.v);
      WlzFreeValueTb(valuesT12.v);
    }
  }
  else
  {
    WlzFreeValueTb(valuesT11.v);
  }
  /* create three Wlz objects to hold t11, t22 and t12 tensor components */
  if (errNum == WLZ_ERR_NONE)
  {
    if ((objT11 = WlzMakeMain(inObj->type, inObj->domain, valuesT11, NULL, 
			      NULL, &errNum)) != NULL) 
    {
      if ((objT12 = WlzMakeMain(inObj->type, inObj->domain, valuesT12, NULL, 
			        NULL, &errNum)) != NULL) 
      {
	if ((objT22 = WlzMakeMain(inObj->type, inObj->domain, valuesT22, 
				   NULL, NULL, &errNum)) == NULL)
	{
	  WlzFreeObj(objT11);
	  objT11 = NULL;
	  WlzFreeObj(objT12);
	  objT12 = NULL;
	}
      }
      else
      {
	WlzFreeObj(objT11);
	objT11 = NULL;
      }
    }
  }
  /* initialise workspaces */
  if (errNum == WLZ_ERR_NONE)
  {
    if ((errNum = WlzInitRasterScan(inObj, &iWsp, WLZ_RASTERDIR_ILIC)) == 
	WLZ_ERR_NONE)
    {
      if ((errNum = WlzInitGreyScan(objT11, &iWspT11, &gWspT11)) == 
	  WLZ_ERR_NONE)
      {
	if ((errNum = WlzInitGreyScan(objT12, &iWspT12, &gWspT12)) == 
	  WLZ_ERR_NONE)
	{
	  errNum = WlzInitGreyScan(objT22, &iWspT22, &gWspT22);
	}
      }
    }
  }
  /* Calculate tensor components for MQ2 only */
  if (errNum == WLZ_ERR_NONE)
  {
    switch (basisFnType)
    {
      case WLZ_FN_BASIS_2DMQ:
	while(((errNum = WlzNextInterval(&iWsp)) == WLZ_ERR_NONE) &&
	      ((errNum = WlzNextGreyInterval(&iWspT11)) == WLZ_ERR_NONE) &&
	      ((errNum = WlzNextGreyInterval(&iWspT12)) == WLZ_ERR_NONE) &&
	      ((errNum = WlzNextGreyInterval(&iWspT22)) == WLZ_ERR_NONE))
	{
	  gPixT11 = gWspT11.u_grintptr;
	  gPixT12 = gWspT12.u_grintptr;
	  gPixT22 = gWspT22.u_grintptr;
	  l = iWsp.linpos;
	  for (k = iWsp.lftpos; k <= iWsp.rgtpos; k++)
	  {
	    sVtx.vtX = k;
	    sVtx.vtY = l;
	    t11Partial = WlzBasisFnValueMQ2DPrv(basisTr->basisFn, sVtx, 0);
	    *(gPixT11.flp) = (float)t11Partial;
	    ++(gPixT11.flp);
	    t22Partial = WlzBasisFnValueMQ2DPrv(basisTr->basisFn, sVtx, 1);
	    *(gPixT22.flp) = (float)t22Partial;
	    ++(gPixT22.flp);
	    t12APartial = WlzBasisFnValueMQ2DPrv(basisTr->basisFn, sVtx, 2);
	    t12BPartial = WlzBasisFnValueMQ2DPrv(basisTr->basisFn, sVtx, 3);
	    *(gPixT12.flp) = 0.5 * ((float)t12APartial + (float)t12BPartial);
	    ++(gPixT12.flp);
	  }
	}
        if(errNum == WLZ_ERR_EOO)        
	{
	  errNum = WLZ_ERR_NONE;
	}
	break;
      case WLZ_FN_BASIS_2DTPS:
	while(((errNum = WlzNextInterval(&iWsp)) == WLZ_ERR_NONE) &&
	      ((errNum = WlzNextGreyInterval(&iWspT11)) == WLZ_ERR_NONE) &&
	      ((errNum = WlzNextGreyInterval(&iWspT12)) == WLZ_ERR_NONE) &&
	      ((errNum = WlzNextGreyInterval(&iWspT22)) == WLZ_ERR_NONE))
	{
	  gPixT11 = gWspT11.u_grintptr;
	  gPixT12 = gWspT12.u_grintptr;
	  gPixT22 = gWspT22.u_grintptr;
	  l = iWsp.linpos;
	  for (k = iWsp.lftpos; k <= iWsp.rgtpos; k++)
	  {
	    sVtx.vtX = k;
	    sVtx.vtY = l;
	    t11Partial = WlzBasisFnValueTPS2DPrv(basisTr->basisFn, sVtx, 0);
	    *(gPixT11.flp) = (float)t11Partial;
	    ++(gPixT11.flp);
	    t22Partial = WlzBasisFnValueTPS2DPrv(basisTr->basisFn, sVtx, 1);
	    *(gPixT22.flp) = (float)t22Partial;
	    ++(gPixT22.flp);
	    t12APartial = WlzBasisFnValueTPS2DPrv(basisTr->basisFn, sVtx, 2);
	    t12BPartial = WlzBasisFnValueTPS2DPrv(basisTr->basisFn, sVtx, 3);
	    *(gPixT12.flp) = 0.5 * ((float)t12APartial + (float)t12BPartial);
	    ++(gPixT12.flp);
	  }
	}
        if(errNum == WLZ_ERR_EOO)        
	{
	  errNum = WLZ_ERR_NONE;
	}
	break;
      default:
        errNum = WLZ_ERR_TRANSFORM_TYPE;
      break;
    }
  }
  /* create compound object */
  if (errNum == WLZ_ERR_NONE)
  {
    cArray = WlzMakeCompoundArray(WLZ_COMPOUND_ARR_1, 1, 3, NULL, 
				  objT11->type, &errNum);
    if (errNum == WLZ_ERR_NONE) 
    {
      cArray->o[0] = WlzAssignObject(objT11, NULL);
      cArray->o[1] = WlzAssignObject(objT22, NULL);
      cArray->o[2] = WlzAssignObject(objT12, NULL);
    }
  }

  if(dstErr)
  {
    *dstErr = errNum;
  }
  return(cArray);
}
コード例 #23
0
ファイル: WlzGreyMask.c プロジェクト: dscho/Woolz
static WlzObject *WlzGreyMask3d(
  WlzObject	*obj,
  WlzObject	*mask,
  WlzPixelV	maskVal,
  WlzErrorNum	*dstErr)
{
  WlzObject	*rtnObj=NULL;
  WlzObject	*tmpMask, *obj1, *obj2;
  WlzDomain	*domains;
  WlzValues	values, *valuess, *newvaluess;
  WlzPlaneDomain	*pdom;
  int		p;
  WlzErrorNum	errNum=WLZ_ERR_NONE;

  /* check the object - it is non-NULL and 3D but the
     domain needs checking */
  if( obj->domain.p == NULL ){
    errNum = WLZ_ERR_DOMAIN_NULL;
  }
  else {
    switch( obj->domain.p->type ){
    case WLZ_2D_DOMAINOBJ:
      /* check there is a valuetable */
      if( obj->values.core == NULL ){
	errNum = WLZ_ERR_VALUES_NULL;
      }
      break;

    case WLZ_EMPTY_DOMAIN:
      return WlzMakeEmpty(dstErr);

    default:
      errNum = WLZ_ERR_DOMAIN_TYPE;
      break;
    }
  }

  /* check the mask */
  if( errNum == WLZ_ERR_NONE ){
    if( mask == NULL ){
      errNum = WLZ_ERR_OBJECT_NULL;
    }
    else {
      /* set some local variables */
      pdom = obj->domain.p;
      domains = obj->domain.p->domains;
      valuess = obj->values.vox->values;

      /* create a new voxel object, initially no values */
      values.vox = WlzMakeVoxelValueTb(obj->values.vox->type,
				       obj->values.vox->plane1,
				       obj->values.vox->lastpl,
				       obj->values.vox->bckgrnd,
				       obj, NULL);
      rtnObj = WlzMakeMain(WLZ_3D_DOMAINOBJ, obj->domain, values,
			   NULL, NULL, NULL);
      newvaluess = rtnObj->values.vox->values;

      /* switch on mask type - a 2D mask is applied to each plane */
      switch( mask->type ){
      case WLZ_2D_DOMAINOBJ:
      case WLZ_2D_POLYGON:
      case WLZ_BOUNDLIST:
      case WLZ_EMPTY_OBJ:
	for(p=pdom->plane1; p <= pdom->lastpl; p++, domains++, valuess++){
	  if( (*domains).core ){
	    obj1 = WlzAssignObject(
	      WlzMakeMain(WLZ_2D_DOMAINOBJ, *domains, *valuess,
			  NULL, NULL, NULL), NULL);
	    if((obj2 = WlzGreyMask(obj1, mask, maskVal, &errNum)) != NULL){
	      newvaluess[p - pdom->plane1] =
		WlzAssignValues(obj->values, NULL);
	      WlzFreeObj(obj2);
	    }
	    WlzFreeObj(obj1);
	  }
	}
	break;

      case WLZ_3D_DOMAINOBJ:
	/* switch on plane domain type - polygon and boundlist
	   are legal but need transforming first. */
	switch( obj->domain.p->type ){
	  WlzDomain	*maskDoms;

	case WLZ_PLANEDOMAIN_DOMAIN:
	  maskDoms = mask->domain.p->domains;
	  for(p=pdom->plane1; p <= pdom->lastpl; p++, domains++, valuess++){
	    if(((*domains).core)){
	      if((p >= mask->domain.p->plane1) &&
		 (p <= mask->domain.p->lastpl) &&
		 (maskDoms[p - mask->domain.p->plane1].core) ){
		values.core = NULL;
		tmpMask = WlzMakeMain(WLZ_2D_DOMAINOBJ,
				      maskDoms[p - mask->domain.p->plane1],
				      values, NULL, NULL, NULL);
	      }
	      else {
		tmpMask = WlzMakeEmpty(NULL);
	      }

	      obj1 = WlzAssignObject(
		WlzMakeMain(WLZ_2D_DOMAINOBJ, *domains, *valuess,
			    NULL, NULL, NULL), NULL);
	      if((obj2 = WlzGreyMask(obj1, tmpMask, maskVal,
	      			     &errNum)) != NULL){
		newvaluess[p - pdom->plane1] =
		  WlzAssignValues(obj2->values, NULL);
		WlzFreeObj(obj2);
	      }
	      WlzFreeObj(obj1);
	      WlzFreeObj(tmpMask);
	    }
	  }
	  break;

	case WLZ_PLANEDOMAIN_POLYGON:
	  maskDoms = mask->domain.p->domains;
	  for(p=pdom->plane1; p <= pdom->lastpl; p++, domains++, valuess++){
	    if(((*domains).core)){
	      if((p >= mask->domain.p->plane1) &&
		 (p <= mask->domain.p->lastpl) &&
		 (maskDoms[p - mask->domain.p->plane1].core) ){
		values.core = NULL;
		tmpMask = WlzMakeMain(WLZ_2D_POLYGON,
				      maskDoms[p - mask->domain.p->plane1],
				      values, NULL, NULL, NULL);
	      }
	      else {
		tmpMask = WlzMakeEmpty(NULL);
	      }

	      obj1 = WlzAssignObject(
		WlzMakeMain(WLZ_2D_DOMAINOBJ, *domains, *valuess,
			    NULL, NULL, NULL), NULL);
	      if((obj2 = WlzGreyMask(obj1, tmpMask, maskVal,
	                             &errNum)) != NULL){
		newvaluess[p - pdom->plane1] =
		  WlzAssignValues(obj2->values, NULL);
		WlzFreeObj(obj2);
	      }
	      WlzFreeObj(obj1);
	      WlzFreeObj(tmpMask);
	    }
	  }
	  break;

	case WLZ_PLANEDOMAIN_BOUNDLIST:
	  maskDoms = mask->domain.p->domains;
	  for(p=pdom->plane1; p <= pdom->lastpl; p++, domains++, valuess++){
	    if(((*domains).core)){
	      if((p >= mask->domain.p->plane1) &&
		 (p <= mask->domain.p->lastpl) &&
		 (maskDoms[p - mask->domain.p->plane1].core) ){
		values.core = NULL;
		tmpMask = WlzMakeMain(WLZ_BOUNDLIST,
				      maskDoms[p - mask->domain.p->plane1],
				      values, NULL, NULL, NULL);
	      }
	      else {
		tmpMask = WlzMakeEmpty(NULL);
	      }

	      obj1 = WlzAssignObject(
		WlzMakeMain(WLZ_2D_DOMAINOBJ, *domains, *valuess,
			    NULL, NULL, NULL), NULL);
	      if((obj2 = WlzGreyMask(obj1, tmpMask, maskVal,
	                             &errNum)) != NULL){
		newvaluess[p - pdom->plane1] =
		  WlzAssignValues(obj2->values, NULL);
		WlzFreeObj(obj2);
	      }
	      WlzFreeObj(obj1);
	      WlzFreeObj(tmpMask);
	    }
	  }
	  break;

	default:
	  errNum = WLZ_ERR_DOMAIN_TYPE;
	  WlzFreeObj(rtnObj);
	  rtnObj = NULL;
	  break;
	}
	break;

      default:
	errNum = WLZ_ERR_OBJECT_NULL;
	WlzFreeObj(rtnObj);
	rtnObj = NULL;
	break;
      }
    }
  }


  if( dstErr ){
    *dstErr = errNum;
  }
  return rtnObj;
}
コード例 #24
0
ファイル: WlzTensor.c プロジェクト: dscho/Woolz
int             main(int argc, char **argv)
{
  int		nTiePP,
		option,
		vxCount = 0,
		vxLimit = 0,
		basisFnPolyOrder = 3,
                index,
                relFlag,
                meshMinDist,
                meshMaxDist;
  char 		*srcFileStr,
		*bibFileStr = NULL,
                *outFileStr,
                *bibErrMsg;
  const char    *errMsg;
  FILE		*inFile = NULL,
                *outFile = NULL;
  WlzDVertex2   *sVtx2 = NULL,
                *dVtx2 = NULL,
                *srcVtx2 = NULL,
                *dstVtx2 = NULL;
  WlzDVertex3   *dVtx = NULL, 
                *sVtx = NULL,
                *srcVtx = NULL,   
                *dstVtx = NULL;
  WlzObject	*inObj = NULL;
  WlzCompoundArray  *outObj = NULL;              
  WlzBasisFnTransform  *basisTr;
  WlzTransformType     trType;
  WlzFnType basisFnType;
  WlzMeshGenMethod genMethod;
  WlzErrorNum	errNum = WLZ_ERR_NONE; 
  BibFileRecord	       *bibfileRecord;
  BibFileError         bibFileErr;
  
  /* read the argument list and check for an input file */

  static char	       optList[] = "s:b:t:h";
 
   while( (option = getopt(argc, argv, optList)) != EOF )
   {
      switch( option )
      {
        case 'h':
             usage(argv[0]);
	     return(0);
        case 'b':
	    bibFileStr = optarg;
	    break;
        case 's':
	    srcFileStr = optarg;
	    break;
        case 't':
	    outFileStr = optarg;
	    break;
        default:
              return(0);
      }
   }
   if((inFile = fopen(bibFileStr, "r")) == NULL )
   {
       printf("cannot open the input bib file.\n");
       exit(1);
   }
   /* read the bibfile until we get the WlzWarptransformParams part */

   while( !feof(inFile) ){
      bibFileErr = BibFileRecordRead(&bibfileRecord, &bibErrMsg, inFile);
      if(bibFileErr != BIBFILE_ER_EOF)
      {
	bibFileErr = WlzEffBibParseWarpTransformParamsRecord(
						bibfileRecord,
						&basisFnType,
						&trType,
						&genMethod,
						&meshMinDist,
						&meshMaxDist);
	 if (bibFileErr == BIBFILE_ER_NONE)
	   break;
      }
      else
	break;
   }

   /* read the bibfile until we get the TiePointVtxs part */
   if(  bibFileErr == BIBFILE_ER_NONE )
   {
     while( !feof(inFile) ){
       bibFileErr = BibFileRecordRead(&bibfileRecord, &bibErrMsg, inFile);
       if(bibFileErr != BIBFILE_ER_EOF)
       {
	    if(vxCount >= vxLimit)
	    {
	      vxLimit = (vxLimit + 1024) * 2;
	      if(((srcVtx = (WlzDVertex3 *)AlcRealloc(srcVtx,
			     vxLimit * sizeof(WlzDVertex3))) == NULL) ||
		 ((dstVtx = (WlzDVertex3 *)AlcRealloc(dstVtx,
			     vxLimit * sizeof(WlzDVertex3))) == NULL))
	      {
		errNum = WLZ_ERR_MEM_ALLOC;
	      }
	      else
	      {
		sVtx = srcVtx + vxCount;
		dVtx = dstVtx + vxCount;
	      }
	    }
	    if(errNum == WLZ_ERR_NONE)
	    {
	      bibFileErr = WlzEffBibParseTiePointVtxsRecord(
						bibfileRecord,
						&index,
						dVtx,
						sVtx,
						&relFlag);
	      if (bibFileErr == BIBFILE_ER_NONE)
	      {	      
		++sVtx;
		++dVtx;
		++vxCount;
	      }
	    }
      }
      else
	break;
     }
   }

   nTiePP = vxCount;

   BibFileRecordFree(&bibfileRecord);

   fclose(inFile);

   if(  bibFileErr == BIBFILE_ER_EOF )
   {
     errNum = WLZ_ERR_NONE;
   }
   else
   {
     printf("Read bib file error.\n");
     exit(1);
   }

   /* copy 3D verices to 2D vertices - cast won't work */
   if(((srcVtx2 = (WlzDVertex2 *)AlcRealloc(srcVtx2,
		  vxCount * sizeof(WlzDVertex2))) == NULL) ||
		  ((dstVtx2 = (WlzDVertex2 *)AlcRealloc(dstVtx2,
		  vxCount * sizeof(WlzDVertex2))) == NULL))
   {
     errNum = WLZ_ERR_MEM_ALLOC;
   }
   else
   {
     sVtx = srcVtx;
     dVtx = dstVtx;
     sVtx2 = srcVtx2;
     dVtx2 = dstVtx2;
     for (vxCount = 0; vxCount < nTiePP;  vxCount++)
     {
       sVtx2->vtX = sVtx->vtX;
       sVtx2->vtY = sVtx->vtY;
       dVtx2->vtX = dVtx->vtX;
       dVtx2->vtY = dVtx->vtY;
       ++sVtx2;
       ++dVtx2;
       ++sVtx;
       ++dVtx;
     }
   }

   errNum = WLZ_ERR_READ_EOF;
   if((srcFileStr == NULL) ||
	(*srcFileStr == '\0') ||
	((inFile = (strcmp(srcFileStr, "-")?
		fopen(srcFileStr, "r"): stdin)) == NULL) ||
       	((inObj= WlzAssignObject(WlzReadObj(inFile, &errNum), NULL)) == NULL) 
               || (errNum != WLZ_ERR_NONE))
   {
      (void )fprintf(stderr,
		     "%s: failed to read object from file %s\n",
		     *argv, srcFileStr);
   }
   if(inFile)
   {
      if(strcmp(srcFileStr, "-"))
      {
	fclose(inFile);
      }
      inFile = NULL;
   }
  if(errNum == WLZ_ERR_NONE)
  {
      basisTr = WlzAffineBasisFnTransformFromCPtsT(inObj, basisFnType, 
					    basisFnPolyOrder,
					    nTiePP, srcVtx2, nTiePP, dstVtx2, 
					    &errNum);
  }
  
  /* Calculate tensor components and then write them out. */
  if(errNum == WLZ_ERR_NONE)
  {
    outObj = WlzBasisFnTensorTransformObjPrv(inObj, basisTr, &errNum);
  }
  if(errNum != WLZ_ERR_NONE)
  {
    (void )WlzStringFromErrorNum(errNum, &errMsg);
    (void )fprintf(stderr,
    	       "%s: failed to transform object (%s).\n",
       	       *argv, errMsg);
  }
  if(errNum == WLZ_ERR_NONE)
  {
    errNum = WLZ_ERR_WRITE_EOF;
    if(((outFile = (strcmp(outFileStr, "-")?
		  fopen(outFileStr, "w"):
		  stdout)) == NULL) ||
	          ((errNum = WlzWriteObj(outFile, (WlzObject *)outObj)) 
		   != WLZ_ERR_NONE))
    {
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
			 "%s: failed to write output compound array (%s).\n",
			 *argv, errMsg);
    }
    if(outFile && strcmp(outFileStr, "-"))
    {
      fclose(outFile);
    }
  }

  /* free memory */
  AlcFree(srcVtx);
  AlcFree(dstVtx);
  AlcFree(srcVtx2);
  AlcFree(dstVtx2);
  WlzBasisFnFreeTransform(basisTr);
  return(errNum);
}
コード例 #25
0
ファイル: WlzGreyMask.c プロジェクト: VirtualFlyBrain/Woolz
int main(int	argc,
	 char	**argv)
{

  WlzObject	*obj, *mask, *newobj;
  FILE		*inFile = NULL;
  char 		optList[] = "m:h";
  int		option;
  WlzPixelV	maskVal;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const char	*errMsg;
    
  /* read the argument list and check for an input file */
  opterr = 0;
  maskVal.type = WLZ_GREY_FLOAT;
  maskVal.v.flv = 0.0;
  
  while( (option = getopt(argc, argv, optList)) != EOF ){
    switch( option ){
    case 'm':
      maskVal.v.flv = atof(optarg);
      break;
    case 'h':
    default:
      usage(argv[0]);
      return 1;
    }
  }

  /* check for read from file, note if one file is defined then
     it is the mask and the object should be on stdin */
  if( (argc - optind) >= 2 ){
    /* read the mask */
    if( (inFile = fopen(*(argv+optind), "r")) == NULL ){
      fprintf(stderr, "%s: can't open file %s\n", argv[0], *(argv+optind));
      usage(argv[0]);
      return 1;
    }
    if( (mask = WlzAssignObject(WlzReadObj(inFile, NULL), NULL)) == NULL ){
      fprintf(stderr, "%s: can't read mask from file %s\n", argv[0],
	      *(argv+optind));
      usage(argv[0]);
      return 1;
    }
    fclose( inFile );
    optind++;

    /* read the object */
    if( (inFile = fopen(*(argv+optind), "r")) == NULL ){
      fprintf(stderr, "%s: can't open file %s\n", argv[0], *(argv+optind));
      usage(argv[0]);
      return 1;
    }
    if( (obj = WlzAssignObject(WlzReadObj(inFile, NULL), NULL)) == NULL ){
      fprintf(stderr, "%s: can't read obj from file %s\n", argv[0],
	      *(argv+optind));

      usage(argv[0]);
      return 1;
    }
    fclose( inFile );
  }
  else if( (argc - optind) == 1 ){
    /* read the mask */
    if( (inFile = fopen(*(argv+optind), "r")) == NULL ){
      fprintf(stderr, "%s: can't open file %s\n", argv[0], *(argv+optind));
      usage(argv[0]);
      return 1;
    }
    if( (mask = WlzAssignObject(WlzReadObj(inFile, NULL), NULL)) == NULL ){
      fprintf(stderr, "%s: can't read mask from file %s\n", argv[0],
	      *(argv+optind));
      usage(argv[0]);
      return 1;
    }
    fclose( inFile );
    inFile = stdin;
    if( (obj = WlzAssignObject(WlzReadObj(inFile, NULL), NULL)) == NULL ){
      fprintf(stderr, "%s: can't read obj from stdin\n", argv[0]);
      usage(argv[0]);
      return 1;
    }
  }
  else {
    /* else read objects from stdin */
    if( (obj = WlzAssignObject(WlzReadObj(inFile, NULL), NULL)) == NULL ){
      fprintf(stderr, "%s: can't read obj from stdin\n", argv[0]);
      usage(argv[0]);
      return 1;
    }
    if( (mask = WlzAssignObject(WlzReadObj(inFile, NULL), NULL)) == NULL ){
      fprintf(stderr, "%s: can't read mask from stdin\n", argv[0]);
      usage(argv[0]);
      return 1;
    }
  }
    
  /* apply mask and write resultant object */
  if((newobj = WlzGreyMask(obj, mask, maskVal, &errNum)) != NULL){
    if((errNum = WlzWriteObj(stdout, newobj)) != WLZ_ERR_NONE) {
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: failed to write object (%s).\n",
		     argv[0], errMsg);
      return(1);
    }
    WlzFreeObj(newobj);
  }
  WlzFreeObj(mask);
  WlzFreeObj(obj);

  return 0;
}
コード例 #26
0
ファイル: WlzGreyGradient.c プロジェクト: dscho/Woolz
int             main(int argc, char **argv)
{
  int		option,
		ok = 1,
		usage = 0;
  double	ftrMlt = 1.0,
  		ftrPrm = 1.0;
  WlzRsvFilterName ftrName = WLZ_RSVFILTER_NAME_DERICHE_1;
  WlzRsvFilter *ftr = NULL;
  WlzObject	*inObj = NULL,
  		*outObj = NULL;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  FILE		*fP = NULL;
  char 		*outFileStr,
  		*inObjFileStr;
  static char	optList[] = "ho:gdm:p:",
		outFileStrDef[] = "-",
  		inObjFileStrDef[] = "-";

  opterr = 0;
  outFileStr = outFileStrDef;
  inObjFileStr = inObjFileStrDef;
  while(ok && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'o':
        outFileStr = optarg;
	break;
      case 'h':
        usage = 1;
	ok = 0;
	break;
      case 'g':
        ftrName = WLZ_RSVFILTER_NAME_GAUSS_1;
	break;
      case 'd':
        ftrName = WLZ_RSVFILTER_NAME_DERICHE_1;
	break;
      case 'm':
	if(sscanf(optarg, "%lg", &ftrMlt) != 1)
	{
	  usage = 1;
	  ok = 0;
	}
        break;
      case 'p':
	if(sscanf(optarg, "%lg", &ftrPrm) != 1)
	{
	  usage = 1;
	  ok = 0;
	}
        break;
      default:
        usage = 1;
	ok = 0;
	break;
    }
  }
  if(ok)
  {
    if((inObjFileStr == NULL) || (*inObjFileStr == '\0') ||
       (outFileStr == NULL) || (*outFileStr == '\0'))
    {
      ok = 0;
      usage = 1;
    }
    if(ok && (optind < argc))
    {
      if((optind + 1) != argc)
      {
	usage = 1;
	ok = 0;
      }
      else
      {
	inObjFileStr = *(argv + optind);
      }
    }
    if(ok)
    {
      if(((ftr = WlzRsvFilterMakeFilter(ftrName, ftrPrm, &errNum)) == NULL) ||
         (errNum != WLZ_ERR_NONE))
      {
        ok = 0;
	(void )fprintf(stderr, "%s Failed to create filter (%s)\n",
		       *argv, WlzStringFromErrorNum(errNum, NULL));
      }
      else
      {
	ftr->c *= ftrMlt;
      }
    }
    if(ok)
    {
      if((inObjFileStr == NULL) ||
	 (*inObjFileStr == '\0') ||
	 ((fP = (strcmp(inObjFileStr, "-")?
		fopen(inObjFileStr, "r"): stdin)) == NULL) ||
	 ((inObj= WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL) ||
	 (errNum != WLZ_ERR_NONE))
      {
	ok = 0;
	(void )fprintf(stderr,
		       "%s: failed to read object from file %s\n",
		       *argv, inObjFileStr);
      }
      if(fP && strcmp(inObjFileStr, "-"))
      {
	fclose(fP);
      }
      if(ok)
      {
        if(((outObj = WlzAssignObject(
		      WlzGreyGradient(NULL, NULL, NULL,
		      		      inObj, ftr, &errNum), NULL)) == NULL) ||
	   (errNum != WLZ_ERR_NONE))

        {
	  ok = 0;
	  (void )fprintf(stderr, "%s Failed to compute gradient object (%s)\n",
	  		 *argv, WlzStringFromErrorNum(errNum, NULL));
	}
      }
      if(ok)
      {
	if(((fP = (strcmp(outFileStr, "-")?
		  fopen(outFileStr, "w"):
		  stdout)) == NULL) ||
	   (WlzWriteObj(fP, outObj) != WLZ_ERR_NONE))
	{
	  ok = 0;
	  (void )fprintf(stderr,
			 "%s: failed to write output object\n",
			 *argv);
	}
	if(fP && strcmp(outFileStr, "-"))
	{
	  fclose(fP);
	}
      }
    }
  }
  if(inObj)
  {
    WlzFreeObj(inObj);
  }
  if(outObj)
  {
    WlzFreeObj(outObj);
  }
  if(ftr)
  {
    WlzRsvFilterFreeFilter(ftr);
  }
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%sExample: %s%s",
    *argv,
    " [-o<output object>] [-h] [-o] [-g] [-d] [-m#] [-p#]\n"
    "        [<input object>]\n"
    "Options:\n"
    "  -h  Prints this usage information\n"
    "  -o  Output object file name.\n"
    "  -g  Use approximate Gaussian filter.\n"
    "  -d  Use Deriche filter.\n"
    "  -p  Filter parameter for Gaussian (sigma) and Deriche (alpha) filters\n"
    "  -m  Extra multiplication factor for gradient grey levels.\n"
    "Computes a grey gradient object from the input object.\n"
    "The input object is read from stdin and the gradient object is\n"
    "written to stdout unless the filenames are given.\n",
    *argv,
    " -d -m 2.0 -o grad.wlz in.wlz\n"
    "The input Woolz object is read from in.wlz, and the grey gradient\n"
    "image is computed using a Deriche filter and an additional multiplying\n"
    "factor of 2.0. The gradient object is written to grad.wlz.\n"
    "Objects with unsigned byte grey values will be promoted to short\n"
    "grey valued objects.\n");
  }
  return(!ok);
}
コード例 #27
0
int             main(int argc, char **argv)
{
  int		idM,
  		idN,
  		option,
		ok = 1,
		usage = 0;
  double	dif,
  		tol = 1e-06;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  int		dim[3];
  WlzObject	*obj[2];
  FILE		*fP = NULL;
  char 		*objFileStr[2];
  char		*outFileStr;
  static char	optList[] = "he:o:";

  opterr = 0;
  obj[0] = obj[1] = NULL;
  objFileStr[0] = objFileStr[1] = "-";
  outFileStr = "-";
  while(ok && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'e':
        if(sscanf(optarg, "%lg", &tol) != 1)
	{
	  usage = 1;
	}
	break;
      case 'o':
        outFileStr = optarg;
	break;
      case 'h':
      default: /* FALLTHROUGH */
        usage = 1;
	break;
    }
  }
  if(ok && (optind < argc))
  {
    if((optind + 2) != argc)
    {
      usage = 1;
    }
    else
    {
      objFileStr[0] = *(argv + optind);
      objFileStr[1] = *(argv + optind + 1);
    }
  }
  ok = !usage;
  /* Read the affine transforms objects. */
  if(ok)
  {
    idN = 0;
    while(ok && (idN < 2))
    {
      if((objFileStr[idN] == NULL) ||
	 (*(objFileStr[idN]) == '\0') ||
	 ((fP = (strcmp(objFileStr[idN], "-")?
		fopen(objFileStr[idN], "r"): stdin)) == NULL) ||
	 ((obj[idN] = WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL))
      {
	ok = 0;
	(void )fprintf(stderr,
		       "%s: Failed to read object from file %s.\n",
		       *argv, objFileStr[idN]);
      }
      if(fP && strcmp(objFileStr[idN], "-"))
      {
	(void )fclose(fP); fP = NULL;
      }
      ++idN;
    }
  }
  /* Check object types. */
  if(ok)
  {
    idN = 0;
    while(ok && (idN < 2))
    {
      if(obj[idN]->type != WLZ_AFFINE_TRANS)
      {
        ok = 0;
	(void )fprintf(stderr,
		       "%s: Object read from %s is not an affine transform.\n",
		       *argv, objFileStr[idN]);
      }
      else if(obj[idN]->domain.core == NULL)
      {
        ok = 0;
	(void )fprintf(stderr,
		       "%s: Object read from %s has a NULL domain.\n",
		       *argv, objFileStr[idN]);
      }
      else
      {
        switch(obj[idN]->domain.t->type)
	{
          case WLZ_TRANSFORM_2D_AFFINE:  /* FALLTHROUGH */
  	  case WLZ_TRANSFORM_2D_REG:     /* FALLTHROUGH */
  	  case WLZ_TRANSFORM_2D_TRANS:   /* FALLTHROUGH */
  	  case WLZ_TRANSFORM_2D_NOSHEAR:
	    dim[idN] = 2;
	    break;
  	  case WLZ_TRANSFORM_3D_AFFINE:  /* FALLTHROUGH */
  	  case WLZ_TRANSFORM_3D_REG:     /* FALLTHROUGH */
  	  case WLZ_TRANSFORM_3D_TRANS:   /* FALLTHROUGH */
          case WLZ_TRANSFORM_3D_NOSHEAR:
	    dim[idN] = 3;
	    break;
	  default:
	    ok = 0;
	    (void )fprintf(stderr,
		       "%s: Object read from %s is not an affine transform.\n",
			   *argv, objFileStr[idN]);
	    break;
	}
      }
      ++idN;
    }
  }
  /* Open the output file. */
  if(ok)
  {
    if((outFileStr == NULL) ||
       (*outFileStr == '\0') ||
       ((fP = (strcmp(outFileStr, "-")?
	      fopen(outFileStr, "w"): stdout)) == NULL))
    {
      ok = 0;
      (void )fprintf(stderr,
		     "%s: Failed to open output file %s.\n",
		     *argv, outFileStr);
    }
  }
  /* Compare the transform dimensions. */
  if(ok)
  {
    if(dim[0] != dim[1])
    {
      ok = 0;
      (void )fprintf(fP, "dimension\n< %d\n---\n> %d\n", dim[0], dim[1]);
    }
    dim[2] = WLZ_MAX(dim[0], dim[1]);
    for(idM = 0; idM < dim[2]; ++idM)
    {
      for(idN = 0; idN < dim[2]; ++idN)
      {
        dif = obj[0]->domain.t->mat[idM][idN] -
	      obj[1]->domain.t->mat[idM][idN];
        dif = fabs(dif);
	if(dif > tol)
	{
	  ok = 0;
	  (void )fprintf(fP, "[%d][%d]\n< %1.8e\n---\n> %1.8e\n",
			 idM, idN,
	  		 obj[0]->domain.t->mat[idM][idN],
			 obj[1]->domain.t->mat[idM][idN]);
	}
      }
    }
  }
  if(fP && strcmp(outFileStr, "-"))
  {
    (void )fclose(fP); fP = NULL;
  }
  (void )WlzFreeObj(obj[0]);
  (void )WlzFreeObj(obj[1]);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%s%s%sExample: %s%s",
    *argv,
    " [-h] [-e #] [-o<output file>]\n"
    "                              <transform 0> <transform 1>\n"
    "Version: ",
    WlzVersion(),
    "\n"
    "Options:\n"
    "  -h  Help, prints this usage message.\n"
    "  -e  Tolerance value.\n"
    "  -o  Output file for differences.\n"
    "Compares two given affine transforms for significant differences\n"
    "using the given tollerance value.\n"
    "The exit status is 0 if the two transforms do not significantly\n"
    "differ, otherwise it is 1.\n"
    "The output file (if given) will be touched even if there are no\n"
    "differences found.\n",
    *argv,
    " -e 0.00001 -o diff.out tr0.wlz tr1.wlz\n"
    "Reads a pair of affine transforms from tr0.wlz and tr1.wlz, then\n"
    "writes any differences to diff.out.\n");
  }
  return((ok)? 0: 1);
}
コード例 #28
0
ファイル: WlzGreyInvert.c プロジェクト: dscho/Woolz
int main(int	argc,
	 char	**argv)
{

  WlzObject	*obj;
  FILE		*inFile;
  char 		optList[] = "l:u:hv";
  int		option;
  WlzPixelV	max, min;
  WlzPixelV	gmin, gmax;
  int		getminFlg=1, getmaxFlg=1, verboseFlg=0;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const char	*errMsg;
  int		objCount=0;
    
  /* read the argument list and check for an input file */
  opterr = 0;
  max.type = min.type = WLZ_GREY_DOUBLE;
  max.v.dbv = 255.0;
  min.v.dbv = 0.0;
  
  while( (option = getopt(argc, argv, optList)) != EOF ){
    switch( option ){

    case 'l':
      min.v.dbv = atof(optarg);
      getminFlg = 0;
      break;

    case 'u':
      max.v.dbv = atof(optarg);
      getmaxFlg = 0;
      break;

    case 'v':
      verboseFlg = 1;
      break;

    case 'h':
    default:
      usage(argv[0]);
      return 1;

    }
  }

  inFile = stdin;
  if( optind < argc ){
    if( (inFile = fopen(*(argv+optind), "r")) == NULL ){
      fprintf(stderr, "%s: can't open file %s\n", argv[0], *(argv+optind));
      usage(argv[0]);
      return 1;
    }
  }

  /* read objects and threshold if possible */
  while(((obj = WlzAssignObject(WlzReadObj(inFile, NULL), NULL)) != NULL) &&
        (errNum == WLZ_ERR_NONE))
  {
    objCount++;
    switch( obj->type )
    {
    case WLZ_2D_DOMAINOBJ:
    case WLZ_3D_DOMAINOBJ:
      /* get the existing min and max grey values */
      if( getminFlg || getmaxFlg ){
	if( (errNum = WlzGreyRange(obj, &gmin, &gmax)) == WLZ_ERR_NONE ){
	  if( getminFlg ){
	    WlzValueConvertPixel(&min, gmin, WLZ_GREY_DOUBLE);
	  }
	  if( getmaxFlg ){
	    WlzValueConvertPixel(&max, gmax, WLZ_GREY_DOUBLE);
	  }
	}
      }

      if( errNum == WLZ_ERR_NONE ){
	if( verboseFlg ){
	  fprintf(stderr,
		  "%s:\nconverting object %d with parameters:\n"
		  "\t(l, u) = (%f, %f)\n",
		  argv[0], objCount, min.v.dbv, max.v.dbv);
	}

	errNum = WlzGreyInvertMinMax(obj, min, max);
	if( errNum == WLZ_ERR_NONE ){
	  if((errNum = WlzWriteObj(stdout, obj)) != WLZ_ERR_NONE) {
	    (void )WlzStringFromErrorNum(errNum, &errMsg);
	    (void )fprintf(stderr,
			   "%s: failed to write object (%s).\n",
			   argv[0], errMsg);
	    return(1);
	  }
	}
      }
      break;

    default:
      if((errNum = WlzWriteObj(stdout, obj)) != WLZ_ERR_NONE) {
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: failed to write object (%s).\n",
		       argv[0], errMsg);
	return(1);
      }
      break;
    }
    WlzFreeObj(obj);
  }

  return 0;
}
コード例 #29
0
ファイル: HGU_XmImageView.c プロジェクト: ma-tech/HGUX
void HGU_XmImageViewControlledInstallImage(
    WlzObject			*obj,
    HGU_XmImageViewDataStruct	*data,
    unsigned int			cntrlMask)
{
    if( data == NULL ) {
        return;
    }
    if( obj == NULL || (obj->type != WLZ_2D_DOMAINOBJ) ) {
        if( cntrlMask & HGU_XmIMAGEVIEW_CLEARONINVALID ) {
            obj = NULL;
        }
        else {
            return;
        }
    }

    /* clear old object and ximage */
    if( data->obj ) {
        WlzFreeObj(data->obj);
        data->obj = NULL;
    }
    if( data->ximage ) {
        if( data->ximage->data ) {
            AlcFree(data->ximage->data);
            data->ximage->data = NULL;
        }
        XDestroyImage(data->ximage);
        data->ximage = NULL;
    }

    if( obj ) {
        Dimension	width, height;
        data->obj = WlzAssignObject(obj, NULL);

        /* reset the LUT */
        HGU_XmImageViewResetGreyRange(data);
        if( !(cntrlMask & HGU_XmIMAGEVIEW_KEEPLUTCONTROLVALUES) ) {
            HGU_XmImageViewResetLutControlValues(data);
        }
        HGU_XmImageViewSetLutTransform(data);
        HGU_XmImageViewSetLutControls(data);

        /* call canvas expose to provoke display */
        if( !(cntrlMask & HGU_XmIMAGEVIEW_KEEPMAGVALUE) ) {
            data->magVal = 1.0;
        }
        data->width = data->obj->domain.i->lastkl - data->obj->domain.i->kol1 + 1;
        data->height = data->obj->domain.i->lastln - data->obj->domain.i->line1 + 1;
        width = data->width * data->magVal;
        height = data->height * data->magVal;
        XtVaSetValues(data->canvas, XmNwidth, width,
                      XmNheight, height, NULL);
        XtCallCallbacks(data->canvas, XmNexposeCallback, NULL);
    }
    else {
        /* clear the canvas, leave data etc unchanged */
        XClearWindow(XtDisplay(data->canvas), XtWindow(data->canvas));
    }

    return;
}
コード例 #30
0
ファイル: WlzTensorComponent.c プロジェクト: ma-tech/Woolz
int		main(int argc, char *argv[])
{
  int		ok = 1,
  		option,
		usage = 0,
		cpt = 0;
  char		*inFileStr,
		*outFileStr;
  FILE		*fP = NULL;
  WlzObject	*inObj = NULL,
		*outObj = NULL;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const char	*errMsgStr;
  static char	optList[] = "hc:o:";
  const char    fileStrDef[] = "-";

  /* Parse the argument list and check for input files. */
  opterr = 0;
  inFileStr = (char *)fileStrDef;
  outFileStr = (char *)fileStrDef;
  while(ok && !usage && ((option = getopt(argc, argv, optList)) != EOF))
  {
    switch(option)
    {
      case 'c':
	if(sscanf(optarg, "%d", &cpt) != 1)
        {
	  usage = 1;
	}
	break;
      case 'o':
	outFileStr = optarg;
	break;
      case 'h':
      default:
	usage = 1;
	break;
    }
  }
  if(ok)
  {
    ok = !usage;
  }
  if(ok && (optind < argc))
  {
    if((optind + 1) != argc)
    {
      usage = 1;
      ok = 0;
    }
    else
    {
      inFileStr = argv[optind];
    }
  }
  /* Read the input object. */
  if(ok)
  {
    if((inFileStr == NULL) ||
       (*inFileStr == '\0') ||
       ((fP = (strcmp(inFileStr, "-")?
              fopen(inFileStr, "r"): stdin)) == NULL) ||
       ((inObj = WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL))
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Failed to read input object from file %s.\n",
                     argv[0], inFileStr);
    }
    if(fP && strcmp(inFileStr, "-"))
    {
      (void )fclose(fP); fP = NULL;
    }
  }
  /* Extract component to a new object. */
  if(ok)
  {
    outObj = WlzTensorGetComponent(inObj, cpt, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsgStr);
      (void )fprintf(stderr,
                     "%s: Failed to extract component with index %d, %s.\n",
                     argv[0], cpt, errMsgStr);
    }
  }
  /* Output the component object. */
  if(ok)
  {
    if((fP = (strcmp(outFileStr, "-")?
             fopen(outFileStr, "w"): stdout)) == NULL)
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Failed to open output file %s.\n",
                     argv[0], outFileStr);
    }
  }
  if(ok)
  {
    errNum = WlzWriteObj(fP, outObj);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsgStr);
      (void )fprintf(stderr,
                     "%s: Failed to write output object, %s.\n",
                     argv[0], errMsgStr);
    }
  }
  if(fP && strcmp(outFileStr, "-"))
  {
    (void )fclose(fP); fP = NULL;
  }
  (void )WlzFreeObj(inObj);
  (void )WlzFreeObj(outObj);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s [-c<cpt>] [-o<output object>] [-h]\n"
    "\t\t[<input object>]\n"
    "Version: %s\n"
    "Options:\n"
    "  -c  Component index which must be in the range [0-(1-V_n)] where\n"
    "      V_n is the number of component values per element in the object,\n"
    "      eg for a scalar image 0 and for a rank 2 3x3 tensor this would\n"
    "      be 9.\n"
    "  -o  Output file.\n"
    "  -h  Help, prints usage message.\n"
    "Extracts tensor component values from a tensor image object.\n"
    "Because the resulting object is always a non-tiled object this\n"
    "filter may also be used to convert a tiled to non-tiled object.\n"
    "It is safe to supply a non-tiled object as the input (provided that\n"
    "the component index is zero). By default all files are read from the\n"
    "standard input and written to the standard output.\n"
    "Example:\n"
    "  %s -o c_0.wlz -c 0 in.wlz\n"
    "creates a scalar object containing just the first component of\n"
    "the given tensor image. Alternatively this would also convert\n"
    "a tiled object (in.wlz) to a non-tiled object (retaining only\n"
    "the zeroth component of it's values). The object is written to the\n"
    "file c_0.wlz\n",
    argv[0],
    WlzVersion(),
    argv[0]);
  }
  return(!ok);
}