/* A colour difference operation. */ int im__colour_difference( const char *domain, IMAGE *in1, IMAGE *in2, IMAGE *out, im_wrapmany_fn buffer_fn, void *a, void *b ) { IMAGE *t[3]; if( im_check_uncoded( domain, in1 ) || im_check_uncoded( domain, in2 ) || im_check_bands( domain, in1, 3 ) || im_check_bands( domain, in2, 3 ) || im_check_size_same( domain, in1, in2 ) || im_open_local_array( out, t, 2, domain, "p" ) || im_clip2fmt( in1, t[0], IM_BANDFMT_FLOAT ) || im_clip2fmt( in2, t[1], IM_BANDFMT_FLOAT ) ) return( -1 ); if( im_cp_descv( out, t[0], t[1], NULL ) ) return( -1 ); out->Bands = 1; out->Type = IM_TYPE_B_W; t[2] = NULL; if( im_wrapmany( t, out, buffer_fn, a, b ) ) return( -1 ); return( 0 ); }
int im_dECMC_fromLab( IMAGE *im1, IMAGE *im2, IMAGE *out ) { IMAGE *invec[3]; /* Check input types. */ if( im1->Bands != 3 || im1->BandFmt != IM_BANDFMT_FLOAT || im1->Coding != IM_CODING_NONE || im2->Bands != 3 || im2->BandFmt != IM_BANDFMT_FLOAT || im2->Coding != IM_CODING_NONE ) { im_errormsg( "im_dECMC_fromLab: 3-band float only" ); return( -1 ); } /* Prepare the output image */ if( im_cp_descv( out, im1, im2, NULL ) ) return( -1 ); out->Bbits = IM_BBITS_FLOAT; out->Bands = 1; out->BandFmt = IM_BANDFMT_FLOAT; out->Type = IM_TYPE_B_W; /* Do the processing. */ invec[0] = im1; invec[1] = im2; invec[2] = NULL; if( im_wrapmany( invec, out, (im_wrapmany_fn) imb_dECMC_fromLab, NULL, NULL ) ) return( -1 ); return( 0 ); }
int im_subtract( IMAGE *in1, IMAGE *in2, IMAGE *out ) { /* Basic checks. */ if( im_piocheck( in1, out ) || im_pincheck( in2 ) ) return( -1 ); if( in1->Bands != in2->Bands && (in1->Bands != 1 && in2->Bands != 1) ) { im_error( "im_subtract", _( "not same number of bands" ) ); return( -1 ); } if( in1->Coding != IM_CODING_NONE || in2->Coding != IM_CODING_NONE ) { im_error( "im_subtract", _( "not uncoded" ) ); return( -1 ); } if( im_cp_descv( out, in1, in2, NULL ) ) return( -1 ); /* What number of bands will we write? */ out->Bands = IM_MAX( in1->Bands, in2->Bands ); /* What output type will we write? int, float or complex. */ if( im_iscomplex( in1 ) || im_iscomplex( in2 ) ) { /* What kind of complex? */ if( in1->BandFmt == IM_BANDFMT_DPCOMPLEX || in2->BandFmt == IM_BANDFMT_DPCOMPLEX ) /* Output will be DPCOMPLEX. */ out->BandFmt = IM_BANDFMT_DPCOMPLEX; else out->BandFmt = IM_BANDFMT_COMPLEX; } else if( im_isfloat( in1 ) || im_isfloat( in2 ) ) { /* What kind of float? */ if( in1->BandFmt == IM_BANDFMT_DOUBLE || in2->BandFmt == IM_BANDFMT_DOUBLE ) out->BandFmt = IM_BANDFMT_DOUBLE; else out->BandFmt = IM_BANDFMT_FLOAT; } else /* Must be int+int -> int. */ out->BandFmt = iformat[in1->BandFmt][in2->BandFmt]; /* And process! */ if( im__cast_and_call( in1, in2, out, (im_wrapmany_fn) subtract_buffer, NULL ) ) return( -1 ); /* Success! */ return( 0 ); }
static int ifthenelse( IMAGE *c, IMAGE *a, IMAGE *b, IMAGE *out ) { IMAGE **in; /* Check args. */ if( im_check_uncoded( "im_ifthenelse", c ) || im_check_coding_known( "im_ifthenelse", a ) || im_check_coding_known( "im_ifthenelse", b ) || im_check_format( "ifthenelse", c, IM_BANDFMT_UCHAR ) || im_check_format_same( "ifthenelse", a, b ) || im_check_bands_same( "ifthenelse", a, b ) || im_check_bands_1orn( "im_ifthenelse", c, a ) || im_piocheck( c, out ) || im_pincheck( a ) || im_pincheck( b ) ) return( -1 ); /* Make output image. */ if( im_demand_hint( out, IM_THINSTRIP, c, a, b, NULL ) || im_cp_descv( out, a, b, c, NULL ) || !(in = im_allocate_input_array( out, c, a, b, NULL )) || im_generate( out, im_start_many, ifthenelse_gen, im_stop_many, in, NULL ) ) return( -1 ); return( 0 ); }
/** * im_maplut: * @in: input image * @out: output image * @lut: look-up table * * Map an image through another image acting as a LUT (Look Up Table). * The lut may have any type, and the output image will be that type. * * The input image will be cast to one of the unsigned integer types, that is, * IM_BANDFMT_UCHAR, IM_BANDFMT_USHORT or IM_BANDFMT_UINT. * * If @lut is too small for the input type (for example, if @in is * IM_BANDFMT_UCHAR but @lut only has 100 elements), the lut is padded out * by copying the last element. Overflows are reported at the end of * computation. * If @lut is too large, extra values are ignored. * * If @lut has one band, then all bands of @in pass through it. If @lut * has same number of bands as @in, then each band is mapped * separately. If @in has one band, then @lut may have many bands and * the output will have the same number of bands as @lut. * * See also: im_histgr(), im_identity(). * * Returns: 0 on success, -1 on error */ int im_maplut( IMAGE *in, IMAGE *out, IMAGE *lut ) { IMAGE *t; LutInfo *st; /* Check input output. Old-style IO from lut, for simplicity. */ if( im_check_hist( "im_maplut", lut ) || im_check_uncoded( "im_maplut", lut ) || im_check_uncoded( "im_maplut", in ) || im_check_bands_1orn( "im_maplut", in, lut ) || im_piocheck( in, out ) || im_incheck( lut ) ) return( -1 ); /* Cast in to u8/u16/u32. */ if( !(t = im_open_local( out, "im_maplut", "p" )) || im_clip2fmt( in, t, bandfmt_maplut[in->BandFmt] ) ) return( -1 ); /* Prepare the output header. */ if( im_cp_descv( out, t, lut, NULL ) ) return( -1 ); /* Force output to be the same type as lut. */ out->BandFmt = lut->BandFmt; /* Output has same number of bands as LUT, unless LUT has 1 band, in * which case output has same number of bands as input. */ if( lut->Bands != 1 ) out->Bands = lut->Bands; /* Make tables. */ if( !(st = build_luts( out, lut )) ) return( -1 ); /* Set demand hints. */ if( im_demand_hint( out, IM_THINSTRIP, t, NULL ) ) return( -1 ); /* Process! */ if( im_generate( out, maplut_start, maplut_gen, maplut_stop, t, st ) ) return( -1 ); return( 0 ); }
/* Raw fastcor, with no borders. */ int im_fastcor_raw( IMAGE *in, IMAGE *ref, IMAGE *out ) { /* PIO between in and out; WIO from ref. */ if( im_piocheck( in, out ) || im_incheck( ref ) ) return( -1 ); /* Check sizes. */ if( in->Xsize < ref->Xsize || in->Ysize < ref->Ysize ) { im_errormsg( "im_fastcor: ref not smaller than in" ); return( -1 ); } /* Check types. */ if( in->Coding != IM_CODING_NONE || in->Bands != 1 || in->BandFmt != IM_BANDFMT_UCHAR || ref->Coding != IM_CODING_NONE || ref->Bands != 1 || ref->BandFmt != IM_BANDFMT_UCHAR ) { im_errormsg( "im_fastcor_raw: input not uncoded 1 band uchar" ); return( -1 ); } /* Prepare the output image. */ if( im_cp_descv( out, in, ref, NULL ) ) return( -1 ); out->Bbits = IM_BBITS_INT; out->BandFmt = IM_BANDFMT_UINT; out->Xsize = in->Xsize - ref->Xsize + 1; out->Ysize = in->Ysize - ref->Ysize + 1; /* Set demand hints. FATSTRIP is good for us, as THINSTRIP will cause * too many recalculations on overlaps. */ if( im_demand_hint( out, IM_FATSTRIP, in, NULL ) ) return( -1 ); /* Write the correlation. */ if( im_generate( out, im_start_one, fastcor_gen, im_stop_one, in, ref ) ) return( -1 ); out->Xoffset = -ref->Xsize / 2; out->Yoffset = -ref->Ysize / 2; return( 0 ); }
/* Join two images. out->Bands = in1->Bands + in2->Bands. in1 goes first in * the list. */ int im_bandjoin( IMAGE *in1, IMAGE *in2, IMAGE *out ) { IMAGE **in; /* Check our args. */ if( im_piocheck( in1, out ) ) return( -1 ); if( im_piocheck( in2, out ) ) return( -1 ); if( in1->Xsize != in2->Xsize || in1->Ysize != in2->Ysize ) { im_errormsg( "im_bandjoin: images not same size" ); return( -1 ); } if( in1->BandFmt != in2->BandFmt ) { im_errormsg( "im_bandjoin: images not same type" ); return( -1 ); } if( in1->Coding != IM_CODING_NONE || in2->Coding != IM_CODING_NONE ) { im_errormsg( "im_bandjoin: input coded" ); return( -1 ); } /* Set up the output header. */ if( im_cp_descv( out, in1, in2, NULL ) ) return( -1 ); out->Bands = in1->Bands + in2->Bands; /* Set demand hints. */ if( im_demand_hint( out, IM_THINSTRIP, in1, in2, NULL ) ) return( -1 ); /* Make input array. */ if( !(in = im_allocate_input_array( out, in1, in2, NULL )) ) return( -1 ); /* Make output image. */ if( im_generate( out, im_start_many, bandjoin_gen, im_stop_many, in, NULL ) ) return( -1 ); return( 0 ); }
/* Raw fastcor, with no borders. */ int im_fastcor_raw( IMAGE *in, IMAGE *ref, IMAGE *out ) { /* PIO between in and out; WIO from ref. */ if( im_piocheck( in, out ) || im_incheck( ref ) ) return( -1 ); /* Check sizes. */ if( in->Xsize < ref->Xsize || in->Ysize < ref->Ysize ) { im_error( "im_fastcor", "%s", _( "ref not smaller than or equal to in" ) ); return( -1 ); } /* Check types. */ if( im_check_uncoded( "im_fastcor", in ) || im_check_mono( "im_fastcor", in ) || im_check_format( "im_fastcor", in, IM_BANDFMT_UCHAR ) || im_check_coding_same( "im_fastcor", in, ref ) || im_check_bands_same( "im_fastcor", in, ref ) || im_check_format_same( "im_fastcor", in, ref ) ) return( -1 ); /* Prepare the output image. */ if( im_cp_descv( out, in, ref, NULL ) ) return( -1 ); out->BandFmt = IM_BANDFMT_UINT; out->Xsize = in->Xsize - ref->Xsize + 1; out->Ysize = in->Ysize - ref->Ysize + 1; /* FATSTRIP is good for us, as THINSTRIP will cause * too many recalculations on overlaps. */ if( im_demand_hint( out, IM_FATSTRIP, in, NULL ) || im_generate( out, im_start_one, fastcor_gen, im_stop_one, in, ref ) ) return( -1 ); out->Xoffset = -ref->Xsize / 2; out->Yoffset = -ref->Ysize / 2; return( 0 ); }
static int hist_write( IMAGE *out, Histogram *hist ) { if( im_cp_descv( out, hist->index, hist->value, NULL ) ) return( -1 ); im_initdesc( out, hist->mx + 1, 1, hist->value->Bands, IM_BBITS_DOUBLE, IM_BANDFMT_DOUBLE, IM_CODING_NONE, IM_TYPE_HISTOGRAM, 1.0, 1.0, 0, 0 ); if( im_setupout( out ) ) return( -1 ); if( im_writeline( 0, out, (PEL *) hist->bins ) ) return( -1 ); return( 0 ); }
int im__tbmerge( IMAGE *ref, IMAGE *sec, IMAGE *out, int dx, int dy, int mwidth ) { Overlapping *ovlap; if( dy > 0 || dy < 1 - ref->Ysize ) { /* No overlap, use insert instead. */ if( im_insert( ref, sec, out, -dx, -dy ) ) return( -1 ); out->Xoffset = -dx; out->Yoffset = -dy; return( 0 ); } /* Build state for this join. */ if( !(ovlap = build_tbstate( ref, sec, out, dx, dy, mwidth )) ) return( -1 ); /* Prepare the output IMAGE. */ if( im_cp_descv( out, ref, sec, NULL ) ) return( -1 ); out->Xsize = ovlap->oarea.width; out->Ysize = ovlap->oarea.height; out->Xoffset = ovlap->sarea.left; out->Yoffset = ovlap->sarea.top; /* Set demand hints. */ if( im_demand_hint( out, IM_THINSTRIP, ref, sec, NULL ) ) return( -1 ); /* Generate! */ if( im_generate( out, im__start_merge, im__merge_gen, im__stop_merge, ovlap, NULL ) ) return( -1 ); return ( 0 ); }