Changeset 11649 for ImageMagick/trunk
- Timestamp:
- 07/17/08 06:48:49 (6 weeks ago)
- Location:
- ImageMagick/trunk
- Files:
-
- 4 modified
-
ChangeLog (modified) (2 diffs)
-
magick/distort.c (modified) (17 diffs)
-
magick/distort.h (modified) (1 diff)
-
magick/option.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
ImageMagick/trunk/ChangeLog
r11612 r11649 1 2008-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 1 5 2008-07-12 6.4.2-2 Anthony <anthony@griffith...> 2 6 * Separate coefficient calculation from DistortImages (future development) … … 5 9 * Affine Distortion now handles 2 point pairs (SRT of a single line) 6 10 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) 7 13 8 14 2008-06-29 6.4.2-2 Cristy <quetzlzacatenango@image...> -
ImageMagick/trunk/magick/distort.c
r11648 r11649 86 86 % account in the mapping. 87 87 % 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 % 88 91 % 89 92 % The format of the DistortImage() method is: … … 197 200 } 198 201 199 #if 0 202 203 204 #if 0 200 205 For some reason compiler errors on % in this! 201 206 static inline double MagickFraction(double x) … … 340 345 static double *DistortCoefficents(Image *image, DistortImageMethod *method, 341 346 const unsigned long number_arguments, const double *arguments, 342 MagickBooleanType bestfit,ExceptionInfo *exception)347 ExceptionInfo *exception) 343 348 { 344 349 /* Determine correct coefficients for the given input arguments. … … 388 393 break; 389 394 case PolynomialDistortion: 395 /* number of coefficents depend on the given polynomal 'order' */ 390 396 if ( number_arguments < 5 && (number_arguments-1)%4 != 0) 391 397 { … … 415 421 number_coefficients=5; 416 422 break; 423 case ShepardsDistortion: 424 number_coefficients=1; /* not actually used, but keep things happy */ 425 break; 417 426 case UndefinedDistortion: 418 427 default: … … 420 429 break; 421 430 } 431 if ( number_coefficients == 0 ) 432 return((double *) NULL); 422 433 423 434 /* allocate the array of coefficients needed */ … … 430 441 return((double *) NULL); 431 442 } 443 432 444 /* zero out coeffiecents array */ 433 445 for (i=0; i < (long)number_coefficients; i++) … … 909 921 And convert to affine mapping coefficients 910 922 */ 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; 917 925 sx = sy = 1.0; 918 926 switch ( number_arguments ) { … … 1078 1086 } 1079 1087 coefficients[4] = (1.0*image->columns-1.0)/2.0; 1088 #if 0 1089 Not working yet -- 1080 1090 if ( GetImageArtifact(image,"verbose") != (const char *) NULL ) { 1081 1091 fprintf(stderr, "Arc Reverse Map\n"); 1082 #if 01083 Not working yet1084 1092 fprintf(stderr, "c0=%-8lg # angle for center line in source image\n", 1085 1093 coefficients[0]); … … 1114 1122 coefficients[2], ((double)image->rows)/coefficients[3] ); 1115 1123 fprintf(stderr, " v.p{xx,yy}'\n"); 1124 } 1116 1125 #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); 1117 1139 } 1118 1140 return(coefficients); … … 1175 1197 So these no longer need to be considered below. 1176 1198 */ 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 } 1181 1209 1182 1210 /* … … 1312 1340 break; 1313 1341 } 1342 case ShepardsDistortion: 1314 1343 case BilinearDistortion: 1315 1344 case PolynomialDistortion: … … 1524 1553 if ( point.y > MagickEpsilon ) 1525 1554 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] ); 1527 1556 else 1528 1557 ScaleResampleFilter( resample_filter[id], … … 1532 1561 point.x = point.x*coefficients[1] + coefficients[4]; 1533 1562 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 */ 1534 1594 break; 1535 1595 } … … 1539 1599 Noop distortion (failsafe) should not happen! 1540 1600 */ 1541 point.x=(double) i;1542 point.y=(double) j;1601 point.x=(double) x; 1602 point.y=(double) y; 1543 1603 break; 1544 1604 } … … 1577 1637 resample_filter=DestroyResampleFilterThreadSet(resample_filter); 1578 1638 1639 1579 1640 /* Arc does not return an offset unless 'bestfit' is in effect 1580 1641 And the user has not provided an overriding 'viewport'. … … 1586 1647 if (status == MagickFalse) 1587 1648 distort_image=DestroyImage(distort_image); 1649 1650 coefficients = RelinquishMagickMemory(coefficients); 1588 1651 return(distort_image); 1589 1652 } -
ImageMagick/trunk/magick/distort.h
r11623 r11649 35 35 PerspectiveProjectionDistortion, 36 36 PolynomialDistortion, 37 ScaleRotateTranslateDistortion 37 ScaleRotateTranslateDistortion, 38 ShepardsDistortion, 38 39 } DistortImageMethod; 39 40 -
ImageMagick/trunk/magick/option.c
r11624 r11649 787 787 { "SRT", (long) ScaleRotateTranslateDistortion }, 788 788 { "Arc", (long) ArcDistortion }, 789 { "Shepards", (long) ShepardsDistortion }, 789 790 { (char *) NULL, (long) UndefinedDistortion } 790 791 },
