示例#1
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 );
}
示例#2
0
/**
 * im_abs:
 * @in: input #IMAGE
 * @out: output #IMAGE
 *
 * This operation finds the absolute value of an image. It does a copy for
 * unsigned integer types, negate for negative values in
 * signed integer types, <function>fabs(3)</function> for
 * float types, and calculate modulus for complex
 * types.
 *
 * See also: im_exp10tra(), im_sign().
 *
 * Returns: 0 on success, -1 on error
 */
int
im_abs( IMAGE *in, IMAGE *out )
{
    if( im_piocheck( in, out ) ||
            im_check_uncoded( "im_abs", in ) )
        return( -1 );

    /* Is this one of the unsigned types? Degenerate to im_copy() if it
     * is.
     */
    if( vips_bandfmt_isuint( in->BandFmt ) )
        return( im_copy( in, out ) );

    /* Prepare output header. Output type == input type, except for
     * complex.
     */
    if( im_cp_desc( out, in ) )
        return( -1 );
    switch( in->BandFmt ) {
    case IM_BANDFMT_CHAR:
    case IM_BANDFMT_SHORT:
    case IM_BANDFMT_INT:
    case IM_BANDFMT_FLOAT:
    case IM_BANDFMT_DOUBLE:
        /* No action.
         */
        break;

    case IM_BANDFMT_COMPLEX:
        out->BandFmt = IM_BANDFMT_FLOAT;
        break;

    case IM_BANDFMT_DPCOMPLEX:
        out->BandFmt = IM_BANDFMT_DOUBLE;
        break;

    default:
        im_error( "im_abs", "%s", _( "unknown input type" ) );
        return( -1 );
    }

    /* Generate!
     */
    if( im_wrapone( in, out,
                    (im_wrapone_fn) abs_gen, in, NULL ) )
        return( -1 );

    return( 0 );
}
示例#3
0
/**
 * im_zerox:
 * @in: input image
 * @out: output image
 * @sign: detect positive or negative zero crossings
 *
 * im_zerox() detects the positive or negative zero crossings @in, 
 * depending on @sign. If @sign is -1, negative zero crossings are returned,
 * if @sign is 1, positive zero crossings are returned.
 *
 * The output image is byte with zero crossing set to 255 and all other values
 * set to zero. Input can have any number of channels, and be any non-complex 
 * type.
 *
 * See also: im_conv(), im_rot90.
 *
 * Returns: 0 on success, -1 on error
 */
int 
im_zerox( IMAGE *in, IMAGE *out, int sign )
{
	IMAGE *t1;

	if( sign != -1 && sign != 1 ) {
		im_error( "im_zerox", "%s", _( "flag not -1 or 1" ) );
		return( -1 );
	}
	if( in->Xsize < 2 ) {
		im_error( "im_zerox", "%s", _( "image too narrow" ) );
		return( -1 );
	}
	if( !(t1 = im_open_local( out, "im_zerox" , "p" )) ||
		im_piocheck( in, t1 ) ||
		im_check_uncoded( "im_zerox", in ) ||
		im_check_noncomplex( "im_zerox", in ) )
		return( -1 );
	if( vips_bandfmt_isuint( in->BandFmt ) )
		/* Unsigned type, therefore there will be no zero-crossings.
		 */
		return( im_black( out, in->Xsize, in->Ysize, in->Bands ) );

	/* Force output to be BYTE. Output is narrower than input by 1 pixel.
	 */
	if( im_cp_desc( t1, in ) )
		return( -1 );
	t1->BandFmt = IM_BANDFMT_UCHAR;
	t1->Xsize -= 1;

	/* Set hints - THINSTRIP is ok with us.
	 */
	if( im_demand_hint( t1, IM_THINSTRIP, NULL ) )
		return( -1 );

	/* Generate image.
	 */
	if( im_generate( t1, im_start_one, zerox_gen, im_stop_one, 
		in, GINT_TO_POINTER( sign ) ) )
		return( -1 );

	/* Now embed it in a larger image.
	 */
	if( im_embed( t1, out, 0, 0, 0, in->Xsize, in->Ysize ) )
		return( -1 );

	return( 0 );
}
示例#4
0
/**
 * im_msb:
 * @in: input image
 * @out: output image
 *
 * Turn any integer image to 8-bit unsigned char by discarding all but the most
 * significant byte.
 * Signed values are converted to unsigned by adding 128.
 *
 * This operator also works for LABQ coding.
 *
 * See also: im_msb_band().
 *
 * Returns: 0 on success, -1 on error
 */
