Example #1
0
VImage VSelectDestImage (VStringConst routine, VImage dest,
			 int nbands, int nrows, int ncolumns,
			 VRepnKind pixel_repn)
{
  /* If no destination image was specified, allocate one: */
  if (! dest)
    return VCreateImage (nbands, nrows, ncolumns, pixel_repn);

    /* Otherwise check that the destination provided has the appropriate
       characteristics: */
  if (VImageNBands (dest) != nbands) {
    VWarning ("%s: Destination image has %d bands; %d expected",
	      routine, VImageNBands (dest), nbands);
    return NULL;
  }
  if (VImageNRows (dest) != nrows) {
    VWarning ("%s: Destination image has %d rows; %d expected",
	      routine, VImageNRows (dest), nrows);
    return NULL;
  }
  if (VImageNColumns (dest) != ncolumns) {
    VWarning ("%s: Destination image has %d columns; %d expected",
	      routine, VImageNColumns (dest), ncolumns);
    return NULL;
  }
  if (VPixelRepn (dest) != pixel_repn) {
    VWarning ("%s: Destination image has %s pixels; %s expected", routine, 
	      VPixelRepnName (dest), VRepnName (pixel_repn));
    return NULL;
  }
  return dest;
}
Example #2
0
VBoolean Compatible (VImage Image1, VImage Image2)
{
   /* compare image sizes */
   if ((VImageNBands   (Image1) != VImageNBands   (Image2)) ||
       (VImageNRows    (Image1) != VImageNRows    (Image2)) ||
       (VImageNColumns (Image1) != VImageNColumns (Image2)))
   {
      VError ("Images have different sizes");
      return FALSE;
   }

   return TRUE;

} /* Compatible */
Example #3
0
/* Output an image in the ppm format (see ppm man page for details).
 */
void WritePnmFile (FILE *outfile, VImage image, VBand band)
{
  VUByte *src_pp;
  int i,u,r,c;
  int nrows = VImageNRows (image),
    ncols = VImageNColumns (image);

  if (VImageColorInterp(image) == VBandInterpRGB) {    /* color map */
    fprintf (outfile, "P6\n%d %d\n255\n",ncols,nrows);
    for (r=0; r<nrows; r++) {
      for (c=0; c<ncols; c++) {
	u = (int)VPixel(image,0,r,c,VUByte);
	putc(u,outfile);
	u = (int)VPixel(image,1,r,c,VUByte);
	putc(u,outfile);
	u = (int)VPixel(image,2,r,c,VUByte);
	putc(u,outfile);
      }
    }
  }


  else {     /* gray map */
    fprintf (outfile, "P5\n%d %d\n255\n",ncols,nrows);
    src_pp = (VUByte *) VPixelPtr (image, band, 0, 0);
    for (i=0; i<nrows*ncols; i++) {
      u = *src_pp++;
      putc(u,outfile);
    }
  }
  fclose(outfile);
}
Example #4
0
File: vhemi.c Project: Rollmops/via
/*
 *  Zero out one hemisphere of a raster image
 */
