fix hist_norm range

the cast change broke hist_norm
This commit is contained in:
John Cupitt 2020-05-04 17:04:37 +01:00
parent 29d9fcb0c8
commit 8281416ca4
1 changed files with 8 additions and 7 deletions

View File

@ -77,7 +77,7 @@ vips_hist_norm_build( VipsObject *object )
VipsHistNorm *norm = (VipsHistNorm *) object; VipsHistNorm *norm = (VipsHistNorm *) object;
VipsImage **t = (VipsImage **) vips_object_local_array( object, 3 ); VipsImage **t = (VipsImage **) vips_object_local_array( object, 3 );
guint64 px; guint64 new_max;
int bands; int bands;
double *a, *b; double *a, *b;
int y; int y;
@ -95,13 +95,13 @@ vips_hist_norm_build( VipsObject *object )
/* Scale each channel by px / channel max /* Scale each channel by px / channel max
*/ */
px = VIPS_IMAGE_N_PELS( norm->in ); new_max = VIPS_IMAGE_N_PELS( norm->in ) - 1;
bands = norm->in->Bands; bands = norm->in->Bands;
if( !(a = VIPS_ARRAY( object, bands, double )) || if( !(a = VIPS_ARRAY( object, bands, double )) ||
!(b = VIPS_ARRAY( object, bands, double )) ) !(b = VIPS_ARRAY( object, bands, double )) )
return( -1 ); return( -1 );
for( y = 0; y < bands; y++ ) { for( y = 0; y < bands; y++ ) {
a[y] = px / *VIPS_MATRIX( t[0], 1, y + 1 ); a[y] = new_max / *VIPS_MATRIX( t[0], 1, y + 1 );
b[y] = 0; b[y] = 0;
} }
@ -110,9 +110,9 @@ vips_hist_norm_build( VipsObject *object )
/* Make output format as small as we can. /* Make output format as small as we can.
*/ */
if( px <= 256 ) if( new_max <= 255 )
fmt = VIPS_FORMAT_UCHAR; fmt = VIPS_FORMAT_UCHAR;
else if( px <= 65536 ) else if( new_max <= 65535 )
fmt = VIPS_FORMAT_USHORT; fmt = VIPS_FORMAT_USHORT;
else else
fmt = VIPS_FORMAT_UINT; fmt = VIPS_FORMAT_UINT;
@ -161,8 +161,9 @@ vips_hist_norm_init( VipsHistNorm *hist_norm )
* @out: (out): output image * @out: (out): output image
* @...: %NULL-terminated list of optional named arguments * @...: %NULL-terminated list of optional named arguments
* *
* Normalise histogram ... normalise range to make it square (ie. max == * Normalise histogram. The maximum of each band becomes equal to the maximum
* number of elements). Normalise each band separately. * index, so for example the max for a uchar image becomes 255.
* Normalise each band separately.
* *
* See also: vips_hist_cum(). * See also: vips_hist_cum().
* *