コード例 #1
0
static void
autovscale(DDLSymbolTable *st, float *vmin, float *vmax)
{
    int i;
    int n;
    float min;
    float max;

    // Find max and min values in the data
    int npts = (get_image_width(st) * get_image_height(st)
		* get_image_depth(st));
    get_min_max(st, &min, &max);

    // Get intensity distribution
    int nbins = 10000;
    int *histogram = new int[nbins];
    get_histogram(st, min, max, histogram, nbins);

    // Estimate percentile points from distribution
    int percentile = (int)(0.01 * npts);
    if (percentile < 1) percentile = 1;
    float scale = (nbins - 1) / (max - min);
    for (i=n=0; n<percentile && i<nbins; n += histogram[i++]);
    *vmin = min + (i-1) / scale;
    for (i=nbins, n=0; n<percentile && i>0; n += histogram[--i]);
    *vmax = min + i / scale;

    // Set vmin to 0 if it looks plausible
    if (*vmin > 0 && *vmin / *vmax < 0.05){
	*vmin = 0;
    }

    delete [] histogram;
}   
コード例 #2
0
ファイル: stdlib.c プロジェクト: grubbymits/esdg-opencl
int4 OVERLOAD get_image_dim(image3d_t image)
{
    int4 result;

    result.x = get_image_width(image);
    result.y = get_image_height(image);
    result.z = get_image_depth(image);
    result.w = 0;

    return result;
}
コード例 #3
0
static void
get_min_max(DDLSymbolTable *st, float *vmin, float *vmax)
{
    char *errmsg;
    int npts = (get_image_width(st) * get_image_height(st)
		* get_image_depth(st));
    int type = get_data_type(st, &errmsg);
    switch (type){
      case DDL_INT8:
	{
	    u_char *data = (u_char *)get_ddl_data(st);
	    u_char *end = data + npts;
	    u_char min = *data;
	    u_char max = *data++;
	    u_char x;
	    while (data < end){
		if ((x=*data++) < min){
		    min = x;
		}else if (x > max){
		    max = x;
		}
	    }
	    *vmin = (float)min;
	    *vmax = (float)max;
	}
	break;
      case DDL_INT16:
	{
	    u_short *data = (u_short *)get_ddl_data(st);
	    u_short *end = data + npts;
	    u_short min = *data;
	    u_short max = *data++;
	    u_short x;
	    while (data < end){
		if ((x=*data++) < min){
		    min = x;
		}else if (x > max){
		    max = x;
		}
	    }
	    *vmin = (float)min;
	    *vmax = (float)max;
	}
	break;
      case DDL_INT32:
	{
	    int *data = (int *)get_ddl_data(st);
	    int *end = data + npts;
	    int min = *data;
	    int max = *data++;
	    int x;
	    while (data < end){
		if ((x=*data++) < min){
		    min = x;
		}else if (x > max){
		    max = x;
		}
	    }
	    *vmin = (float)min;
	    *vmax = (float)max;
	}
	break;
      case DDL_FLOAT32:
	{
	    float *data = (float *)get_ddl_data(st);
	    float *end = data + npts;
	    float min = *data;
	    float max = *data++;
	    float x;
	    while (data < end){
		if ((x=*data++) < min){
		    min = x;
		}else if (x > max){
		    max = x;
		}
	    }
	    *vmin = (float)min;
	    *vmax = (float)max;
	}
	break;
      case DDL_FLOAT64:
	{
	    double *data = (double *)get_ddl_data(st);
	    double *end = data + npts;
	    double min = *data;
	    double max = *data++;
	    double x;
	    while (data < end){
		if ((x=*data++) < min){
		    min = x;
		}else if (x > max){
		    max = x;
		}
	    }
	    *vmin = (float)min;
	    *vmax = (float)max;
	}
	break;
    }
}
コード例 #4
0
static void
get_histogram(DDLSymbolTable *st, float min, float max,
	      int *histogram, int nbins)
{
    int i;
    char *errmsg;
    int npts = (get_image_width(st) * get_image_height(st)
		* get_image_depth(st));
    float scale = (nbins - 1) / (max - min);
    for (i=0; i<nbins; i++){
	histogram[i] = 0;
    }
    int type = get_data_type(st, &errmsg);
    switch (type){
      case DDL_INT8:
	{
	    u_char *data = (u_char *)get_ddl_data(st);
	    u_char *end = data + npts;
	    while (data < end){
		histogram[(int)((*data++ - min) * scale)]++;
	    }
	}
	break;
      case DDL_INT16:
	{
	    u_short *data = (u_short *)get_ddl_data(st);
	    u_short *end = data + npts;
	    while (data < end){
		histogram[(int)((*data++ - min) * scale)]++;
	    }
	}
	break;
      case DDL_INT32:
	{
	    int *data = (int *)get_ddl_data(st);
	    int *end = data + npts;
	    while (data < end){
		histogram[(int)((*data++ - min) * scale)]++;
	    }
	}
	break;
      case DDL_FLOAT32:
	{
	    float *data = (float *)get_ddl_data(st);
	    float *end = data + npts;
	    while (data < end){
		histogram[(int)((*data++ - min) * scale)]++;
	    }
	}
	break;
      case DDL_FLOAT64:
	{
	    double *data = (double *)get_ddl_data(st);
	    double *end = data + npts;
	    while (data < end){
		histogram[(int)((*data++ - min) * scale)]++;
	    }
	}
	break;
    }
}
コード例 #5
0
ファイル: mathproto.c プロジェクト: timburrow/ovj3
int
mathexpr(ParmList inparms, ParmList *outparms)
{
    float x, y, z;		/* User variables */
    float r[100];		/* Many user variables */
    int ii, jj, kk;		/* Integer user variables */
    int n[100];			/* Many integer user variables */

    int i, j, k;		/* Pixel position in row, column, depth */
    int width, height, depth;	/* Size of all images */
    int indx;			/* Running pixel number */

    char msg[128];
    DDLSymbolTable *st;
    DDLSymbolTable *out;
    float **img;		/* Vector of pointers to input data */
    float *iout;		/* Pointer to output data */
    int nsrcs;			/* Number of input images */
    ParmList src_ddls;
    ParmList dst_ddls;

    /*fprintf(stderr,"mathexpr(0x%x, 0x%x)\n", inparms, outparms);/*CMP*/
    /*printParm(inparms);/*CMP*/
    /* Grab the input args */
    src_ddls = findParm(inparms, "src_ddls");
    if (!src_ddls){
	ib_errmsg("MATH: \"src_ddls\" not passed");
	return FALSE;
    }
    nsrcs = countParm(src_ddls);
    img = (float **)malloc(nsrcs * sizeof(float *));
    fdfhandle = (DDLSymbolTable **)malloc(nsrcs * sizeof(DDLSymbolTable *));
    if (!img || !fdfhandle){
	ib_errmsg("MATH: out of memory");
	return FALSE;
    }

    /* Check image sizes */
    width = height = depth = 0;
    for (indx=0; indx<nsrcs; indx++){
	getPtrParm(src_ddls, &st, indx);
	i = get_image_width(st);
	j = get_image_height(st);
	k = get_image_depth(st);
	if (!i || !j){
	    sprintf(msg,"MATH: image size is %dx%d\n", i, j);
	    ib_errmsg(msg);
	    return FALSE;
	}
	if ((width && i != width)
	    || (height && j != height)
	    || (depth && k != depth))
	{
	    ib_errmsg("MATH: images are different sizes\n");
	    return FALSE;
	}
	width = i;
	height = j;
	depth = k;

	/* Point the working source image pointers to the appropriate data */
	img[indx] = get_ddl_data(st);
	fdfhandle[indx] = st;
    }
    /*fprintf(stderr,"MATH: width=%d, height=%d, depth=%d\n",
	    width, height, depth);/*DBG*/

    /* Copy the first input object (for storing the output image) */
    getPtrParm(src_ddls, &st, 0);
    out = clone_ddl(st, 1);
    /*fprintf(stderr,"MATH: out width=%d, data=0x%x, *data=%g\n",
	    get_image_width(out),
	    get_ddl_data(out), *get_ddl_data(out));/*CMP*/
    /*fprintf(stderr,"indata=0x%x, *indata=%g\n", img[0], img[0][0]);/*CMP*/
    iout = get_ddl_data(out);

    /*
     * NOTE: IB_EXPRESSION will be expanded into something like
     *		img[0][indx]+img[1][indx]
     */
    interrupt_begin();
    for (indx=k=0; k<depth; k++){
	for (j=0; j<height; j++){
	    for (i=0; i<width && !interrupt(); i++, indx++){
		iout[indx] = IB_EXPRESSION;
	    }
	}
    }
    interrupt_end();
    /*fprintf(stderr,"MATH: out width=%d, data=0x%x, *data=%g\n",
	    get_image_width(out),
	    get_ddl_data(out), *get_ddl_data(out));/*CMP*/

    /* Pass back the output image */
    *outparms = allocParm("dst_ddls", PL_PTR, 1);
    setPtrParm(*outparms, out, 0);

    return TRUE;
}