void
VImageHemi(VImage *src,VLong hemi)
{
  int nbands,nrows,ncols;
  int b,r,c,c0,c1,half;

  ncols  = VImageNColumns (*src);
  nrows  = VImageNRows (*src);
  nbands = VImageNBands (*src);

  half = ncols/2;

  if (hemi == 1) {
    c0 = 0;
    c1 = half;
  }
  else {
    c0 = half;
    c1 = ncols;
  }
 
  for (b=0; b<nbands; b++) {
    for (r=0; r<nrows; r++) {
      for (c=c0; c<c1; c++) {
	VSetPixel((*src),b,r,c,(VDouble) 0);
      }
    }
  }
}
Example #5
0
VImage VImageManager::scaleImage( VImage src, VImage dest, double factor )
{
	int nPixel = VImageSize( src ) / VPixelSize( src );

	if ( dest == NULL ) {
		dest = VCreateImage(
				   VImageNBands( src ),
				   VImageNRows( src ),
				   VImageNColumns( src ),
				   VUByteRepn );
	}


	VUByte *destPtr = ( VUByte * ) VImageData( dest );
	VShort *srcPtr = ( VShort * ) VImageData( src );

	srcPtr = ( VShort * ) VImageData( src );

	for ( int i = 0; i < nPixel; i++ ) {
		if ( *srcPtr <= m_xmin )
			*destPtr = 0;
		else if ( *srcPtr >= m_xmax )
			*destPtr = 255;
		else {
			int val = *srcPtr - m_xmin;
			*destPtr = ( VUByte ) ( val * factor );
		}

		srcPtr++;
		destPtr++;
	}

	return dest;
}
Example #6
0
/*!
  \fn VImage VDTDilate(VImage src,VImage dest,VDouble radius)
  \brief 3D morphological dilation
  \param src   input image (bit repn)
  \param dest  output image (bit repn)
  \param radius radius of the spherical structural element
*/
VImage
VDTDilate(VImage src,VImage dest,VDouble radius)
{
  VImage float_image;
  VBit *bin_pp;
  VFloat *float_pp;
  int i,nbands,nrows,ncols,npixels;

  if (VPixelRepn(src) != VBitRepn) 
    VError("Input image must be of type VBit");

  nbands  = VImageNBands(src);
  nrows   = VImageNRows(src);
  ncols   = VImageNColumns(src);
  npixels = nbands * nrows * ncols;

  float_image = VChamferDist3d(src,NULL,VFloatRepn);
  if (! float_image) 
    VError("VDTDilate failed.\n");

  dest = VSelectDestImage("VDTDilate",dest,nbands,nrows,ncols,VBitRepn);
  if (! dest) return NULL;

  float_pp  = (VFloat *) VPixelPtr(float_image,0,0,0);
  bin_pp    = (VBit *) VPixelPtr(dest,0,0,0);
  for (i=0; i<npixels; i++)
    *bin_pp++ = ((*float_pp++ > radius) ? 0 : 1);

  VDestroyImage(float_image);

  VCopyImageAttrs (src,dest);
  return dest;
}
Example #7
0
VImage VImageManager::vtimestep( VAttrList list, VImage dest, int step )
{
	VFillImage( dest, VAllBands, 0 );
	VPointer src_pp = NULL;
	VPointer dest_pp = NULL;
	VAttrListPosn posn;
	VShort *ptr1 = NULL;
	VShort *ptr2 = NULL;
	VString str;
	VImage src;

	int n = 0;
	int npixels = 0;

	bool revert = false;

	for ( VFirstAttr ( list, & posn ); VAttrExists ( & posn ); VNextAttr ( & posn ) ) {
		if ( VGetAttrRepn ( & posn ) != VImageRepn )
			continue;

		VGetAttrValue ( &posn, NULL, VImageRepn, &src );

		if ( VPixelRepn( src ) != VShortRepn )
			continue;


		if ( ( VGetAttr ( VImageAttrList ( src ), "MPIL_vista_0", NULL,
						  VStringRepn, ( VPointer ) & str ) != VAttrFound ) &&
			 ( VGetAttr ( VImageAttrList ( src ), "repetition_time", NULL,
						  VStringRepn, ( VPointer ) & str ) != VAttrFound ) )
			continue;


		/* doch nicht rumdrehen!
		   if (VGetAttr (VImageAttrList (src), "extent", NULL,
		   VStringRepn, (VPointer) & str) != VAttrFound)
		   revert = true;
		*/

		if ( n == 0 )
			VCopyImageAttrs ( src, dest );

		if ( VImageNRows( src ) > 1 ) {
			if ( VSelectBand ( "vtimestep", src, step, &npixels, &src_pp ) == FALSE )
				VError( "err reading data" );

			int destBand = ( revert ) ? VImageNBands( dest ) - n - 1 : n;

			dest_pp = VPixelPtr( dest, destBand, 0, 0 );

			ptr1 = ( VShort * ) src_pp;
			ptr2 = ( VShort * ) dest_pp;
			memcpy ( ptr2, ptr1, npixels * sizeof( VShort ) );
		}

		n++;
	}

	return dest;
}
Example #8
0
VImage VCombineBands (int nels, VImage src_images[], VBand src_bands[],
		      VImage dest)
{
  int n, i;
  VImage result, src = src_images[0];

  /* Count the number of bands needed in the destination image: */
  for (i = n = 0; i < nels; i++)
    n += (src_bands[i] == VAllBands) ? VImageNBands (src_images[i]) : 1;

  /* Check or allocate the destination image: */
  result = VSelectDestImage ("VCombineBands", dest, n,
			     VImageNRows (src), VImageNColumns (src), 
			     VPixelRepn (src));
  if (! result)
    return NULL;

  /* Copy each source band into the destination image: */
  for (i = n = 0; i < nels; i++) {
    if (! VCopyBand (src_images[i], src_bands[i], result, n)) {
      if (result != dest)
	VDestroyImage (result);
      return NULL;
    }
    n += (src_bands[i] == VAllBands) ? VImageNBands (src_images[i]) : 1;
  }
  return result;
}
Example #9
0
/*
** check if multicomp is okay
*/
VBoolean
CheckValueSymm(VImage multicomp, int size, VFloat zval, float sym) {
    int j, k, csize, msize;
    VFloat u, tiny = 0.00001;
    float s[3] = {0.1, 0.2, 0.3};  /* symm dist */
    csize = VImageNRows(multicomp);
    msize = VImageNColumns(multicomp);
    if(size >= csize)
        return TRUE;
    u = sym;
    if(u < s[0])
        k = 0;                     /* non-symmetric */
    else if(u >= s[0] && u < s[1])
        k = 1;    /* somewhat symmetric */
    else if(u >= s[1] && u < s[2])
        k = 2;    /* symmetric */
    else
        k = 3;                             /* strongly symmetric */
    for(j = 1; j < msize; j++) {
        u = VPixel(multicomp, k, size, j, VFloat);
        if(zval > u && u > tiny)
            return TRUE;
    }
    return FALSE;
}
Example #10
0
/*
** read several rows of data from a file
*/
void
VReadObjectData (FILE *fp,int object_id,VImage *image)
{
  static VImageInfo imageInfo;
  static VAttrList list=NULL;

  fseek(fp,0L,SEEK_SET);
  if (! ReadHeader (fp)) VError("error reading header"); 


  if (! (list = ReadAttrList (fp)))  
    VError("error reading attr list"); 
  
  if (! VGetImageInfo(fp,list,object_id,&imageInfo))
    VError(" error reading image info");

  if (imageInfo.nbands != VImageNBands((*image)))
    VError("incorrect number of bands");
  if (imageInfo.nrows != VImageNRows((*image))) 
    VError("incorrect number of rows");
  if (imageInfo.ncolumns != VImageNColumns((*image)))
    VError("incorrect number of columns");
  if (imageInfo.repn != VPixelRepn((*image))) 
    VError("incorrect pixel representation");
  
  if (! VReadBlockData (fp,&imageInfo,0,imageInfo.nrows,image))
    VError(" error reading data");
}
Example #11
0
/*
** read a 2nd level design file
*/
VImage
VRead2ndLevel(FILE *fp) {
    VImage dest = NULL;
    int i, j, nrows, ncols;
    float val;
    char buf[LEN], token[32];
    nrows = ncols = 0;
    while(!feof(fp)) {
        memset(buf, 0, LEN);
        if(!fgets(buf, LEN, fp))
            break;
        if(strlen(buf) < 1)
            continue;
        if(buf[0] == '%')
            continue;
        j = 0;
        while(VStringToken(buf, token, j, 30)) {
            if(!sscanf(token, "%f", &val))
                VError("illegal input string: %s", token);
            j++;
        }
        if(ncols == 0)
            ncols = j;
        if(j < 1)
            continue;
        else if(ncols != j)
            VError(" inconsistent number of columns in row %d", nrows + 1);
        nrows++;
    }
    rewind(fp);
    dest = VCreateImage(1, nrows, ncols, VFloatRepn);
    VFillImage(dest, VAllBands, 0);
    VSetAttr(VImageAttrList(dest), "modality", NULL, VStringRepn, "X");
    VSetAttr(VImageAttrList(dest), "name", NULL, VStringRepn, "X");
    VSetAttr(VImageAttrList(dest), "ntimesteps", NULL, VLongRepn, (VLong)VImageNRows(dest));
    VSetAttr(VImageAttrList(dest), "nsessions", NULL, VShortRepn, (VShort)1);
    VSetAttr(VImageAttrList(dest), "designtype", NULL, VShortRepn, (VShort)2);
    i = 0;
    while(!feof(fp)) {
        memset(buf, 0, LEN);
        if(!fgets(buf, LEN, fp))
            break;
        if(strlen(buf) < 1)
            continue;
        if(buf[0] == '%')
            continue;
        j = 0;
        while(VStringToken(buf, token, j, 30)) {
            sscanf(token, "%f", &val);
            VPixel(dest, 0, i, j, VFloat) = val;
            j++;
        }
        if(j < 1)
            continue;
        i++;
    }
    return dest;
}
Example #12
0
VImage 
VSelSlices (VImage src,VImage dest,VShort first,VShort last)
{
  int nbands,nrows,ncols,nbands_neu,npixels;
  int i,b,bn;
  VRepnKind repn;

  nbands = VImageNBands(src);
  nrows  = VImageNRows(src);
  ncols  = VImageNColumns(src);
  repn   = VPixelRepn(src);

  if (first < 0) VError("VSelSlices: parameter <first> must be positive");
  if (last < 0) last = nbands-1;
  if (last >= nbands) last = nbands-1;


  if (first > last)
    VError("VSelSlices: <first> must be less than <last>.");

  nbands_neu = last - first + 1;
  if (dest == NULL)
    dest = VCreateImage(nbands_neu,nrows,ncols,repn);

  npixels = nrows * ncols;

#define SelSlices(type) \
{ \
  type *src_pp, *dest_pp; \
  bn = 0; \
  for (b=first; b<=last; b++) { \
    src_pp  = VPixelPtr(src,b,0,0); \
    dest_pp = VPixelPtr(dest,bn,0,0); \
    for (i=0; i<npixels; i++) *dest_pp++ = *src_pp++; \
    bn++; \
  } \
}

      
  /* Instantiate the macro once for each source pixel type: */
  switch (repn) {
  case VBitRepn:	SelSlices (VBit);	break;
  case VUByteRepn:	SelSlices (VUByte);	break;
  case VSByteRepn:	SelSlices (VSByte);	break;
  case VShortRepn:	SelSlices (VShort);	break;
  case VLongRepn:	SelSlices (VLong);	break;
  case VFloatRepn:	SelSlices (VFloat);	break;
  case VDoubleRepn:	SelSlices (VDouble);	break;
  default: ;
  }


  /* Let the destination inherit any attributes of the source image: */
  VCopyImageAttrs (src, dest);
  return dest;
}
Example #13
0
VImage
ConcatDesigns(VImage *design, int nimages) {
    VImage dest = NULL;
    VString buf = NULL;
    VDouble x;
    int i, r, c, row, col;
    int nrows, ncols;
    nrows = ncols = 0;
    for(i = 0; i < nimages; i++) {
        ncols += VImageNColumns(design[i]);
        nrows += VImageNRows(design[i]);
    }
    dest = VCreateImage(1, nrows, ncols, VFloatRepn);
    VFillImage(dest, VAllBands, 0);
    VCopyImageAttrs(design[0], dest);
    VSetAttr(VImageAttrList(dest), "nsessions", NULL, VShortRepn, (VShort)nimages);
    buf = (VString) VMalloc(80);
    buf[0] = '\0';
    for(i = 0; i < nimages; i++)
        sprintf(buf, "%s %d", buf, (int)VImageNRows(design[i]));
    VSetAttr(VImageAttrList(dest), "session_lengths", NULL, VStringRepn, buf);
    buf[0] = '\0';
    for(i = 0; i < nimages; i++)
        sprintf(buf, "%s %d", buf, (int)VImageNColumns(design[i]));
    VSetAttr(VImageAttrList(dest), "session_covariates", NULL, VStringRepn, buf);
    row = col = 0;
    for(i = 0; i < nimages; i++) {
        for(r = 0; r < VImageNRows(design[i]); r++) {
            for(c = 0; c < VImageNColumns(design[i]); c++) {
                x = VGetPixel(design[i], 0, r, c);
                if(row + r >= VImageNRows(dest))
                    VError(" row: %d\n", row + r);
                if(col + c >= VImageNColumns(dest))
                    VError(" column: %d\n", col + c);
                VSetPixel(dest, 0, row + r, col + c, x);
            }
        }
        row += VImageNRows(design[i]);
        col += VImageNColumns(design[i]);
    }
    return dest;
}
Example #14
0
VBoolean FunctionalZero (VImage Image)
{
   int     Pixels;   /* number of pixels   */
   VShort* image;    /* image data pointer */
   int     n;        /* index              */


   /* check image size */
   if ((VImageNBands (Image) == 1) && (VImageNRows (Image) == 1) && (VImageNColumns (Image) == 1))
      return TRUE;

   /* check image content */
   Pixels = VImageNBands (Image) * VImageNRows (Image) * VImageNColumns (Image);
   image  = (VShort*) VPixelPtr (Image, 0, 0, 0);
   for (n = 0; n < Pixels; ++n)
      if (*(image++) != 0)
         return FALSE;

   return TRUE;

} /* FunctionalZero */
Example #15
0
unsigned short CVImage::getSize( Direction dir, VImage image )
{
	switch( dir ) {
	case read:
		return VImageNColumns( image );
		break;
	case phase:
		return VImageNRows( image );
		break;
	case slice:
		return VImageNBands( image );
		break;
	}
}
Example #16
0
/*!
\fn VImage VMedianImage2d (VImage src, VImage dest, int dim, VBoolean ignore)
\param src      input image
\param dest     output image 
\param dim      kernel size
\param ignore   whether to ignore zero voxels
*/
VImage 
VMedianImage2d (VImage src, VImage dest, int dim, VBoolean ignore)
{
  int nbands,nrows,ncols;
  int i,len,b,r,c,rr,cc,d=0;
  gsl_vector *vec=NULL;
  double u,tiny=1.0e-10;

  if (dim%2 == 0) VError("VMedianImage2d: dim (%d) must be odd",dim);

  nrows  = VImageNRows (src);
  ncols  = VImageNColumns (src);
  nbands = VImageNBands (src);

  d = dim/2;
  len = dim * dim;
  vec = gsl_vector_calloc(len);

  dest   = VCopyImage(src,dest,VAllBands);

  for (b=0; b<nbands; b++) {
    for (r=d; r<nrows-d; r++) {
      for (c=d; c<ncols-d; c++) {
	gsl_vector_set_zero(vec);

	u = VGetPixel(src,b,r,c);
	if ( !ignore || ABS(u) > tiny) {

	  i = 0;
	  for (rr=r-d; rr<=r+d; rr++) {
	    for (cc=c-d; cc<=c+d; cc++) {
	      u = VGetPixel(src,b,rr,cc);
	      if (ABS(u) > 0) {
		gsl_vector_set(vec,i,u);
		i++;
	      }
	    }
	  }
	  gsl_sort_vector(vec);
	  u = gsl_stats_median_from_sorted_data(vec->data,vec->stride,i);
	  VSetPixel(dest,b,r,c,u);
	}
      }
    }
  }
  return dest;
}
Example #17
0
VImage VCopyImageAttrs (VImage src, VImage dest)
{
  VAttrList list;

  if (src == dest)
    return dest;
  if (! dest) {
    dest = VCreateImage (VImageNBands (src), VImageNRows (src),
			 VImageNColumns (src), VPixelRepn (src));
    if (! dest)
      return NULL;
  }

  /* Clone the source image's attribute list if it isn't empty: */
  if (! VAttrListEmpty (VImageAttrList (src))) {
    list = VImageAttrList (dest);
    VImageAttrList (dest) = VCopyAttrList (VImageAttrList (src));
  } else if (! VAttrListEmpty (VImageAttrList (dest))) {
    list = VImageAttrList (dest);
    VImageAttrList (dest) = VCreateAttrList ();
  } else list = NULL;
  if (list)
    VDestroyAttrList (list);

  /* Preserve band interpretation attributes only if the source and
     destination images have the same number of bands: */
  if (VImageNBands (src) > 1 && VImageNBands (dest) == VImageNBands (src)) {
    VImageNFrames (dest) = VImageNFrames (src);
    VImageNViewpoints (dest) = VImageNViewpoints (src);
    VImageNColors (dest) = VImageNColors (src);
    VImageNComponents (dest) = VImageNComponents (src);
  } else {
    VExtractAttr (VImageAttrList (dest), VFrameInterpAttr, NULL,
		  VBitRepn, NULL, FALSE);
    VExtractAttr (VImageAttrList (dest), VViewpointInterpAttr, NULL,
		  VBitRepn, NULL, FALSE);
    VExtractAttr (VImageAttrList (dest), VColorInterpAttr, NULL,
		  VBitRepn, NULL, FALSE);
    VExtractAttr (VImageAttrList (dest), VComponentInterpAttr, NULL,
		  VBitRepn, NULL, FALSE);
    VImageNComponents (dest) = VImageNColors (dest) = 
      VImageNViewpoints (dest) = 1;
    VImageNFrames (dest) = VImageNBands (dest);
  }
  return dest;
}
Example #18
0
/*!
\fn VImage VMapImageRange(VImage src,VImage dest,VRepnKind repn)
\brief
The minimum and maximum grey values of the input images are computed,
and a linear mapping is performed mapping the input minimum(maximum) 
of the input image to the min(max) value of the output pixel repn.
E.g. if the input image min is -17 and its max is +2376, and the output repn
is VUByteRepn, then the linear mapping function maps -17 to 0 and
+2376 to 255.
\param src   input image  (any repn)
\param dest  output image
\param repn  the output pixel repn (e.g. VUByteRepn)
*/
VImage
VMapImageRange(VImage src,VImage dest,VRepnKind repn)
{
  int i,nbands,nrows,ncols,npixels;
  float u,ymin,ymax,dmin,dmax,slope;

  if (repn == VDoubleRepn || repn == VLongRepn || repn == VSByteRepn)
    VError(" VMapImageRange: double, long and sbyte are not supported");

  nbands = VImageNBands(src);
  nrows  = VImageNRows(src);
  ncols  = VImageNColumns(src);
  npixels = VImageNPixels(src);

  dest = VSelectDestImage("VMapImageRange",dest,nbands,nrows,ncols,repn);
  if (! dest) VError(" err creating dest image");
  VFillImage(dest,VAllBands,0);


  ymin = VPixelMaxValue(src);
  ymax = VPixelMinValue(src);

  for (i=0; i<npixels; i++) {
    u = VGetPixelValue (src,i);
    if (u < ymin) ymin = u;
    if (u > ymax) ymax = u;
  }

  dmax = VPixelMaxValue(dest);
  dmin = VPixelMinValue(dest);

  slope = (dmax - dmin) / (ymax - ymin);

  for (i=0; i<npixels; i++) {
    u = VGetPixelValue (src,i);
    u = slope * (u - ymin);
    if (u < dmin) u = dmin;
    if (u > dmax) u = dmax;
    VSetPixelValue(dest,i,(VFloat) u);
  }

  VCopyImageAttrs (src, dest);
  return dest;
}
Example #19
0
/* Output an image in the pgm format (see pgm man page for details).
 */
