Beispiel #1
0
/**
 * im_scaleps:
 * @in: input image
 * @out: output image
 *
 * Scale a power spectrum. Transform with log10(1.0 + pow(x, 0.25)) + .5, 
 * then scale so max == 255.
 *
 * See also: im_scale().
 *
 * Returns: 0 on success, -1 on error
 */
int 
im_scaleps( IMAGE *in, IMAGE *out )
{
	IMAGE *t[4];
	double mx;
	double scale;

	if( im_open_local_array( out, t, 4, "im_scaleps-1", "p" ) || 
		im_max( in, &mx ) )
		return( -1 );

	if( mx <= 0.0 ) 
		/* Range of zero: just return black.
		 */
		return( im_black( out, in->Xsize, in->Ysize, in->Bands ) );

	scale = 255.0 / log10( 1.0 + pow( mx, .25 ) );

	/* Transform!
	 */
	if( im_powtra( in, t[0], 0.25 ) ||
		im_lintra( 1.0, t[0], 1.0, t[1] ) ||
		im_log10tra( t[1], t[2] ) ||
		im_lintra( scale, t[2], 0.0, t[3] ) ||
		im_clip2fmt( t[3], out, IM_BANDFMT_UCHAR ) )
		return( -1 );

	return( 0 );
}
Beispiel #2
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 );
}
Beispiel #3
0
/* Plot image.
 */
static int
plot( IMAGE *in, IMAGE *out )
{
	double max;
	int tsize;
	int xsize;
	int ysize;

	if( im_incheck( in ) ||
		im_poutcheck( out ) )
		return( -1 );

	/* Find range we will plot.
	 */
	if( im_max( in, &max ) )
		return( -1 );
	g_assert( max >= 0 );
	if( in->BandFmt == IM_BANDFMT_UCHAR )
		tsize = 256;
	else
		tsize = ceil( max );

	/* Make sure we don't make a zero height image.
	 */
	if( tsize == 0 )
		tsize = 1;

	if( in->Xsize == 1 ) {
		/* Vertical graph.
		 */
		xsize = tsize;
		ysize = in->Ysize;
	}
	else {
		/* Horizontal graph.
		 */
		xsize = in->Xsize;
		ysize = tsize;
	}

	/* Set image.
	 */
	im_initdesc( out, xsize, ysize, in->Bands, 
		IM_BBITS_BYTE, IM_BANDFMT_UCHAR, 
		IM_CODING_NONE, IM_TYPE_HISTOGRAM, 1.0, 1.0, 0, 0 );

	/* Set hints - ANY is ok with us.
	 */
	if( im_demand_hint( out, IM_ANY, NULL ) )
		return( -1 );
	
	/* Generate image.
	 */
	if( in->Xsize == 1 ) {
		if( im_generate( out, NULL, make_vert_gen, NULL, in, NULL ) )
			return( -1 );
	}
	else {
		if( im_generate( out, NULL, make_horz_gen, NULL, in, NULL ) )
			return( -1 );
	}

	return( 0 );
}