move im_dif_std() to almostdeprecated

im_dif_std() is another ancient function which I don't want to update.
You can now make this function with a simple combination of other vips
operations.

This patch includes gtk-doc for im_benchamrk.c
This commit is contained in:
John Cupitt 2011-02-01 13:27:50 +00:00
parent 117a5fedcf
commit 390fd643a3
11 changed files with 91 additions and 896 deletions

View File

@ -17,6 +17,8 @@
- im_fits2vips() is lazy and much faster
- im__file_open_write() / _read() has a flag for text_mode, get rid of all the
remaining fopen()s
- move cooc_* and glds_* to deprecated
- move im_dif_std() to almostdeprecated
30/11/10 started 7.24.0
- bump for new stable

View File

@ -2,6 +2,7 @@ noinst_LTLIBRARIES = libdeprecated.la
libdeprecated_la_SOURCES = \
deprecated_dispatch.c \
im_dif_std.c \
cooc_funcs.c \
glds_funcs.c \
im_fav4.c \

View File

@ -50,6 +50,43 @@
#include <dmalloc.h>
#endif /*WITH_DMALLOC*/
static int
im__mean_std_int_buffer( int *buffer, int size,
double *pmean, double *pstd )
{
double mean, std;
register int i;
int sumf;
int temp;
int *pbuffer;
int sumf2;
double correction; /* calulates the correction term for the variance */
double variance; /* = (sumf2 - correction)/n */
if (size <= 0) {
im_error( "im_mean_std_int_buffer", "%s", _( "wrong args") );
return(-1);
}
mean = 0.0; std = 0.0;
sumf = 0; sumf2 = 0;
pbuffer = buffer;
for (i=0; i<size; i++) {
temp = *pbuffer++;
sumf += temp;
sumf2 += (temp*temp);
}
correction = ((double)(sumf * sumf))/((double)size);
mean = ((double)sumf)/((double)size);
variance = ( sumf2 - correction)/((double)size);
std = sqrt(variance);
*pmean = mean;
*pstd = std;
return(0);
}
int im_dif_std(im, xpos, ypos, xsize, ysize, dx, dy, pmean, pstd)
IMAGE *im;
int xpos, ypos, xsize, ysize; /* location of the box within im */

View File

@ -151,6 +151,22 @@ int im_render( IMAGE *in, IMAGE *out, IMAGE *mask,
int width, int height, int max,
void (*notify)( IMAGE *, Rect *, void * ), void *client );
int im_cooc_matrix( IMAGE *im, IMAGE *m,
int xp, int yp, int xs, int ys, int dx, int dy, int flag );
int im_cooc_asm( IMAGE *m, double *asmoment );
int im_cooc_contrast( IMAGE *m, double *contrast );
int im_cooc_correlation( IMAGE *m, double *correlation );
int im_cooc_entropy( IMAGE *m, double *entropy );
int im_glds_matrix( IMAGE *im, IMAGE *m,
int xpos, int ypos, int xsize, int ysize, int dx, int dy );
int im_glds_asm( IMAGE *m, double *asmoment );
int im_glds_contrast( IMAGE *m, double *contrast );
int im_glds_entropy( IMAGE *m, double *entropy );
int im_glds_mean( IMAGE *m, double *mean );
int im_dif_std();
/* Renamed operations.
*/

View File

@ -49,20 +49,6 @@ int im_make_xy( IMAGE *out, const int xsize, const int ysize );
int im_benchmarkn( IMAGE *in, IMAGE *out, int n );
int im_benchmark2( IMAGE *in, double *out );
int im_cooc_matrix( IMAGE *im, IMAGE *m,
int xp, int yp, int xs, int ys, int dx, int dy, int flag );
int im_cooc_asm( IMAGE *m, double *asmoment );
int im_cooc_contrast( IMAGE *m, double *contrast );
int im_cooc_correlation( IMAGE *m, double *correlation );
int im_cooc_entropy( IMAGE *m, double *entropy );
int im_glds_matrix( IMAGE *im, IMAGE *m,
int xpos, int ypos, int xsize, int ysize, int dx, int dy );
int im_glds_asm( IMAGE *m, double *asmoment );
int im_glds_contrast( IMAGE *m, double *contrast );
int im_glds_entropy( IMAGE *m, double *entropy );
int im_glds_mean( IMAGE *m, double *mean );
int im_simcontr( IMAGE *image, int xs, int ys );
int im_sines( IMAGE *image,
int xsize, int ysize, double horfreq, double verfreq );

View File

@ -1,14 +1,10 @@
noinst_LTLIBRARIES = libother.la
libother_la_SOURCES = \
cooc_funcs.c \
glds_funcs.c \
im_benchmark.c \
im_dif_std.c \
im_eye.c \
im_grey.c \
im_make_xy.c \
im_meanstd.c \
im_simcontr.c \
im_sines.c \
im_spatres.c \

View File

@ -1,474 +0,0 @@
/* @(#) Calculates the cooccurrence matrix of an image and some of its
* @(#) features. The 256x256 cooccurrence matrix of im is held by m
* @(#) There should be enough margin around the box so the (dx,dy) can
* @(#) access neighbouring pixels outside the box
* @(#)
* @(#) Usage:
* @(#) int im_cooc_matrix(im, m, xpos, ypos, xsize, ysize, dx, dy, sym_flag)
* @(#) IMAGE *im, *m;
* @(#) int xpos, ypos, xsize, ysize; location of the box within im
* @(#) int dx, dy; displacements
* @(#) int sym_flag;
* @(#)
* @(#) int im_cooc_asm(m, asmoment)
* @(#) IMAGE *m;
* @(#) double *asmoment;
* @(#)
* @(#) int im_cooc_contrast(m, contrast)
* @(#) IMAGE *m;
* @(#) double *contrast;
* @(#)
* @(#) int im_cooc_correlation(m, correlation)
* @(#) IMAGE *m;
* @(#) double *correlation;
* @(#)
* @(#) int im_cooc_entropy(m, entropy)
* @(#) IMAGE *m;
* @(#) double *entropy;
* @(#)
* @(#) All functions return 0 on success and -1 on error
*
* Copyright: N. Dessipris 1991
* Written on: 2/12/1991
* Updated on: 2/12/1991
* 22/7/93 JC
* - extern decls removed
* - im_incheck() calls added
* 28/5/97 JC
* - protos added :(
*/
/*
This file is part of VIPS.
VIPS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vips/vips.h>
#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif /*WITH_DMALLOC*/
static
int im_cooc_sym(im, m, xpos, ypos, xsize, ysize, dx, dy)
IMAGE *im, *m;
int xpos, ypos, xsize, ysize; /* location of the box within im */
int dx, dy; /* displacements */
{
PEL *input, *cpinput;
int *buf, *pnt, *cpnt;
double *line, *cpline;
int x, y;
int offset;
int bufofst;
int tempA, tempB;
int norm;
if (im_iocheck(im, m) == -1)
return( -1 );
if ((im->Bands != 1)||(im->BandFmt != IM_BANDFMT_UCHAR)) {
im_error( "im_cooc_sym", "%s", _( "Unable to accept input") );
return(-1);
}
if ( (xpos + xsize + dx > im->Xsize)|| (ypos + ysize + dy > im->Ysize) ) {
im_error( "im_cooc_sym", "%s", _( "wrong args") );
return(-1); }
if (im_cp_desc(m, im) == -1)
return( -1 );
m->Xsize = 256;
m->Ysize = 256;
m->BandFmt = IM_BANDFMT_DOUBLE;
m->Type = IM_TYPE_B_W;
if (im_setupout(m) == -1)
return( -1 );
/* malloc space to keep the read values */
buf = (int *)calloc( (unsigned)m->Xsize*m->Ysize, sizeof(int) );
line = (double *)calloc( (unsigned)m->Xsize * m->Bands, sizeof(double));
if ( (buf == NULL) || (line == NULL) ) {
im_error( "im_cooc_sym", "%s", _( "calloc failed") );
return(-1); }
input = (PEL*)im->data;
input += ( ypos * im->Xsize + xpos );
offset = dy * im->Xsize + dx;
for ( y=0; y<ysize; y++ )
{
cpinput = input;
input += im->Xsize;
for ( x=0; x<xsize; x++ )
{
tempA = (int)(*cpinput);
tempB = (int)(*(cpinput + offset));
bufofst = tempA + m->Xsize * tempB;
(*(buf + bufofst))++;
bufofst = tempB + m->Xsize * tempA;
(*(buf + bufofst))++;
cpinput++;
}
}
norm = xsize * ysize * 2;
pnt = buf;
for ( y=0; y<m->Ysize; y++ )
{
cpnt = pnt;
pnt += m->Xsize;
cpline = line;
for (x=0; x<m->Xsize; x++)
*cpline++ = (double)(*cpnt++)/(double)norm;
if (im_writeline( y, m, (PEL *) line ) == -1)
{
im_error( "im_cooc_sym", "%s", _( "unable to im_writeline") );
return(-1);
}
}
free((char*)buf);
free((char*)line);
return(0);
}
static
int im_cooc_ord(im, m, xpos, ypos, xsize, ysize, dx, dy)
IMAGE *im, *m;
int xpos, ypos, xsize, ysize; /* location of the box within im */
int dx, dy; /* displacements */
{
PEL *input, *cpinput;
int *buf, *pnt, *cpnt;
double *line, *cpline;
int x, y;
int offset;
int bufofst;
int tempA, tempB;
int norm;
if (im_iocheck(im, m) == -1)
return( -1 );
if ((im->Bands != 1)||(im->BandFmt != IM_BANDFMT_UCHAR))
{
im_error( "im_cooc_ord", "%s", _( "Unable to accept input") );
return(-1);
}
if ( (xpos + xsize + dx > im->Xsize)|| (ypos + ysize + dy > im->Ysize) ) {
im_error( "im_cooc_ord", "%s", _( "wrong args") );
return(-1); }
if (im_cp_desc(m, im) == -1)
return( -1 );
m->Xsize = 256;
m->Ysize = 256;
m->BandFmt = IM_BANDFMT_DOUBLE;
if (im_setupout(m) == -1)
return( -1 );
/* malloc space to keep the read values */
buf = (int *)calloc( (unsigned)m->Xsize*m->Ysize, sizeof(int) );
line = (double *)calloc( (unsigned)m->Xsize * m->Bands, sizeof(double));
if ( (buf == NULL) || (line == NULL) ) {
im_error( "im_cooc_ord", "%s", _( "calloc failed") );
return(-1); }
input = (PEL*)im->data;
input += ( ypos * im->Xsize + xpos );
offset = dy * im->Xsize + dx;
for ( y=0; y<ysize; y++ )
{
cpinput = input;
input += im->Xsize;
for ( x=0; x<xsize; x++ )
{
tempA = (int)(*cpinput);
tempB = (int)(*(cpinput + offset));
bufofst = tempA + m->Xsize * tempB;
(*(buf + bufofst))++;
cpinput++;
}
}
norm = xsize * ysize;
pnt = buf;
for ( y=0; y<m->Ysize; y++ )
{
cpnt = pnt;
pnt += m->Xsize;
cpline = line;
for (x=0; x<m->Xsize; x++)
*cpline++ = (double)(*cpnt++)/(double)norm;
if (im_writeline( y, m, (PEL *) line ) == -1)
{
im_error( "im_cooc_ord", "%s", _( "unable to im_writeline") );
return(-1);
}
}
free((char*)buf);
free((char*)line);
return(0);
}
/* Keep the coocurrence matrix as a 256x256x1 double image */
int
im_cooc_matrix( IMAGE *im, IMAGE *m,
int xp, int yp, int xs, int ys, int dx, int dy, int flag )
{
if (flag == 0)
return( im_cooc_ord(im, m, xp, yp, xs, ys, dx, dy) );
else if (flag == 1) /* symmetrical cooc */
return( im_cooc_sym(im, m, xp, yp, xs, ys, dx, dy) );
else {
im_error( "im_cooc_matrix", "%s", _( "wrong flag!") );
return(-1); }
}
/* Calculate contrast, asmoment, entropy and correlation
*/
int
im_cooc_asm( IMAGE *m, double *asmoment )
{
double temp, tmpasm, *pnt;
int i;
if( im_incheck( m ) )
return( -1 );
if (m->Xsize != 256 || m->Ysize != 256 ||
m->Bands != 1 || m->BandFmt != IM_BANDFMT_DOUBLE)
{
im_error( "im_cooc_asm", "%s", _( "unable to accept input") );
return(-1);
}
tmpasm = 0.0;
pnt = (double*)m->data;
for(i=0; i<m->Xsize * m->Ysize; i++)
{
temp = *pnt++;
tmpasm += temp * temp;
}
*asmoment = tmpasm;
return(0);
}
int
im_cooc_contrast( IMAGE *m, double *contrast )
{
double dtemp, tmpcon, *pnt, *cpnt;
int x, y;
if( im_incheck( m ) )
return( -1 );
if (m->Xsize != 256 || m->Ysize != 256 ||
m->Bands != 1 || m->BandFmt != IM_BANDFMT_DOUBLE)
{
im_error( "im_cooc_contrast", "%s", _( "unable to accept input") );
return(-1);
}
tmpcon = 0.0;
pnt = (double*)m->data;
for(y=0; y<m->Ysize; y++)
{
cpnt = pnt;
pnt += m->Xsize;
for(x=0; x<m->Xsize; x++)
{
dtemp = (double)( (y-x)*(y-x) );
tmpcon += dtemp * (*cpnt);
cpnt++;
}
}
*contrast = tmpcon;
return(0);
}
static void
stats(buffer, size, pmean, pstd)
double *buffer; /* buffer contains the frequency distributions f[i] */
int size; /* Note that sum(f[i]) = 1.0 and that the */
/* cooccurence matrix is symmetrical */
double *pmean, *pstd;
{
double mean, std;
register int i;
double sumf; /* calculates the sum of f[i] */
double temp; /* temporary variable */
double *pbuffer;
double sumf2; /* calculates the sum of f[i]^2 */
double correction; /* calulates the correction term for the variance */
double variance; /* = (sumf2 - correction)/n, n=sum(f[i]) = 1 */
mean = 0.0; std = 0.0;
sumf = 0.0; sumf2 = 0.0;
pbuffer = buffer;
for (i=0; i<size; i++)
{
temp = *pbuffer++;
sumf += (temp*i);
sumf2 += (temp*i*i);
}
correction = sumf*sumf;
mean = sumf;
variance = sumf2-correction;
std = sqrt(variance);
*pmean = mean;
*pstd = std;
}
int
im_cooc_correlation( IMAGE *m, double *correlation )
{
double mcol, stdcol, mrow, stdrow; /* mean and std of cols and rows */
double *pbuf;
double *cpbuf;
double dtemp;
register int i,j;
double *row; /* Keeps the sum of rows entries as double */
double *col; /* Keeps the sum of cols entries as double */
double tmpcor=0.0;
double sum = 0.0;
if( im_incheck( m ) )
return( -1 );
if (m->Xsize != 256 || m->Ysize != 256 ||
m->Bands != 1 || m->BandFmt != IM_BANDFMT_DOUBLE)
{
im_error( "im_cooc_correlation", "%s", _( "unable to accept input") );
return(-1);
}
row = (double*)calloc( (unsigned)m->Ysize, sizeof(double));
col = (double*)calloc( (unsigned)m->Xsize, sizeof(double));
if ( row == NULL || col == NULL )
{
im_error( "im_cooc_correlation", "%s", _( "unable to calloc") );
return(-1);
}
pbuf = (double*)m->data;
for(j=0; j<m->Ysize; j++)
{
cpbuf = pbuf;
pbuf += m->Xsize;
sum=0.0;
for(i=0; i<m->Xsize; i++)
sum += *cpbuf++;
*(row+j) = sum;
}
pbuf = (double*)m->data;
for(j=0; j<m->Ysize; j++)
{
cpbuf = pbuf;
pbuf++;
sum=0.0;
for(i=0; i<m->Xsize; i++)
{
sum += *cpbuf;
cpbuf += m->Xsize;
}
*(col+j) = sum;
}
stats(row, m->Ysize, &mrow, &stdrow);
stats(col, m->Ysize ,&mcol, &stdcol);
#ifdef DEBUG
fprintf(stderr, "rows: mean=%f std=%f\ncols: mean=%f std=%f\n",
mrow, stdrow, mcol, stdcol);
#endif
tmpcor = 0.0;
pbuf = (double*)m->data;
for(j=0; j<m->Ysize; j++)
{
cpbuf = pbuf;
pbuf += m->Xsize;
for(i=0; i<m->Xsize; i++)
{
dtemp = *cpbuf;
tmpcor += ( ((double)i)*((double)j)*dtemp);
cpbuf++;
}
}
#ifdef DEBUG
fprintf(stderr, "tmpcor=%f\n", tmpcor);
#endif
if ( (stdcol==0.0)||(stdrow==0) )
{
im_error( "im_cooc_correlation", "%s", _( "zero std") );
return(-1);
}
tmpcor = (tmpcor-(mcol*mrow))/(stdcol*stdrow);
*correlation = tmpcor;
free((char*)row); free((char*)col);
return(0);
}
int
im_cooc_entropy( IMAGE *m, double *entropy )
{
double *pbuf, *pbufstart;
double *cpbuf;
register int i,j;
double tmpent, dtemp;
double val;
if( im_incheck( m ) )
return( -1 );
if (m->Xsize != 256 || m->Ysize != 256 ||
m->Bands != 1 || m->BandFmt != IM_BANDFMT_DOUBLE)
{
im_error( "im_cooc_entropy", "%s", _( "unable to accept input") );
return(-1);
}
pbufstart = (double*)m->data;
tmpent = 0.0;
pbuf = pbufstart;
for(j=0; j<m->Ysize; j++)
{
cpbuf = pbuf;
pbuf += m->Xsize;
for(i=0; i<m->Xsize; i++)
{
if(*cpbuf != 0)
{
dtemp = *cpbuf;
tmpent += (dtemp*log10(dtemp));
}
cpbuf++;
}
}
val = tmpent*(-1);
#ifdef DEBUG
fprintf(stderr,"ENT=%f\nwhich is %f bits\n", val, val/log10(2.0) );
#endif
*entropy = (val/log10(2.0));
return(0);
}

View File

@ -1,256 +0,0 @@
/* @(#) Calculates the spatial grey level differnce
* @(#) matrix of an image and some of its
* @(#) features. The 256x1 difference matrix of im is held by m
* @(#) There should be enough margin around the box so the (dx,dy) can
* @(#) access neighbouring pixels outside the box
* @(#)
* @(#) Usage:
* @(#) int im_glds_matrix(im, m, xpos, ypos, xsize, ysize, dx, dy)
* @(#) IMAGE *im, *m;
* @(#) int xpos, ypos, xsize, ysize; location of the box within im
* @(#) int dx, dy; displacements
* @(#)
* @(#) int im_glds_asm(m, asmoment)
* @(#) IMAGE *m;
* @(#) double *asmoment;
* @(#)
* @(#) int im_glds_contrast(m, contrast)
* @(#) IMAGE *m;
* @(#) double *contrast;
* @(#)
* @(#) int im_glds_entropy(m, entropy)
* @(#) IMAGE *m;
* @(#) double *entropy;
* @(#)
* @(#) int im_glds_mean(m, mean)
* @(#) IMAGE *m;
* @(#) double *mean;
* @(#)
* @(#) All functions return 0 on success and -1 on error
*
* Copyright: N. Dessipris, 1991
* Written on: 2/12/1991
* Modified on:
* 22/7/93 JC
* - im_incheck() added
*/
/*
This file is part of VIPS.
VIPS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vips/vips.h>
#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif /*WITH_DMALLOC*/
/* Keep the greylevel difference matrix as a 256x1 double image */
int
im_glds_matrix( IMAGE *im, IMAGE *m,
int xpos, int ypos, int xsize, int ysize, int dx, int dy )
{
PEL *in, *cpin;
int *b, *pb;
double *l, *pl;
int x, y;
int ofs;
int tmp;
int norm;
if (im_iocheck(im, m) == -1)
return( -1 );
if ((im->Bands != 1)||(im->BandFmt != IM_BANDFMT_UCHAR)) {
im_error( "im_glds_matrix", "%s", _( "Wrong input") );
return(-1); }
if ( (xpos + xsize + dx > im->Xsize)|| (ypos + ysize + dy > im->Ysize) ) {
im_error( "im_glds_matrix", "%s", _( "wrong args") );
return(-1); }
if (im_cp_desc(m, im) == -1)
return( -1 );
m->Xsize = 256;
m->Ysize = 1;
m->BandFmt = IM_BANDFMT_DOUBLE;
m->Type = IM_TYPE_B_W;
if (im_setupout(m) == -1)
return( -1 );
b = (int *)calloc( (unsigned)m->Xsize, sizeof(int) );
l = (double *)calloc( (unsigned)m->Xsize, sizeof(double));
if ( (b == NULL) || (l == NULL) ) {
im_error( "im_glds_matrix", "%s", _( "calloc failed") );
return(-1); }
in = (PEL*)im->data;
in += ( ypos * im->Xsize + xpos );
ofs = dy * im->Xsize + dx;
for ( y=0; y<ysize; y++ )
{
cpin = in;
in += im->Xsize;
for ( x=0; x<xsize; x++ )
{
tmp = abs((int)*cpin - (int)(*(cpin+ofs)));
pb = (b + tmp);
(*pb)++;
cpin++;
}
}
norm = xsize * ysize;
pb = b;
pl = l;
for (x=0; x<m->Xsize; x++)
*pl++ = ((double)(*pb++))/(double)norm;
if (im_writeline( 0, m, (PEL *) l ) == -1)
return( -1 );
free((char*)b); free((char*)l);
return(0);
}
/* @(#) Calculates the asmoment of the sglds matrix held by m
*/
int
im_glds_asm( IMAGE *m, double *asmoment )
{
double temp, tmpasm, *in;
int i;
if( im_incheck( m ) )
return( -1 );
if (m->Xsize != 256 || m->Ysize != 1 ||
m->Bands != 1 || m->BandFmt != IM_BANDFMT_DOUBLE) {
im_error( "im_glds_asm", "%s", _( "unable to accept input") );
return(-1);}
tmpasm = 0.0;
in = (double*)m->data;
for(i=0; i<m->Xsize; i++)
{
temp = *in++;
tmpasm += (temp*temp);
}
*asmoment = tmpasm;
return(0);
}
/* @(#) Calculates the contrast of the coocurence matrix passed in buffer
*/
int
im_glds_contrast( IMAGE *m, double *contrast )
{
double tmpcon, *in;
int i;
if( im_incheck( m ) )
return( -1 );
if (m->Xsize != 256 || m->Ysize != 1 ||
m->Bands != 1 || m->BandFmt != IM_BANDFMT_DOUBLE) {
im_error( "im_glds_contrast", "%s", _( "wrong input") );
return(-1); }
tmpcon = 0.0;
in = (double*)m->data;
for(i=0; i<m->Xsize; i++)
{
tmpcon += ( ((double)i)*((double)i)*(*in) );
in++;
}
*contrast = tmpcon;
return(0);
}
/* @(#) Calculates the entropy of the glds vector passed in buffer
* @(#) Function returns the entropy based on log base 2.
*/
int
im_glds_entropy( IMAGE *m, double *entropy )
{
double tmpent, dtemp, *in;
int i;
if( im_incheck( m ) )
return( -1 );
if (m->Xsize != 256 || m->Ysize != 1 ||
m->Bands != 1 || m->BandFmt != IM_BANDFMT_DOUBLE) {
im_error( "im_glds_entropy", "%s", _( "wrong input") );
return(-1); }
tmpent = 0.0;
in = (double*)m->data;
for(i=0; i<m->Xsize; i++)
{
if(*in != 0)
{
dtemp = *in;
tmpent += (dtemp*log10(dtemp));
}
in++;
}
*entropy = ((-1)*tmpent/log10(2.0));
return(0);
}
/* @(#) Calculates the mean of the sglds matrix passed in m
*/
int
im_glds_mean( IMAGE *m, double *mean )
{
double tmpmean, *in;
int i;
if( im_incheck( m ) )
return( -1 );
if (m->Xsize != 256 || m->Ysize != 1 ||
m->Bands != 1 || m->BandFmt != IM_BANDFMT_DOUBLE) {
im_error( "im_glds_mean", "%s", _( "wrong input") );
return(-1); }
tmpmean = 0.0;
in = (double*)m->data;
for(i=0; i<m->Xsize; i++)
{
tmpmean += ( ((double)i)*(*in) );
in++;
}
tmpmean = tmpmean/((double)m->Xsize);
*mean = tmpmean;
return(0);
}

View File

@ -1,18 +1,11 @@
/* @(#) Do a complicated compound operation for benchmarking the threading
* @(#) system. Input should be a large LABQ image, output is a large sRGB
* @(#) image.
* @(#)
* @(#) Usage:
* @(#)
* @(#) int im_benchmark( IMAGE *in, IMAGE *out )
* @(#)
* @(#) Returns 0 on sucess and -1 on error.
* @(#)
/* a complicated operation for testing
*
* 6/10/06
* - hacked in
* 27/11/06
* - added im_benchmarkn()
* 1/2/11
* - gtk-doc
*/
/*
@ -244,7 +237,23 @@ benchmark( IMAGE *in, IMAGE *out )
);
}
/* Chain n benchmarks together to get a CPU-bound operation.
/**
* im_benchmarkn:
* @in: input image
* @out: output image
* @n: iterations
*
* This operation runs a complicated set of other operations on image @in,
* producing image @out. Use @n to set the number of iterations to run: a
* larger number will make the operation more CPU-bound, a smaller number will
* make the operation more IO-bound.
*
* See http://www.vips.ecs.soton.ac.uk/index.php?title=Benchmarks for a
* detailed discussion of the benchmark and some sample results.
*
* See also: im_benchmark2().
*
* Returns: 0 on success, -1 on error
*/
int
im_benchmarkn( IMAGE *in, IMAGE *out, int n )
@ -274,6 +283,18 @@ im_benchmarkn( IMAGE *in, IMAGE *out, int n )
im_benchmarkn( t[1], out, n - 1 ) );
}
/**
* im_benchmark2:
* @in: input image
* @out: average image value
*
* This operation runs a single im_benchmarkn() and calculates the average
* pixel value. It's useful if you just want to test image input.
*
* See also: im_benchmarkn().
*
* Returns: 0 on success, -1 on error
*/
int
im_benchmark2( IMAGE *in, double *out )
{

View File

@ -1,136 +0,0 @@
/* @(#) Calculates the mean and the standard deviation (std) of
* @(#) an int or double buffer of size size.
* @(#)
* @(#) Usage:
* @(#) int im__mean_std_double_buffer(buffer, size, pmean, pstd)
* @(#) double *buffer;
* @(#) int size;
* @(#) double *pmean, *pstd;
* @(#)
* @(#) int im__mean_std_int_buffer(buffer, size, pmean, pstd)
* @(#) int *buffer;
* @(#) int size;
* @(#) double *pmean, *pstd;
* @(#)
* @(#) Both functions return 0 on success and -1 on error
*
* Copyright: N. Dessipris 1991
* Written on: 2/12/1991
* Updated on: 2/12/1991
* 22/7/93 JC
* - externs removed
*/
/*
This file is part of VIPS.
VIPS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vips/vips.h>
#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif /*WITH_DMALLOC*/
int
im__mean_std_double_buffer( double *buffer, int size,
double *pmean, double *pstd )
{
double mean, std;
register int i;
double sumf;
double temp;
double *pbuffer;
double sumf2;
double correction; /* calulates the correction term for the variance */
double variance; /* = (sumf2 - correction)/n */
if (size <= 0) {
im_error( "im_mean_std_double_buffer", "%s", _( "wrong args") );
return(-1);
}
mean = 0.0; std = 0.0;
sumf = 0.0; sumf2 = 0.0;
pbuffer = buffer;
for (i=0; i<size; i++) {
temp = *pbuffer++;
sumf += temp;
sumf2 += (temp*temp);
}
correction = (sumf * sumf)/((double)size);
mean = sumf/((double)size);
variance = ( sumf2 - correction)/((double)size);
std = sqrt(variance);
*pmean = mean;
*pstd = std;
return( 0 );
}
int
im__mean_std_int_buffer( int *buffer, int size,
double *pmean, double *pstd )
{
double mean, std;
register int i;
int sumf;
int temp;
int *pbuffer;
int sumf2;
double correction; /* calulates the correction term for the variance */
double variance; /* = (sumf2 - correction)/n */
if (size <= 0) {
im_error( "im_mean_std_int_buffer", "%s", _( "wrong args") );
return(-1);
}
mean = 0.0; std = 0.0;
sumf = 0; sumf2 = 0;
pbuffer = buffer;
for (i=0; i<size; i++) {
temp = *pbuffer++;
sumf += temp;
sumf2 += (temp*temp);
}
correction = ((double)(sumf * sumf))/((double)size);
mean = ((double)sumf)/((double)size);
variance = ( sumf2 - correction)/((double)size);
std = sqrt(variance);
*pmean = mean;
*pstd = std;
return(0);
}

View File

@ -48,8 +48,10 @@
* @stability: Stable
* @include: vips/vips.h
*
* Various small things.
* These functions generate various test images. You can combine them with
* the arithmetic and rotate functions to build more complicated images.
*
* The im_benchmark() operations are for testing the VIPS SMP system.
*/
/* Args for im_eye.