From: <sha...@us...> - 2007-07-11 07:06:02
|
Revision: 2254 http://hugin.svn.sourceforge.net/hugin/?rev=2254&view=rev Author: shahid_du Date: 2007-07-11 00:06:00 -0700 (Wed, 11 Jul 2007) Log Message: ----------- Fixed interpolation and spot problem along with some modification. Modified Paths: -------------- libpanorama/trunk/src/vips/ChangeLog 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/ChangeLog =================================================================== --- libpanorama/trunk/src/vips/ChangeLog 2007-07-10 22:57:52 UTC (rev 2253) +++ libpanorama/trunk/src/vips/ChangeLog 2007-07-11 07:06:00 UTC (rev 2254) @@ -1,3 +1,10 @@ +2007-07-11 Shahid <sha...@gm...> + + * transmap.c - used im_filename_suffix_match + * plug.c - Set interpolation type parameter to int + * resample.c - now grow the input image in every outer edge and also the input mask. Corrected expand factor of bicubic to 3. Also corrected all rounding by adding a 0.5 factor. + * interpolation.c - Shifted the interpolation center pixel according to the interpolation factor before interpolation. Return without doing interpolation if any dependent pixel is not defined valid by the input mask. + 2007-07-08 Shahid <sha...@gm...> * Added input image mask generation and checking. Modified: libpanorama/trunk/src/vips/interpolation.c =================================================================== --- libpanorama/trunk/src/vips/interpolation.c 2007-07-10 22:57:52 UTC (rev 2253) +++ libpanorama/trunk/src/vips/interpolation.c 2007-07-11 07:06:00 UTC (rev 2254) @@ -4,22 +4,26 @@ #include <ctype.h> #include <stdarg.h> #include <assert.h> +#include <math.h> #include "interpolation.h" + unsigned char linearInterpolation(double d0, double p0, double d1, double p1) { return ((unsigned char) ( p0 * d0 + p1 * d1 )); } -void billinearInterpolation(unsigned char *q, REGION *reg, double px, double py, const int ps) +int billinearInterpolation(unsigned char *q, REGION *reg, REGION *mreg, double px, double py, const int ps) { int p00x, p00y, p01x, p01y, p10x, p10y, p11x, p11y, i; double xdis, ydis; - unsigned char *p00, *p01, *p10, *p11, a0, a1; + unsigned char *p00, *p01, *p10, *p11, a0, a1, *s[4]; + px += 1.0; + py += 1.0; - p00x = (int) px; - p00y = (int) py; + p00x = (int) (px+0.5); + p00y = (int) (py+0.5); xdis = px - p00x; ydis = py - p00y; @@ -32,7 +36,14 @@ p11x = p01x; p11y = p10y; + + s[0] = (unsigned char *) IM_REGION_ADDR (mreg, p00x, p00y); + s[1] = (unsigned char *) IM_REGION_ADDR (mreg, p01x, p01y); + s[2] = (unsigned char *) IM_REGION_ADDR (mreg, p10x, p10y); + s[3] = (unsigned char *) IM_REGION_ADDR (mreg, p11x, p11y); + if(s[0] == 0 || s[1] == 0 || s[2] == 0 || s[3] == 0) + return -1; p00 = (unsigned char *) IM_REGION_ADDR (reg, p00x, p00y); p01 = (unsigned char *) IM_REGION_ADDR (reg, p01x, p01y); p10 = (unsigned char *) IM_REGION_ADDR (reg, p10x, p10y); @@ -46,6 +57,7 @@ q[i] = linearInterpolation(1-ydis, a0, ydis, a1); /*printf("i = %d, a0 = %d, a1 = %d, q[i] = %d\n", i, a0, a1, q[i]);*/ } + return 0; } @@ -60,20 +72,30 @@ -void bicubicInterpolation(unsigned char *q, REGION *reg, double px, double py, const int ps) +int bicubicInterpolation(unsigned char *q, REGION *reg, REGION *mreg, double px, double py, const int ps) { int p00x, p00y, i, j; double xdis, ydis, a0, a1, a2, a3; - unsigned char *k[4][4]; + unsigned char *k[4][4], *s; + /*printf("for: px = %f, py = %f\n", px, py); */ + px += 3.0; + py += 3.0; + p00x = (int) (px+0.5); + p00y = (int) (py+0.5); + xdis = fabs(px - p00x); + ydis = fabs(py - p00y); - p00x = (int) px; - p00y = (int) py; - xdis = px - p00x; - ydis = py - p00y; + /*printf("interol need:left = %d\twidth = %d\ttop = %d\theight = %d\n", p00x-1, p00x+2, p00y-1, p00y+2);*/ + 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); + s = (unsigned char *) IM_REGION_ADDR (mreg, p00x-1+i, p00y-1+j); + if(*s == 255) + k[j][i] = (unsigned char *) IM_REGION_ADDR (reg, p00x-1+i, p00y-1+j); + else { + return -1; + } } for(i = 0; i < ps; i++) { @@ -88,5 +110,7 @@ /*printf("for output: %f -- %f -- %f -- %f == %f == %d\n", a0, a1, a2, a3, cubicInterpolation(ydis, a0, a1, a2, a3), q[i]);*/ } + + return 0; } Modified: libpanorama/trunk/src/vips/interpolation.h =================================================================== --- libpanorama/trunk/src/vips/interpolation.h 2007-07-10 22:57:52 UTC (rev 2253) +++ libpanorama/trunk/src/vips/interpolation.h 2007-07-11 07:06:00 UTC (rev 2254) @@ -1,11 +1,16 @@ #ifndef __INTERPOLATION_H__ #define __INTERPOLATION_H__ +#define DEBUG + #include <vips/vips.h> #define maxDefined 2 +#define BICUBIC 2 +#define BILLINEAR 1 +#define NN 0 -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); +int billinearInterpolation(unsigned char *q, REGION *reg, REGION *mreg, double px, double py, const int ps); +int bicubicInterpolation(unsigned char *q, REGION *reg, REGION *mreg, double px, double py, const int ps); #endif Modified: libpanorama/trunk/src/vips/plug.c =================================================================== --- libpanorama/trunk/src/vips/plug.c 2007-07-10 22:57:52 UTC (rev 2253) +++ libpanorama/trunk/src/vips/plug.c 2007-07-11 07:06:00 UTC (rev 2254) @@ -46,12 +46,14 @@ { IMAGE *out, *outMask; char outputImageMask[100]; + int iType; out = argv[2]; sprintf(outputImageMask, "%sMask.v", "output"); outMask = im_open_local(out, outputImageMask, "w"); + iType = *((int *) argv[4]); - if (output_resample_image (argv[0], argv[1], out, outMask, argv[3], argv[4])) + if (output_resample_image (argv[0], argv[1], out, outMask, argv[3], iType)) error_exit ("unable to run operation"); return 0; Modified: libpanorama/trunk/src/vips/resample.c =================================================================== --- libpanorama/trunk/src/vips/resample.c 2007-07-10 22:57:52 UTC (rev 2253) +++ libpanorama/trunk/src/vips/resample.c 2007-07-11 07:06:00 UTC (rev 2254) @@ -9,7 +9,7 @@ #include "interpolation.h" -int findBoundary(REGION *or, Rect *out, IMAGE *im, int *intType) +int findBoundary(REGION *or, Rect *out, IMAGE *im, int intType) { /*printf("in FB\n");*/ Rect *in; @@ -25,10 +25,11 @@ p = (double *) IM_REGION_ADDR (or, le, to); px = p[0]; py = p[1]; - pxi = (int)px; - pyi = (int)py; + pxi = (int)(px+0.5); + pyi = (int)(py+0.5); xmax = pxi; xmin = pxi; ymax = pyi; ymin = pyi; + xmax = -1; xmin = im->Xsize-(2*intType); ymax = -1; ymin = im->Ysize-(2*intType); /*printf("FB:left = %d\twidth = %d\ttop = %d\theight = %d\n", in->left, in->width, in->top, in->height);*/ @@ -40,11 +41,11 @@ py = p[1]; p += 2; - pxi = (int)px; - pyi = (int)py; + pxi = (int)(px+0.5); + pyi = (int)(py+0.5); - if (pxi < im->Xsize- *intType && pxi >= *intType && pyi < im->Ysize- *intType && - pyi >= *intType) { + if (pxi < (im->Xsize-(2*intType)) && pxi >= 0 && pyi < (im->Ysize-(2*intType)) && + pyi >= 0) { if(pxi > xmax) xmax = pxi; @@ -60,40 +61,48 @@ } } - if(xmax == xmin || ymax == ymin) { + /*if(xmax == xmin || ymax == ymin) { */ + if(xmax < xmin || ymax < ymin) { /*printf("xmax = %d, xmin = %d, ymax = %d, ymin = %d\n", xmax, xmin, ymax, ymin);*/ return -1; } else { - out->top = ymin - *intType; - out->left = xmin - *intType; - out->height = ymax + *intType - ymin; - out->width = xmax + *intType - xmin; + out->top = ymin - 0; + out->left = xmin - 0; + out->height = ymax + (2*intType) - ymin; + out->width = xmax + (2*intType) - xmin; } - /*printf("FB:left = %d\twidth = %d\ttop = %d\theight = %d\n", out->left, out->width, out->top, - out->height);*/ + /*printf("input:left = %d\twidth = %d\ttop = %d\theight = %d\n", out->left, out->width, + out->top, out->height);*/ return 0; } static int -output_resample_image_gen( REGION *or, REGION **ir, IMAGE **vec, int *intType) +output_resample_image_gen( REGION *or, REGION **ir, IMAGE **vec, int iType) { Rect inRect, *r; - int le, to, ri, bo, x, y; + int le, to, ri, bo, x, y, pxi, pyi; double *p, px, py; unsigned char *q, *s; + /*printf("interpolation type: %d, %d\n", iType, intType);*/ + /*if(iType != 3) + return -1;*/ + r = &or->valid; le = r->left; to = r->top; ri = IM_RECT_RIGHT( r ); bo = IM_RECT_BOTTOM( r ); + /*printf("output/coordinate:left = %d\twidth = %d\ttop = %d\theight = %d\n", r->left, + r->width, r->top, r->height);*/ + if(im_prepare(ir[0], r)) { return -1; } - if(!findBoundary(ir[0], &inRect, vec[1], intType)) + if(!findBoundary(ir[0], &inRect, vec[1], iType)) if( (im_prepare(ir[1], &inRect)) || (im_prepare(ir[2], &inRect))) { return -1; } @@ -107,23 +116,32 @@ for( x = le; x < ri; x++ ) { px = p[0]; py = p[1]; + pxi = (int)(px+0.5); + pyi = (int)(py+0.5); p += 2; - s = (unsigned char *) IM_REGION_ADDR (ir[2], (int) px, (int) py); + /*s = (unsigned char *) IM_REGION_ADDR (ir[2], (int) (px+0.5), (int) (py+0.5));*/ - if (px < (vec[1]->Xsize - *intType) && px >= *intType && - py < (vec[1]->Ysize - *intType) && py >= *intType && (*s == 255)) { - switch (*intType) { + if (pxi < (vec[1]->Xsize - 2*iType) && pxi >= 0 && + pyi < (vec[1]->Ysize - 2*iType) && pyi >= 0 /*&& (*s == 255)*/) { + switch (iType) { case 0: - memcpy (q, IM_REGION_ADDR (ir[1], (int) px, (int) py), ps); + s = (unsigned char *) IM_REGION_ADDR (ir[2], (int) (px+0.5), + (int) (py+0.5)); + if(*s == 255) + memcpy (q, IM_REGION_ADDR (ir[1], (int) (px+0.5), (int) (py+0.5)), ps); + else + memset (q, 0, ps); break; case 1: - billinearInterpolation(q, ir[1], px, py, ps); + if(billinearInterpolation(q, ir[1], ir[2], px, py, ps)) + memset (q, 0, ps); break; - case 2: - bicubicInterpolation(q, ir[1], px, py, ps); + case 3: + if(bicubicInterpolation(q, ir[1], ir[2], px, py, ps)) + memset (q, 0, ps); break; default: @@ -190,34 +208,50 @@ int -output_resample_image (IMAGE * coordinate, IMAGE * in, IMAGE * out, IMAGE *outMask, IMAGE *inMask, int *intType) +output_resample_image (IMAGE * coordinate, IMAGE * in, IMAGE * out, IMAGE *outMask, IMAGE *inMask, int intType) { - IMAGE **vec; + IMAGE **vec, *inXpnd, *inMaskXpnd; + int xpndFactor; /*printf("starting output resample image ....\n");*/ - if(*intType > maxDefined) { + if(intType > maxDefined) { im_error ("output_resample_image", "undefined interpolation type"); return -1; - } + } else { + if(intType == BICUBIC) + xpndFactor = 3; + else + xpndFactor = intType; + } if (im_piocheck (coordinate, out)) return -1; if (im_pincheck (in)) return -1; - IMAGE *inXpnd = im_open_local(out, "inXpnd", "p"); + inXpnd = im_open_local(out, "inXpnd", "p"); + inMaskXpnd = im_open_local(out, "inMaskXpnd", "p"); if (im_poutcheck (inXpnd)) return -1; - /*printf("b4 embedding\n");*/ - if(im_embed( in, inXpnd, 1, *intType, *intType, in->Xsize + *intType, in->Ysize + *intType )) + printf("b4 embedding - expand factor: %d\n", xpndFactor); + if(im_embed( in, inXpnd, 1, xpndFactor, xpndFactor, in->Xsize + (2*xpndFactor), + in->Ysize + (2*xpndFactor) )) return (-1); - /*else + else { printf("embedding successful: new height: %d, new width %d\n", inXpnd->Xsize, inXpnd->Ysize); } - printf("after checking IO\n");*/ + if(im_embed( inMask, inMaskXpnd, 1, xpndFactor, xpndFactor, inMask->Xsize + (2*xpndFactor), + inMask->Ysize + (2*xpndFactor) )) + return (-1); + else + { + printf("mask embedding successful: new height: %d, new width %d\n", inMaskXpnd->Xsize, + inMaskXpnd->Ysize); + } + printf("after checking IO\n"); if (coordinate->Coding != IM_CODING_NONE || coordinate->Bands != 2 || coordinate->BandFmt != IM_BANDFMT_DOUBLE) { @@ -246,14 +280,14 @@ /*printf("b4 calling demand\n");*/ - if( im_demand_hint( out, IM_SMALLTILE, coordinate, inXpnd, inMask, NULL ) ) + if( im_demand_hint( out, IM_SMALLTILE, coordinate, inXpnd, inMaskXpnd, NULL ) ) return( -1 ); - if( !(vec = im_allocate_input_array( out, coordinate, inXpnd, inMask, NULL )) ) + if( !(vec = im_allocate_input_array( out, coordinate, inXpnd, inMaskXpnd, NULL )) ) return( -1 ); - /*printf("b4 calling generate function\n");*/ + printf("b4 calling generate function"); if( im_generate( out, - im_start_many, output_resample_image_gen, im_stop_many, vec, intType ) ) + im_start_many, output_resample_image_gen, im_stop_many, vec, (int *)xpndFactor ) ) return( -1 ); if( im_demand_hint( outMask, IM_SMALLTILE, coordinate, NULL ) ) Modified: libpanorama/trunk/src/vips/resample.h =================================================================== --- libpanorama/trunk/src/vips/resample.h 2007-07-10 22:57:52 UTC (rev 2253) +++ libpanorama/trunk/src/vips/resample.h 2007-07-11 07:06:00 UTC (rev 2254) @@ -1,9 +1,11 @@ #ifndef __RESAMPLE_H__ #define __RESAMPLE_H__ +#define DEBUG + #include <vips/vips.h> -int output_resample_image( IMAGE *coordinate, IMAGE *in, IMAGE *out, IMAGE *outMask, IMAGE *inMask, int *intType); +int output_resample_image( IMAGE *coordinate, IMAGE *in, IMAGE *out, IMAGE *outMask, IMAGE *inMask, int intType); #endif Modified: libpanorama/trunk/src/vips/transmap.c =================================================================== --- libpanorama/trunk/src/vips/transmap.c 2007-07-10 22:57:52 UTC (rev 2253) +++ libpanorama/trunk/src/vips/transmap.c 2007-07-11 07:06:00 UTC (rev 2254) @@ -5,6 +5,8 @@ #include <stdarg.h> #include <assert.h> +#define DEBUG + #include <vips/vips.h> #include <parser/tparser.h> #include "transform.h" @@ -36,9 +38,8 @@ char outputImage[100], outputImageMask[100]; IMAGE *out, *coordImage, *input; IMAGE *outMask, *tmpMask[4]; - int interpolationType = 2, a, b; - int *type; - type = &interpolationType; + int type = 2; + static const char *suffs[] = { ".tif", ".tiff", ".png", NULL }; sprintf(outputImage, "%s%d.tif", "out", i); sprintf(outputImageMask, "%s%dMask.v", "out", i); @@ -59,12 +60,13 @@ if (!(input = im_open_local (out, inputImg->name, "r"))) error_exit ("unable to run operation\n"); - a = isFormat(out, inputImg->name, "tif"); + + /*a = isFormat(out, inputImg->name, "tif"); b = isFormat(out, inputImg->name, "png"); if(a == -1 || b == -1) - error_exit ("unable to run operation\n"); + error_exit ("unable to run operation\n");*/ - if((a && b) && (input->Bands == 4)) { + if(im_filename_suffix_match(inputImg->name, suffs ) && (input->Bands == 4)) { if(im_extract_band(input, tmpMask[0], 3) || im_moreconst(tmpMask[0], tmpMask[1], 127.0)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |