From: <sha...@us...> - 2007-07-01 07:38:00
|
Revision: 2200 http://hugin.svn.sourceforge.net/hugin/?rev=2200&view=rev Author: shahid_du Date: 2007-07-01 00:37:57 -0700 (Sun, 01 Jul 2007) Log Message: ----------- Added development version of mask image ouput and bicubic interpolation. Modified Paths: -------------- libpanorama/trunk/src/vips/interpolation.c libpanorama/trunk/src/vips/interpolation.h libpanorama/trunk/src/vips/plug.c libpanorama/trunk/src/vips/resample.c libpanorama/trunk/src/vips/resample.h libpanorama/trunk/src/vips/transmap.c Modified: libpanorama/trunk/src/vips/interpolation.c =================================================================== --- libpanorama/trunk/src/vips/interpolation.c 2007-06-30 19:15:50 UTC (rev 2199) +++ libpanorama/trunk/src/vips/interpolation.c 2007-07-01 07:37:57 UTC (rev 2200) @@ -45,9 +45,56 @@ /*linearInterpolation(1-xdis, p00[i], xdis, p01[i], a0); linearInterpolation(1-xdis, p10[i], xdis, p11[i], a1); linearInterpolation(1-ydis, a0, ydis, a1, q[i]);*/ + a0 = linearInterpolation(1-xdis, p00[i], xdis, p01[i]); a1 = linearInterpolation(1-xdis, p10[i], xdis, p11[i]); q[i] = linearInterpolation(1-ydis, a0, ydis, a1); //printf("i = %d, a0 = %d, a1 = %d, q[i] = %d\n", i, a0, a1, q[i]); } } + + + +double cubicInterpolation( double dis, double f0, double f1, double f2, double f3 ) +{ + return( ( -f0 + f1 - f2 + f3) * (dis*dis*dis) + + (2.0*f0 - 2.0*f1 + f2 - f3) * (dis*dis) + + ( -f0 + f2 ) * dis + + f1 ); +} + + + +void bicubicInterpolation(unsigned char *q, REGION *reg, double px, double py, const int ps) +{ + int p00x = (int) px; + int p00y = (int) py; + double xdis = px - p00x; + double ydis = py - p00y; + unsigned char *k[4][4]; + int i, j; + + for(j = 0; j < 4; j++) + for(i = 0; i < 4; i++) + { + k[j][i] = (unsigned char *) IM_REGION_ADDR (reg, p00x-1+i, p00y-1+j); + + } + + for(i = 0; i < ps; i++) + { + double a0, a1, a2, a3; + a0 = cubicInterpolation(xdis, k[0][0][i], k[0][1][i], k[0][2][i], k[0][3][i]); + /*printf("for a0: %d -- %d -- %d -- %d == %f\n", k[0][0][i], k[0][1][i], k[0][2][i], k[0][3][i], a0);*/ + a1 = cubicInterpolation(xdis, k[1][0][i], k[1][1][i], k[1][2][i], k[1][3][i]); + a2 = cubicInterpolation(xdis, k[2][0][i], k[2][1][i], k[2][2][i], k[2][3][i]); + a3 = cubicInterpolation(xdis, k[3][0][i], k[3][1][i], k[3][2][i], k[3][3][i]); + + q[i] = (unsigned char) cubicInterpolation(ydis, a0, a1, a2, a3); + /*printf("for output: %f -- %f -- %f -- %f == %f == %d\n", a0, a1, a2, a3, cubicInterpolation(ydis, a0, a1, a2, a3), q[i]); */ + } + + + +} + Modified: libpanorama/trunk/src/vips/interpolation.h =================================================================== --- libpanorama/trunk/src/vips/interpolation.h 2007-06-30 19:15:50 UTC (rev 2199) +++ libpanorama/trunk/src/vips/interpolation.h 2007-07-01 07:37:57 UTC (rev 2200) @@ -3,9 +3,9 @@ #include <vips/vips.h> -#define maxDefined 1 +#define maxDefined 2 void billinearInterpolation(unsigned char *q, REGION *reg, double px, double py, const int ps); +void bicubicInterpolation(unsigned char *q, REGION *reg, double px, double py, const int ps); - #endif Modified: libpanorama/trunk/src/vips/plug.c =================================================================== --- libpanorama/trunk/src/vips/plug.c 2007-06-30 19:15:50 UTC (rev 2199) +++ libpanorama/trunk/src/vips/plug.c 2007-07-01 07:37:57 UTC (rev 2200) @@ -12,25 +12,6 @@ char *transformFile = argv[1]; int *imgNr = argv[2]; - /*int width, height; - pt_transform *trn;*/ - - /*width and height will be loaded from pt_script */ - /*if( !(trn = transform_new_from_file( transform, &width, &height, 0 )) ) { - im_error( "transform_image_build", - _( "unable to build transform" ) ); - return( -1 ); - } - - if( im_add_close_callback( out, - (im_callback_fn) transform_destroy, trn, NULL ) ) { - transform_destroy( trn ); - return( -1 ); - } - - if( transform_image_build( out, trn, width, height ) ) - return( -1 );*/ - if( transform_image( out, transformFile, *imgNr) ) return( -1 ); @@ -57,18 +38,15 @@ static int output_resample_image_vec( im_object *argv ) { - /*char *imageOut = argv[2]; + IMAGE *out = argv[2]; + char outputImageMask[100]; + sprintf(outputImageMask, "%sMask.v", "output"); - IMAGE *out;*/ - //int *intType = argv[3]; - //int type = *intType; + IMAGE *outMask = im_open_local(out, outputImageMask, "p"); - if (/*!(out = im_open (imageOut, "w")) ||*/ - output_resample_image (argv[0], argv[1], argv[2]/*, argv[3]*/, argv[3])) + if (output_resample_image (argv[0], argv[1], out, outMask, argv[3])) error_exit ("unable to run operation"); - /*im_close (out);*/ - return 0; } @@ -76,13 +54,13 @@ IM_INPUT_IMAGE( "coordinate" ), IM_INPUT_IMAGE( "source" ), IM_OUTPUT_IMAGE( "output" ), - /*IM_OUTPUT_IMAGE( "outputMask" )*/ - IM_INPUT_INT( "interpolation_type(0 = nearest neighbour, 1 = bilinear)" ) + /*IM_OUTPUT_IMAGE( "outputMask" ),*/ + IM_INPUT_INT( "interpolation_type" ) }; static im_function output_resample_image_desc = { "output_resample_image", /* Name */ - "output resample image", /* Description */ + "output resample image (interpolation_type: 0 = nearest neighbour, 1 = bilinear, 2 = bicubic)", /* Description */ IM_FN_PIO | IM_FN_TRANSFORM, /* Flags */ output_resample_image_vec, /* Dispatch function */ IM_NUMBER( output_resample_image_arg_types ),/* Size of arg list */ Modified: libpanorama/trunk/src/vips/resample.c =================================================================== --- libpanorama/trunk/src/vips/resample.c 2007-06-30 19:15:50 UTC (rev 2199) +++ libpanorama/trunk/src/vips/resample.c 2007-07-01 07:37:57 UTC (rev 2200) @@ -104,7 +104,6 @@ double *p = (double *) IM_REGION_ADDR (ir[0], le, y); const int ps = IM_IMAGE_SIZEOF_PEL (vec[1]); unsigned char *q = (unsigned char *) IM_REGION_ADDR (or, le, y); - /*unsigned char *qMask = (unsigned char *) IM_REGION_ADDR (ir[2], le, y);*/ for( x = le; x < ri; x++ ) { @@ -113,7 +112,7 @@ p += 2; - if (px < vec[1]->Xsize && px >= 0 && py < vec[1]->Ysize && py >= 0) + if (px < (vec[1]->Xsize -0) && px >= 0 && py < (vec[1]->Ysize -0) && py >= 0) { switch (*intType) { @@ -125,22 +124,21 @@ billinearInterpolation(q, ir[1], px, py, ps); break; + case 2: + bicubicInterpolation(q, ir[1], px, py, ps); + break; + default: - printf("Unknown type\n"); - break; + printf("Unknown interpolation type\n"); + return (-1); } - /*memcpy (q, IM_REGION_ADDR (ir[1], (int) px, (int) py), ps);*/ - /*billinearInterpolation(q, ir[1], px, py, ps);*/ - /* *qMask = 255;*/ } else { memset (q, 0, ps); - /* *qMask = 0;*/ } q += ps; - /*qMask += 1;*/ } } @@ -148,9 +146,59 @@ } +static int +output_resample_image_mask_gen( REGION *or, REGION *ir, IMAGE *coordinate) +{ + /*printf("start mask gen\n");*/ + Rect *r = &or->valid; + int le = r->left; + int to = r->top; + int ri = IM_RECT_RIGHT( r ); + int bo = IM_RECT_BOTTOM( r ); + + /*printf("b4 prepare\n");*/ + if(im_prepare(ir, r)) + { + return -1; + } + /*printf("after prepare\n");*/ + int x, y; + + for( y = to; y < bo; y++ ) + { + double *p = (double *) IM_REGION_ADDR (ir, le, y); + /*printf("b4 outer fill\n");*/ + unsigned char *q = (unsigned char *) IM_REGION_ADDR (or, le, y); + + for( x = le; x < ri; x++ ) + { + double px = p[0]; + double py = p[1]; + + p += 2; + + printf("b4 fill\n"); + if (px < coordinate->Xsize && px >= 0 && py < coordinate->Ysize && py >= 0) + { + *q = 255; + } + else + { + *q = 0; + } + + q += 1; + } + } + + return( 0 ); +} + + + int -output_resample_image (IMAGE * coordinate, IMAGE * in, IMAGE * out/*, IMAGE *outMask*/, int *intType) +output_resample_image (IMAGE * coordinate, IMAGE * in, IMAGE * out, IMAGE *outMask, int *intType) { //int *intType; //intType = &type; @@ -188,16 +236,18 @@ out->Ysize = coordinate->Ysize; /* preparing mask image headers */ - /*im_initdesc( outMask, out->Xsize, out->Ysize, 1, 0, IM_BANDFMT_UCHAR, + im_initdesc( outMask, out->Xsize, out->Ysize, 1, 0, IM_BANDFMT_UCHAR, IM_CODING_NONE, IM_TYPE_B_W, 1.0, 1.0, 0, 0 ); if( im_poutcheck( outMask ) ) - return( -1 );*/ + return( -1 ); /*printf("b4 calling demand\n");*/ - if( im_demand_hint( out, IM_SMALLTILE, coordinate, in, /*outMask,*/ NULL ) ) + + + if( im_demand_hint( out, IM_SMALLTILE, coordinate, in, NULL ) ) return( -1 ); - if( !(vec = im_allocate_input_array( out, coordinate, in, /*outMask,*/ NULL )) ) + if( !(vec = im_allocate_input_array( out, coordinate, in, NULL )) ) return( -1 ); /*printf("b4 calling generate function\n");*/ @@ -205,6 +255,15 @@ im_start_many, output_resample_image_gen, im_stop_many, vec, intType ) ) return( -1 ); + if( im_demand_hint( outMask, IM_SMALLTILE, coordinate, NULL ) ) + return( -1 ); + + /*printf("b4 calling generate function2\n");*/ + if( im_generate( outMask, + im_start_one, output_resample_image_mask_gen, im_stop_one, coordinate, NULL) ) + return( -1 ); + + /*printf("after calling generate function2\n");*/ return 0; } Modified: libpanorama/trunk/src/vips/resample.h =================================================================== --- libpanorama/trunk/src/vips/resample.h 2007-06-30 19:15:50 UTC (rev 2199) +++ libpanorama/trunk/src/vips/resample.h 2007-07-01 07:37:57 UTC (rev 2200) @@ -3,7 +3,7 @@ #include <vips/vips.h> -int output_resample_image( IMAGE *coordinate, IMAGE *in, IMAGE *out/*, IMAGE *outMask*/, int *intType); +int output_resample_image( IMAGE *coordinate, IMAGE *in, IMAGE *out, IMAGE *outMask, int *intType); #endif Modified: libpanorama/trunk/src/vips/transmap.c =================================================================== --- libpanorama/trunk/src/vips/transmap.c 2007-06-30 19:15:50 UTC (rev 2199) +++ libpanorama/trunk/src/vips/transmap.c 2007-07-01 07:37:57 UTC (rev 2200) @@ -12,6 +12,10 @@ int main(int argc, char *argv[]) { + + /*if (im_init_world (argv[0])) + error_exit ("unable to start VIPS");*/ + if (argc != 2) { printf("Usage: %s script-file-name\n", argv[0]); @@ -33,16 +37,16 @@ { char outputImage[100], outputImageMask[100]; sprintf(outputImage, "%s%d.tif", "out", i); - sprintf(outputImageMask, "%s%dMask", "out", i); + sprintf(outputImageMask, "%s%dMask.v", "out", i); IMAGE *out, *coordImage, *input; - /*IMAGE *outMask;*/ + IMAGE *outMask; int interpolationType = 1; int *type; type = &interpolationType; out = im_open (outputImage, "w"); coordImage = im_open_local(out, "coordImage", "p"); - /*outMask = im_open_local(out, outputImageMask, "p");*/ + outMask = im_open_local(out, outputImageMask, "p"); if( transform_image( coordImage, argv[1], i) ) { @@ -54,12 +58,14 @@ pt_script_image * inputImg = panoScriptGetInputImage(script, i); if (!(input = im_open_local (out, inputImg->name, "r")) || - output_resample_image (coordImage, input, out, type)) + output_resample_image (coordImage, input, out, outMask, type)) error_exit ("unable to run operation\n"); printf("resampling done\n"); printf("saving %s ....\n", outputImage); + /*im_close(outMask);*/ im_close(out); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |