Пример #1
0
/**
 * im_tone_map:
 * @in: input image
 * @out: output image
 * @lut: look-up table
 *
 * Map the first channel of @in through @lut. If @in is IM_CODING_LABQ, unpack
 * to LABS, map L and then repack.
 *
 * @in should be a LABS or LABQ image for this to work
 * sensibly.
 *
 * See also: im_maplut().
 *
 * Returns: 0 on success, -1 on error
 */
int
im_tone_map( IMAGE *in, IMAGE *out, IMAGE *lut )
{
    IMAGE *t[8];

    if( im_check_hist( "im_tone_map", lut ) ||
            im_open_local_array( out, t, 8, "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;

    /* Split into bands.
     */
    if( im_extract_band( t[0], t[1], 0 ) )
        return( -1 );
    if( t[0]->Bands > 1 ) {
        if( im_extract_bands( t[0], t[2], 1, t[0]->Bands - 1 ) )
            return( -1 );
    }

    /* Map L.
     */
    if( im_maplut( t[1], t[3], lut ) )
        return( -1 );

    /* Recombine bands.
     */
    if( t[0]->Bands > 1 ) {
        if( im_bandjoin( t[3], t[2], t[4] ) )
            return( -1 );
    }
    else
        t[4] = t[3];

    /* If input was LabQ, repack.
     */
    if( in->Coding == IM_CODING_LABQ ) {
        if( im_LabS2LabQ( t[4], t[5] ) )
            return( -1 );
    }
    else
        t[5] = t[4];

    return( im_copy( t[4], out ) );
}
Пример #2
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 );
}
Пример #3
0
/**
 * 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 );
}
Пример #4
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 );
}
Пример #5
0
/**
 * im_gammacorrect:
 * @in: input image
 * @out: output image
 * @exponent: gamma factor
 *
 * Gamma-correct an 8- or 16-bit unsigned image with a lookup table. The
 * output format is the same as the input format.
 *
 * See also: im_identity(), im_powtra(), im_maplut()
 *
 * Returns: 0 on success, -1 on error
 */
int 
im_gammacorrect( IMAGE *in, IMAGE *out, double exponent )
{
	IMAGE *t[4];
	double mx1, mx2;

	if( im_open_local_array( out, t, 4, "im_gammacorrect", "p" ) ||
		im_check_u8or16( "im_gammacorrect", in ) ||
		im_piocheck( in, out ) ||
		(in->BandFmt == IM_BANDFMT_UCHAR ?
			im_identity( t[0], 1 ) :
			im_identity_ushort( t[0], 1, 65536 )) ||
		im_powtra( t[0], t[1], exponent ) ||
		im_max( t[0], &mx1 ) ||
		im_max( t[1], &mx2 ) ||
		im_lintra( mx1 / mx2, t[1], 0, t[2] ) ||
		im_clip2fmt( t[2], t[3], in->BandFmt ) ||
		im_maplut( in, out, t[3] ) )
		return( -1 );

	return( 0 );
}