Changeset 11649 for ImageMagick/trunk

Show
Ignore:
Timestamp:
07/17/08 06:48:49 (6 weeks ago)
Author:
anthony
Message:

Adding Shepards Method as a method of Distortion

Location:
ImageMagick/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • ImageMagick/trunk/ChangeLog

    r11612 r11649  
     12008-07-17  6.4.2-4 Anthony <anthony@griffith...> 
     2  * New distortions  Shepards which provide semi-localized distorts of single 
     3    points within an image.  Almost like taffy pulling! 
     4 
    152008-07-12  6.4.2-2 Anthony <anthony@griffith...> 
    26  * Separate coefficient calculation from DistortImages (future development) 
     
    59  * Affine Distortion now handles 2 point pairs (SRT of a single line) 
    610    and a simple translation if only a single point pair is provided. 
     11  * Added 'verbose' output of some of the distortion equations generated 
     12  * Initial addition of polynomal distortion (incomplete - not working yet) 
    713 
    8142008-06-29  6.4.2-2 Cristy  <quetzlzacatenango@image...> 
  • ImageMagick/trunk/magick/distort.c

    r11648 r11649  
    8686%  account in the mapping. 
    8787% 
     88%  If the '-verbose' control option has been set print to standard error the 
     89%  equicelent '-fx' formula with coefficients for the function, if practical. 
     90% 
    8891% 
    8992%  The format of the DistortImage() method is: 
     
    197200} 
    198201 
    199 #if 0   
     202 
     203 
     204#if 0 
    200205   For some reason compiler errors on % in this! 
    201206static inline double MagickFraction(double x) 
     
    340345static double *DistortCoefficents(Image *image, DistortImageMethod *method, 
    341346     const unsigned long number_arguments, const double *arguments, 
    342      MagickBooleanType bestfit, ExceptionInfo *exception) 
     347     ExceptionInfo *exception) 
    343348{ 
    344349  /* Determine correct coefficients for the given input arguments. 
     
    388393      break; 
    389394    case PolynomialDistortion: 
     395      /* number of coefficents depend on the given polynomal 'order' */ 
    390396      if ( number_arguments < 5 && (number_arguments-1)%4 != 0) 
    391397      { 
     
    415421      number_coefficients=5; 
    416422      break; 
     423    case ShepardsDistortion: 
     424      number_coefficients=1; /* not actually used, but keep things happy */ 
     425      break; 
    417426    case UndefinedDistortion: 
    418427    default: 
     
    420429      break; 
    421430  } 
     431  if ( number_coefficients == 0 ) 
     432    return((double *) NULL); 
    422433 
    423434  /* allocate the array of coefficients needed */ 
     
    430441    return((double *) NULL); 
    431442  } 
     443 
    432444  /* zero out coeffiecents array */ 
    433445  for (i=0; i < (long)number_coefficients; i++) 
     
    909921         And convert to affine mapping coefficients 
    910922      */ 
    911       x = nx = (double)image->columns/2.0; 
    912       y = ny = (double)image->rows/2.0; 
    913       if ( bestfit ) { 
    914         x = nx += (double)image->page.x; 
    915         y = ny += (double)image->page.y; 
    916       } 
     923      x = nx = (double)image->columns/2.0 + image->page.x; 
     924      y = ny = (double)image->rows/2.0    + image->page.x; 
    917925      sx = sy = 1.0; 
    918926      switch ( number_arguments ) { 
     
    10781086      } 
    10791087      coefficients[4] = (1.0*image->columns-1.0)/2.0; 
     1088#if 0 
     1089Not working yet -- 
    10801090      if ( GetImageArtifact(image,"verbose") != (const char *) NULL ) { 
    10811091        fprintf(stderr, "Arc Reverse Map\n"); 
    1082 #if 0 
    1083   Not working yet 
    10841092        fprintf(stderr, "c0=%-8lg  # angle for center line in source image\n", 
    10851093             coefficients[0]); 
     
    11141122            coefficients[2], ((double)image->rows)/coefficients[3] ); 
    11151123        fprintf(stderr, "       v.p{xx,yy}'\n"); 
     1124      } 
    11161125#endif 
     1126      return(coefficients); 
     1127    } 
     1128    case ShepardsDistortion: 
     1129    { 
     1130      /* Shepards Distortion  input arguments are the coefficents! 
     1131         Args:  power  u1,v1, x1,y1, ... 
     1132      */ 
     1133      if ( number_arguments < 4 && (number_arguments-1)%4 != 0) 
     1134      { 
     1135        (void) ThrowMagickException(exception,GetMagickModule(),OptionError, 
     1136                     "InvalidArgument","%s : '%s'","distort Shepards", 
     1137                     "Invalid number of coord-pairs: [sX,sY,dX,dY]*"); 
     1138        return((double *) arguments); 
    11171139      } 
    11181140      return(coefficients); 
     
    11751197    So these no longer need to be considered below. 
    11761198  */ 
    1177   coefficients = DistortCoefficents(image, &method, number_arguments, 
    1178        arguments, bestfit, exception); 
    1179   if ( coefficients == (double *) NULL ) 
    1180     return((Image *) NULL); 
     1199  if ( method == ShepardsDistortion ) 
     1200    /* these methods do not require coefficents */ 
     1201    coefficients = (double *)NULL; 
     1202  else { 
     1203    /* determine the coefficents needed for distortion from input */ 
     1204    coefficients = DistortCoefficents(image, &method, number_arguments, 
     1205        arguments, exception); 
     1206    if ( coefficients == (double *) NULL ) 
     1207      return((Image *) NULL); 
     1208  } 
    11811209 
    11821210  /* 
     
    13121340        break; 
    13131341      } 
     1342      case ShepardsDistortion: 
    13141343      case BilinearDistortion: 
    13151344      case PolynomialDistortion: 
     
    15241553          if ( point.y > MagickEpsilon ) 
    15251554            ScaleResampleFilter( resample_filter[id], 
    1526                 coefficients[1]/(2*MagickPI*point.y),0,0,coefficients[3] );  
     1555                coefficients[1]/(2*MagickPI*point.y),0,0,coefficients[3] ); 
    15271556          else 
    15281557            ScaleResampleFilter( resample_filter[id], 
     
    15321561          point.x = point.x*coefficients[1] + coefficients[4]; 
    15331562          point.y = (coefficients[2] - point.y) * coefficients[3]; 
     1563          break; 
     1564        } 
     1565        case ShepardsDistortion: 
     1566        { /* Shepards Method, or Inverse Weighted Distance for 
     1567             displacement around the destination image control points 
     1568             Its coefficents, is the input arguments 
     1569          */ 
     1570          unsigned long 
     1571            i; 
     1572          double 
     1573            denominator; 
     1574 
     1575          denominator = point.x = point.y = 0; 
     1576          for(i=0; i<number_arguments; i+=4) { 
     1577            double weight = 
     1578                ((double)x-arguments[i+2])*((double)x-arguments[i+2]) 
     1579              + ((double)y-arguments[i+3])*((double)y-arguments[i+3]); 
     1580            if ( weight != 0 ) 
     1581              weight = 1/weight; 
     1582            else 
     1583              weight = 1; 
     1584 
     1585            point.x += (arguments[ i ]-arguments[i+2])*weight; 
     1586            point.y += (arguments[i+1]-arguments[i+3])*weight; 
     1587            denominator += weight; 
     1588          } 
     1589          point.x /= denominator; 
     1590          point.y /= denominator; 
     1591          point.x += x; point.y += y; 
     1592 
     1593          /* we can not determine slope using shepards method - interpolate */ 
    15341594          break; 
    15351595        } 
     
    15391599            Noop distortion (failsafe) should not happen! 
    15401600          */ 
    1541           point.x=(double) i; 
    1542           point.y=(double) j; 
     1601          point.x=(double) x; 
     1602          point.y=(double) y; 
    15431603          break; 
    15441604        } 
     
    15771637  resample_filter=DestroyResampleFilterThreadSet(resample_filter); 
    15781638 
     1639 
    15791640  /* Arc does not return an offset unless 'bestfit' is in effect 
    15801641     And the user has not provided an overriding 'viewport'. 
     
    15861647  if (status == MagickFalse) 
    15871648    distort_image=DestroyImage(distort_image); 
     1649 
     1650  coefficients = RelinquishMagickMemory(coefficients); 
    15881651  return(distort_image); 
    15891652} 
  • ImageMagick/trunk/magick/distort.h

    r11623 r11649  
    3535  PerspectiveProjectionDistortion, 
    3636  PolynomialDistortion, 
    37   ScaleRotateTranslateDistortion 
     37  ScaleRotateTranslateDistortion, 
     38  ShepardsDistortion, 
    3839} DistortImageMethod; 
    3940 
  • ImageMagick/trunk/magick/option.c

    r11624 r11649  
    787787    { "SRT", (long) ScaleRotateTranslateDistortion }, 
    788788    { "Arc", (long) ArcDistortion }, 
     789    { "Shepards", (long) ShepardsDistortion }, 
    789790    { (char *) NULL, (long) UndefinedDistortion } 
    790791  },