Changeset 8813


Ignore:
Timestamp:
08/02/12 09:23:28 (10 months ago)
Author:
anthony
Message:

Adding a binomial kernel (for Fred)

Location:
ImageMagick/trunk/MagickCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ImageMagick/trunk/MagickCore/morphology.c

    r8252 r8813  
    114114#define Minimize(assign,value) assign=MagickMin(assign,value) 
    115115#define Maximize(assign,value) assign=MagickMax(assign,value) 
     116 
     117/* Integer Factorial Function - for a Binomial kernel */ 
     118#if 1 
     119static inline size_t fact(size_t n) 
     120{ 
     121  size_t l,f; 
     122  for(f=1, l=2; l <= n; f=f*l, l++); 
     123  return(f); 
     124} 
     125#elif 1 /* glibc floating point alternatives */ 
     126#define fact(n) ((size_t)tgamma((double)n+1)) 
     127#else 
     128#define fact(n) ((size_t)lgamma((double)n+1)) 
     129#endif 
     130 
    116131 
    117132/* Currently these are only internal to this module */ 
     
    634649%       radius of the kernel. 
    635650% 
     651%    Binomial:[{radius}] 
     652%       Generate a discrete kernel using a 2 dimentional Pascel's Triangle 
     653%       of values. 
     654% 
    636655%    # Still to be implemented... 
    637656%    # 
     
    9961015    case BlurKernel: 
    9971016    case CometKernel: 
     1017    case BinomialKernel: 
    9981018    case DiamondKernel: 
    9991019    case SquareKernel: 
     
    12881308        ScaleKernelInfo(kernel, 1.0, NormalizeValue); /* Normalize */ 
    12891309        RotateKernelInfo(kernel, args->xi); /* Rotate by angle */ 
     1310        break; 
     1311      } 
     1312    case BinomialKernel: 
     1313      { 
     1314        size_t 
     1315          order_f; 
     1316 
     1317        if (args->rho < 1.0) 
     1318          kernel->width = kernel->height = 3;  /* default radius = 1 */ 
     1319        else 
     1320          kernel->width = kernel->height = ((size_t)args->rho)*2+1; 
     1321        kernel->x = kernel->y = (ssize_t) (kernel->width-1)/2; 
     1322 
     1323        order_f = fact(kernel->width-1); 
     1324 
     1325        kernel->values=(double *) AcquireAlignedMemory(kernel->width, 
     1326          kernel->height*sizeof(*kernel->values)); 
     1327        if (kernel->values == (double *) NULL) 
     1328          return(DestroyKernelInfo(kernel)); 
     1329 
     1330        /* set all kernel values within diamond area to scale given */ 
     1331        for ( i=0, v=0; v < (ssize_t)kernel->height; v++) 
     1332          { size_t 
     1333              alpha = order_f / ( fact(v) * fact(kernel->height-v-1) ); 
     1334            for ( u=0; u < (ssize_t)kernel->width; u++, i++) 
     1335              kernel->positive_range += kernel->values[i] = (double) 
     1336                (alpha * order_f / ( fact(u) * fact(kernel->height-u-1) )); 
     1337          } 
     1338        kernel->minimum = 1.0; 
     1339        kernel->maximum = kernel->values[kernel->x+kernel->y*kernel->width]; 
     1340        kernel->negative_range = 0.0; 
    12901341        break; 
    12911342      } 
  • ImageMagick/trunk/MagickCore/morphology.h

    r7570 r8813  
    3434  BlurKernel, 
    3535  CometKernel, 
     36  BinomialKernel, 
    3637  LaplacianKernel,    /* Convolution Kernels, by Name */ 
    3738  SobelKernel, 
  • ImageMagick/trunk/MagickCore/option.c

    r8775 r8813  
    11181118    { "Blur", BlurKernel, UndefinedOptionFlag, MagickFalse }, 
    11191119    { "Comet", CometKernel, UndefinedOptionFlag, MagickFalse }, 
     1120    { "Binomial", BinomialKernel, UndefinedOptionFlag, MagickFalse }, 
    11201121    { "Laplacian", LaplacianKernel, UndefinedOptionFlag, MagickFalse }, 
    11211122    { "Sobel", SobelKernel, UndefinedOptionFlag, MagickFalse }, 
     
    17101711%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
    17111712% 
    1712 %  CloneImageOptions() clones one or more image options. 
     1713%  CloneImageOptions() clones all global image options, to another image_info 
    17131714% 
    17141715%  The format of the CloneImageOptions method is: 
     
    17191720%  A description of each parameter follows: 
    17201721% 
    1721 %    o image_info: the image info. 
    1722 % 
    1723 %    o clone_info: the clone image info. 
     1722%    o image_info: the image info to recieve the cloned options. 
     1723% 
     1724%    o clone_info: the source image info for options to clone. 
    17241725% 
    17251726*/ 
     
    17521753% 
    17531754%  DefineImageOption() associates an assignment string of the form 
    1754 %  "key=value" with an image option. It is equivelent to SetImageOption(). 
     1755%  "key=value" with a global image option. It is equivelent to 
     1756%  SetImageOption(). 
    17551757% 
    17561758%  The format of the DefineImageOption method is: 
     
    18001802%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
    18011803% 
    1802 %  DeleteImageOption() deletes an key from the image map. 
     1804%  DeleteImageOption() deletes an key from the global image options. 
    18031805% 
    18041806%  Returns MagickTrue is the option is found and deleted from the Options. 
     
    18401842%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
    18411843% 
    1842 %  DestroyImageOptions() releases memory associated with image option values. 
     1844%  DestroyImageOptions() destroys all global options and associated memory 
     1845%  attached to the given image_info image list. 
    18431846% 
    18441847%  The format of the DestroyDefines method is: 
     
    18731876%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
    18741877% 
    1875 %  GetImageOption() gets a value associated with an image option. 
     1878%  GetImageOption() gets a value associated with the global image options. 
     1879% 
     1880%  The returned string is a constant string in the tree and should NOT be 
     1881%  freed by the caller. 
    18761882% 
    18771883%  The format of the GetImageOption method is: 
     
    21522158%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
    21532159% 
    2154 %  GetNextImageOption() gets the next image option value. 
     2160%  GetNextImageOption() gets the next global option value. 
    21552161% 
    21562162%  The format of the GetNextImageOption method is: 
     
    25962602%  RemoveImageOption() removes an option from the image and returns its value. 
    25972603% 
     2604%  In this case the ConstantString() value returned should be freed by the 
     2605%  caller when finished. 
     2606% 
    25982607%  The format of the RemoveImageOption method is: 
    25992608% 
     
    26362645% 
    26372646%  ResetImageOptions() resets the image_info option.  That is, it deletes 
    2638 %  all options associated with the image_info structure. 
     2647%  all global options associated with the image_info structure. 
    26392648% 
    26402649%  The format of the ResetImageOptions method is: 
     
    27402749      RelinquishMagickMemory,RelinquishMagickMemory); 
    27412750 
    2742   /* Delete Option if NULL */ 
     2751  /* Delete Option if NULL --  empty string values are valid! */ 
    27432752  if (value == (const char *) NULL) 
    27442753    return(DeleteImageOption(image_info,option)); 
Note: See TracChangeset for help on using the changeset viewer.