/** * im_tone_analyse: * @in: input image * @out: output image * @Ps: shadow point (eg. 0.2) * @Pm: mid-tone point (eg. 0.5) * @Ph: highlight point (eg. 0.8) * @S: shadow adjustment (+/- 30) * @M: mid-tone adjustment (+/- 30) * @H: highlight adjustment (+/- 30) * * As im_tone_build(), but analyse the histogram of @in and use it to * pick the 0.1% and 99.9% points for @Lb and @Lw. * * See also: im_tone_build(). * * Returns: 0 on success, -1 on error */ int im_tone_analyse( IMAGE *in, IMAGE *out, double Ps, double Pm, double Ph, double S, double M, double H ) { IMAGE *t[4]; int low, high; double Lb, Lw; if( im_open_local_array( out, t, 4, "im_tone_map", "p" ) ) return( -1 ); /* If in is IM_CODING_LABQ, unpack. */ if( in->Coding == IM_CODING_LABQ ) { if( im_LabQ2LabS( in, t[0] ) ) return( -1 ); } else t[0] = in; /* Should now be 3-band short. */ if( im_check_uncoded( "im_tone_analyse", t[0] ) || im_check_bands( "im_tone_analyse", t[0], 3 ) || im_check_format( "im_tone_analyse", t[0], IM_BANDFMT_SHORT ) ) return( -1 ); if( im_extract_band( t[0], t[1], 0 ) || im_clip2fmt( t[1], t[2], IM_BANDFMT_USHORT ) || im_histgr( t[2], t[3], -1 ) ) return( -1 ); if( im_mpercent_hist( t[3], 0.1 / 100.0, &high ) || im_mpercent_hist( t[3], 99.9 / 100.0, &low ) ) return( -1 ); Lb = 100 * low / 32768; Lw = 100 * high / 32768; im_diag( "im_tone_analyse", "set Lb = %g, Lw = %g", Lb, Lw ); return( im_tone_build( out, Lb, Lw, Ps, Pm, Ph, S, M, H ) ); }
/** * im_mpercent: * @in: input image * @percent: threshold percentage * @out: output threshold value * * im_mpercent() returns (through the @out parameter) the threshold above * which there are @percent values of @in. If for example percent=.1, the * number of pels of the input image with values greater than the returned * int will correspond to 10% of all pels of the image. * * The function works for uchar and ushort images only. It can be used * to threshold the scaled result of a filtering operation. * * See also: im_histgr(), im_profile(). * * Returns: 0 on success, -1 on error */ int im_mpercent( IMAGE *in, double percent, int *out ) { IMAGE *t; if( !(t = im_open( "im_mpercent1", "p" )) ) return( -1 ); if( im_histgr( in, t, -1 ) || im_mpercent_hist( t, percent, out ) ) { im_close( t ); return( -1 ); } im_close( t ); return( 0 ); }