/** * im_ismonotonic: * @lut: lookup-table to test * @out: set non-zero if @lut is monotonic * * Test @lut for monotonicity. @out is set non-zero if @lut is monotonic. * * See also: im_tone_build_range(). * * Returns: 0 on success, -1 on error */ int im_ismonotonic( IMAGE *lut, int *out ) { IMAGE *t[2]; INTMASK *mask; double m; if( im_check_hist( "im_ismonotonic", lut ) || im_open_local_array( lut, t, 2, "im_ismonotonic", "p" ) ) return( -1 ); if( lut->Xsize == 1 ) mask = im_create_imaskv( "im_ismonotonic", 1, 2, -1, 1 ); else mask = im_create_imaskv( "im_ismonotonic", 2, 1, -1, 1 ); if( !(mask = im_local_imask( lut, mask )) ) return( -1 ); mask->offset = 128; /* We want >=128 everywhere, ie. no -ve transitions. */ if( im_conv( lut, t[0], mask ) || im_moreeqconst( t[0], t[1], 128 ) || im_min( t[1], &m ) ) return( -1 ); *out = m; return( 0 ); }
/* Normalise an image using the rules noted above. */ static int normalise( IMAGE *in, IMAGE *out ) { if( im_check_uncoded( "im_histplot", in ) || im_check_noncomplex( "im_histplot", in ) ) return( -1 ); if( vips_bandfmt_isuint( in->BandFmt ) ) { if( im_copy( in, out ) ) return( -1 ); } else if( vips_bandfmt_isint( in->BandFmt ) ) { IMAGE *t1; double min; /* Move min up to 0. */ if( !(t1 = im_open_local( out, "im_histplot", "p" )) || im_min( in, &min ) || im_lintra( 1.0, in, -min, t1 ) ) return( -1 ); } else { /* Float image: scale min--max to 0--any. Output square * graph. */ IMAGE *t1; DOUBLEMASK *stats; double min, max; int any; if( in->Xsize == 1 ) any = in->Ysize; else any = in->Xsize; if( !(stats = im_stats( in )) ) return( -1 ); min = VIPS_MASK( stats, 0, 0 ); max = VIPS_MASK( stats, 1, 0 ); im_free_dmask( stats ); if( !(t1 = im_open_local( out, "im_histplot", "p" )) || im_lintra( any / (max - min), in, -min * any / (max - min), out ) ) return( -1 ); } return( 0 ); }