void WritePgmFile (FILE *outfile, VImage image, VBand band)
{
    VUByte *ppixel;
    int i;
    int rows = VImageNRows (image),
        columns = VImageNColumns (image);

    /* Output header information for pgm. */
    fprintf (outfile, "P2\n%d %d\n255\n", columns, rows);

    ppixel = (VUByte *) VPixelPtr (image, band, 0, 0);
    
    for (i = 0; i < rows * columns; i++) {
	fprintf (outfile, " %3d", *ppixel++);
	if (i%10 == 9)
	    fprintf (outfile, "\n");
    }
    fprintf (outfile, "\n");
}
Example #20
0
VBoolean VCopyBand (VImage src, VBand src_band, VImage dest, VBand dest_band)
{
  int nbands, src_npixels, dest_npixels;
  VPointer src_pixels, dest_pixels;

  /* The destination image must exist: */
  if (! dest) {
    VWarning ("VCopyBand: No destination specified");
    return FALSE;
  }

  /* VAllBands not accepted for destination band: */
  if (dest_band < 0 || dest_band >= VImageNBands (dest)) {
    VWarning ("VCopyBand: Band %d referenced in image of %d bands",
	      (int) dest_band, (int) VImageNBands (dest));
    return FALSE;
  }

  /* Ensure that the destination image has the appropriate dimensions
     and pixel representation: */
  nbands = dest_band;
  if (src_band == VAllBands)
    nbands += VImageNBands (src) - 1;
  if (nbands < VImageNBands (dest))
    nbands = VImageNBands (dest);
  if (! VSelectDestImage ("VCopyBand", dest, nbands, VImageNRows (src),
			  VImageNColumns (src), VPixelRepn (src)))
    return FALSE;

  /* Locate the specified source and destination bands: */
  if (! VSelectBand ("VCopyBand", src, src_band,
		     & src_npixels, & src_pixels))
    return FALSE;
  if (! VSelectBand ("VCopyBand", dest, dest_band,
		     & dest_npixels, & dest_pixels))
    return FALSE;

  /* Copy from the source band to the destination band: */
  memcpy (dest_pixels, src_pixels, src_npixels * VPixelSize (src));

  return TRUE;
}
Example #21
0
VBoolean VSelectBand (VStringConst routine, VImage image, VBand band,
		      int *npixels, VPointer *first_pixel)
{
  if (band == VAllBands) {
    if (npixels)
      *npixels = VImageNPixels (image);
    if (first_pixel)
      *first_pixel = VImageData (image);
  } else if (band >= 0 && band < VImageNBands (image)) {
    if (npixels)
      *npixels = VImageNRows (image) * VImageNColumns (image);
    if (first_pixel)
      *first_pixel = image->band_index[band][0];
  } else {
    VWarning ("%s: Band %d referenced in image of %d band(s)",
	      routine, band, VImageNBands (image));
    return FALSE;
  }
  return TRUE;
}
Example #22
0
template <class T> void OpticalFlow (VImage S, VImage M, VImage G, VImage G2, VImage& V)
{
   const float EPSILON = 1;   /* threshold for denominator of optical flow */

   int Pixels;   /* number of pixels */

   T      *s, *m;    /* source and model data pointer */
   VFloat *g, *g2;   /* gradient data pointer         */
   VFloat *v;        /* optical flow data pointer     */

   float nom, denom;   /* fraction */

   int n;   /* index */


   /* get image size */
   Pixels = VImageNPixels (S);

   /* create optical flow */
   V = VCreateImage (VImageNBands (S), VImageNRows (S), VImageNColumns (S), VFloatRepn);


   /* compute optical flow */
   s  = (T*)      VPixelPtr (S,  0, 0, 0);
   m  = (T*)      VPixelPtr (M,  0, 0, 0);
   g  = (VFloat*) VPixelPtr (G,  0, 0, 0);
   g2 = (VFloat*) VPixelPtr (G2, 0, 0, 0);
   v  = (VFloat*) VPixelPtr (V,  0, 0, 0);
   for (n = 0; n < Pixels; ++n)
   {
      /* compute fraction */
      nom   = (float) (*(m++) - *(s++));
      denom = (float) (*(g2++) + (nom * nom));

      /* assign optical flow */
      if (denom < EPSILON) *(v++) = 0;
      else                 *(v++) = (VFloat) ((nom / denom) * *g);
      ++g;
   }

} /* OpticalFlow */
Example #23
0
VImage VCopyImagePixels (VImage src, VImage dest, VBand band)
{
  int npixels;
  VPointer src_pixels;
  VImage result;

  /* Locate the source and destination of the copy: */
  if (! VSelectBand ("VCopyImagePixels", src, band, & npixels, & src_pixels))
    return NULL;
  result = VSelectDestImage ("VCopyImagePixels", dest,
			     band == VAllBands ? VImageNBands (src) : 1,
			     VImageNRows (src), VImageNColumns (src),
			     VPixelRepn (src));
  if (! result)
    return NULL;

  /* Copy pixel values from src to dest: */
  memcpy (VImageData (result), src_pixels, npixels * VPixelSize (src));

  return result;
}
Example #24
0
Bild::Bild( QWidget *parent, const char *name, VImage src, VImage src1)
  : QWidget( parent, name ), src_m(src), src1_m(src1)


