/** * im_hsp: * @in: input image * @ref: reference histogram * @out: output image * * Maps image @in to image @out, adjusting the histogram to match image @ref. * Both images should have the same number of bands. * * See also: im_histspec(), im_histgr(). * * Returns: 0 on success, -1 on error */ int im_hsp( IMAGE *in, IMAGE *ref, IMAGE *out ) { IMAGE *t[3]; if( im_open_local_array( out, t, 3, "im_hsp", "p" ) || im_histgr( in, t[0], -1 ) || im_histgr( ref, t[1], -1 ) || im_histspec( t[0], t[1], t[2] ) || im_maplut( in, out, t[2] ) ) return( -1 ); return( 0 ); }
/** * im_hist: * @in: input image * @out: output image * @bandno: band to plot * * Find and plot the histogram of @in. If @bandno is -1, plot all bands. * Otherwise plot the specified band. * * See also: im_histgr(), im_histplot(). * * Returns: 0 on success, -1 on error */ int im_hist( IMAGE *in, IMAGE *out, int bandno ) { IMAGE *hist; if( !(hist = im_open_local( out, "im_hist", "p" )) || im_histgr( in, hist, bandno ) || im_histplot( hist, out ) ) return( -1 ); return( 0 ); }
/** * im_heq: * @in: input image * @out: output image * @bandno: band to equalise * * Histogram-equalise @in. Equalise using band @bandno, or if @bandno is -1, * equalise all bands. * * See also: im_lhisteq(), im_histgr(), im_histeq(). * * Returns: 0 on success, -1 on error */ int im_heq( IMAGE *in, IMAGE *out, int bandno ) { IMAGE *t[2]; if( im_open_local_array( out, t, 2, "im_heq", "p" ) || im_histgr( in, t[0], bandno ) || im_histeq( t[0], t[1] ) || im_maplut( in, out, t[1] ) ) return( -1 ); return( 0 ); }
int im_heq( IMAGE *in, IMAGE *out, int bandno ) { IMAGE *t1 = im_open_local( out, "im_heq:1", "p" ); IMAGE *t2 = im_open_local( out, "im_heq:2", "p" ); if( !t1 || !t2 || im_histgr( in, t1, bandno ) || im_histeq( t1, t2 ) || im_maplut( in, out, t2 ) ) return( -1 ); return( 0 ); }
/** * 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 ); }
VALUE img_histgr(int argc, VALUE *argv, VALUE obj) { VALUE v_bandno; int bandno; GetImg(obj, data, im); OutImg(obj, new, data_new, im_new); rb_scan_args(argc, argv, "01", &v_bandno); bandno = NIL_P(v_bandno) ? -1 : NUM2INT(v_bandno); if (im_histgr(im, im_new, bandno)) vips_lib_error(); return new; }
/** * 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 ) ); }