int
im_msb( IMAGE *in, IMAGE *out )
{
	Msb *msb;
	im_wrapone_fn func;

	if( in->Coding == IM_CODING_NONE &&
		in->BandFmt == IM_BANDFMT_UCHAR )
		return( im_copy( in, out ) );

	if( im_piocheck( in, out ) ||
		!(msb = IM_NEW( out, Msb )) )
		return( -1 );

	if( in->Coding == IM_CODING_NONE ) {
		if( im_check_int( "im_msb", in ) ) 
			return( -1 );

		msb->width = IM_IMAGE_SIZEOF_ELEMENT( in );
		msb->index = im_amiMSBfirst() ? 0 : msb->width - 1;
		msb->repeat = in->Bands;

		if( vips_bandfmt_isuint( in->BandFmt ) )
			func = (im_wrapone_fn) byte_select;
		else
			func = (im_wrapone_fn) byte_select_flip;
	}
	else if( IM_CODING_LABQ == in->Coding )
		func = (im_wrapone_fn) msb_labq;
	else {
		im_error( "im_msb", "%s", _( "unknown coding" ) );
		return( -1 );
	}

	if( im_cp_desc( out, in ) )
		return( -1 );
	out->BandFmt = IM_BANDFMT_UCHAR;
	out->Coding = IM_CODING_NONE;

	return( im_wrapone( in, out, func, msb, NULL ) );
}
示例#5
0
gboolean
im_isuint( IMAGE *im )
{	
	return( vips_bandfmt_isuint( im->BandFmt ) );
}
示例#6
0
/**
 * im_msb_band:
 * @in: input image
 * @out: output image
 * @band: select this band
 *
 * Turn any integer image to a single-band 8-bit unsigned char by discarding 
 * all but the most significant byte from the selected band. 
 * Signed values are converted to unsigned by adding 128.
 *
 * This operator also works for LABQ coding.
 *
 * See also: im_msb_band().
 *
 * Returns: 0 on success, -1 on error
 */
int
im_msb_band( IMAGE *in, IMAGE *out, int band )
{
	Msb *msb;
	im_wrapone_fn func;

	if( band < 0 ) {
		im_error( "im_msb_band", "%s", _( "bad arguments" ) );
		return( -1 );
	}

	if( im_piocheck( in, out ) ||
		!(msb = IM_NEW( out, Msb )) )
		return( -1 );

	if( in->Coding == IM_CODING_NONE ) {
		if( im_check_int( "im_msb_band", in ) ) 
			return( -1 );

		if( band >= in->Bands ) {
			im_error( "im_msb_band", "%s", 
				_( "image does not have that many bands" ) );
			return( -1 );
		}

		msb->width = IM_IMAGE_SIZEOF_ELEMENT( in );
		msb->index = im_amiMSBfirst() ? 
			msb->width * band : msb->width * (band + 1) - 1;
		msb->repeat = 1;

		if( vips_bandfmt_isuint( in->BandFmt ) )
			func = (im_wrapone_fn) byte_select;
		else
			func = (im_wrapone_fn) byte_select_flip;
	}
	else if( IM_CODING_LABQ == in->Coding ) {
		if( band > 2 ) {
			im_error( "im_msb_band", "%s", 
				_( "image does not have that many bands" ) );
			return( -1 );
		}
		msb->width = 4;
		msb->repeat = 1;
		msb->index = band;

		if( band )
			func = (im_wrapone_fn) byte_select_flip;
		else
			func = (im_wrapone_fn) byte_select;
	}
	else {
		im_error( "im_msb", "%s", _( "unknown coding" ) );
		return( -1 );
	}

	if( im_cp_desc( out, in ) )
		return( -1 );
	out->BandFmt = IM_BANDFMT_UCHAR;
	out->Coding = IM_CODING_NONE;
	out->Bands = 1;

	return( im_wrapone( in, out, func, msb, NULL ) );
}