{
  //  if (DEBUGING) qWarning( tr("initialize view %1").arg(typ) );
  
  setPalette( QPalette( QColor( 0,0,0) ) );
  QWidget::setMouseTracking ( TRUE );

  effect_m=VImageNRows(src_m);
  scan_m=VImageNColumns(src_m);

  for (int i=0; i<effect_m; i++) {
    for (int j=0; j<scan_m; j++) {
      if (VPixel(src1_m,0,i,j,VFloat) > maxwert) maxwert=VPixel(src1_m,0,i,j,VFloat);
      else if (VPixel(src1_m,0,i,j,VFloat) < minwert) minwert=VPixel(src1_m,0,i,j,VFloat);
    }
  }  

  colorMap(); 
}
Example #25
0
VImage
VSConvolveRow (VImage src,VImage dest,VImage kernel)
{
  int b,r,c,nbands,nrows,ncols;
  int r0,r1,rr;
  float sum,x;
  VFloat *float_pp;
  int d,dim;

  dim = VImageNColumns(kernel);
  d = dim/2;

  nrows  = VImageNRows (src);
  ncols  = VImageNColumns (src);
  nbands = VImageNBands (src);

  dest = VSelectDestImage("VConvolveRow",dest,nbands,nrows,ncols,VFloatRepn);

  for (b=0; b<nbands; b++) {
    for (r=d; r<nrows-d; r++) {
      for (c=0; c<ncols; c++) {

	float_pp = (VFloat *) VImageData(kernel);
	sum = 0;
	r0 = r-d;
	r1 = r+d;
	if (r0 < 0) r0 = 0;
	if (r1 >= nrows) r1 = nrows-1;
	for (rr=r0; rr<=r1; rr++) {
	  x = VPixel(src,b,rr,c,VFloat);
	  sum += x * (*float_pp++);
	}
	VPixel(dest,b,r,c,VFloat) = sum;
      }
    }
  }
  return dest;
}
Example #26
0
VImage
VSConvolveCol (VImage src,VImage dest,VImage kernel)
{
  int b,r,c,nbands,nrows,ncols;
  int c0,c1,cc;
  float sum,x;
  VFloat *float_pp;
  int dim,d;

  nrows  = VImageNRows (src);
  ncols  = VImageNColumns (src);
  nbands = VImageNBands (src);

  dest = VSelectDestImage("VConvolveCol",dest,nbands,nrows,ncols,VFloatRepn);
  VFillImage(dest,VAllBands,0);
  dim  = VImageNColumns(kernel);
  d    = dim/2;

  for (b=0; b<nbands; b++) {
    for (r=0; r<nrows; r++) {
      for (c=d; c<ncols-d; c++) {

	float_pp = (VFloat *) VImageData(kernel);
	sum = 0;
	c0 = c-d;
	c1 = c+d;
	if (c0 < 0) c0 = 0;
	if (c1 >= ncols) c1 = ncols-1;
	for (cc=c0; cc<=c1; cc++) {
	  x = VPixel(src,b,r,cc,VFloat);
	  sum += x * (*float_pp++);
	}
	VPixel(dest,b,r,c,VFloat) = sum;
      }
    }
  }
  return dest;
}
Example #27
0
VImage
VSConvolveBand (VImage src,VImage dest,VImage kernel)
{
  int b,r,c,nbands,nrows,ncols;
  int b0,b1,bb;
  float sum,x;
  VFloat *float_pp;
  int d,dim;

  dim = VImageNColumns(kernel);
  d = dim/2;

  nrows  = VImageNRows (src);
  ncols  = VImageNColumns (src);
  nbands = VImageNBands (src);

  dest = VSelectDestImage("VConvolveBand",dest,nbands,nrows,ncols,VFloatRepn);

  for (b=d; b<nbands-d; b++) {
    for (r=0; r<nrows; r++) {
      for (c=0; c<ncols; c++) {

	float_pp = (VFloat *) VImageData(kernel);
	sum = 0;
	b0 = b-d;
	b1 = b+d;
	if (b0 < 0) b0 = 0;
	if (b1 >= nbands) b1 = nbands-1;
	for (bb=b0; bb<=b1; bb++) {
	  x = VPixel(src,bb,r,c,VFloat);
	  sum += x * (*float_pp++);
	}
	VPixel(dest,b,r,c,VFloat) = sum;
      }
    }
  }
  return dest;
}
Example #28
0
void Bild::mouseMoveEvent( QMouseEvent *e ) {
  int x = e->pos().x();
  int y = e->pos().y();
  int xx, yy;
  double ausgabe=0;
  //  if (x>)
  if ( x >= 80 && x <= width()-20 && y >= 30 && y <= height()-20 ) {
    setCursor( crossCursor );
    xx = (int)( (double)(x-80)/(double)(width()-100)*effect_m );
    yy = (int)( (double)(y-30)/(double)(height()-50)*scan_m );
    if (xx<VImageNRows(src_m) && yy<VImageNColumns(src_m))
      ausgabe = VPixel(src_m,0,xx,yy,VFloat);
    else
      ausgabe=0;
    if ( ausgabe < 0.0001 && ausgabe > -0.0001 ) ausgabe=0.0;
  } else {
    setCursor( pointingHandCursor );
    xx = 0;
    yy = 0;
    ausgabe=0.0;
  }
  emit wertView(ausgabe);
}
Example #29
0
VImage VCombineBandsVa (VImage dest, ...)
{
  va_list args;
  VImage src, result;
  int nbands;
  VBand src_band, dest_band;

  /* Count the number of bands to be combined: */
  va_start (args, dest);
  for (nbands = 0; (src = va_arg (args, VImage)) != 0; nbands +=
	 (va_arg (args, VBand) == VAllBands) ? VImageNBands (src) : 1) ;
  va_end (args);

  /* Check or allocate the destination image: */
  va_start (args, dest);
  src = va_arg (args, VImage);
  va_end (args);
  result = VSelectDestImage ("VCombineBandsVa", dest, nbands,
			     VImageNRows (src), VImageNColumns (src),
			     VPixelRepn (src));
  if (! result)
    return NULL;

  /* Copy each source band into the destination image: */
  va_start (args, dest);
  for (dest_band = 0; (src = va_arg (args, VImage)) != 0; ) {
    src_band = va_arg (args, VBand);
    if (! VCopyBand (src, src_band, result, dest_band)) {
      if (result != dest)
	VDestroyImage (result);
      return NULL;
    }
    dest_band += (src_band == VAllBands) ? VImageNBands (src) : 1;
  }
  va_end (args);
  return result;
}
Example #30
0
static VAttrList VImageEncodeAttrMethod (VPointer value, size_t *lengthp)
{
  VImage image = value;
  VAttrList list;
  size_t length;

#define OptionallyPrepend(value, name)				\
	if (value != 1)							\
	    VPrependAttr (list, name, NULL, VLongRepn, (VLong) value)

  /* Temporarily prepend several attributes to the image's attribute list: */
  if ((list = VImageAttrList (image)) == NULL)
    list = VImageAttrList (image) = VCreateAttrList ();
  VPrependAttr (list, VRepnAttr, VNumericRepnDict,
		VLongRepn, (VLong) VPixelRepn (image));
  VPrependAttr (list, VNColumnsAttr, NULL,
		VLongRepn, (VLong) VImageNColumns (image));
  VPrependAttr (list, VNRowsAttr, NULL,
		VLongRepn, (VLong) VImageNRows (image));
  OptionallyPrepend (VImageNComponents (image), VNComponentsAttr);
  OptionallyPrepend (VImageNColors (image), VNColorsAttr);
  OptionallyPrepend (VImageNViewpoints (image), VNViewpointsAttr);
  OptionallyPrepend (VImageNFrames (image), VNFramesAttr);
  OptionallyPrepend (VImageNBands (image), VNBandsAttr);

  /* Compute the file space needed for the image's binary data: */
  length = VImageNPixels (image);
  if (VPixelRepn (image) == VBitRepn)
    length = (length + 7) / 8;
  else length *= VPixelPrecision (image) / 8;
  *lengthp = length;

  return list;

#undef OptionallyPrepend
}