Mitchell interpolation definition

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
gubach
Posts: 45
Joined: 2013-12-13T11:13:29-07:00
Authentication code: 6789

Mitchell interpolation definition

Post by gubach »

Hello,
I want to define the Mitchell function as a custom interpolation kernel in Matlabs imresize (examples in http://stackoverflow.com/questions/8036 ... ion-kernel). First step would be the definition of the Mitchel filter and in http://www.imagemagick.org/Usage/filter/#mitchell I read „IM uses the same internal function to generate all cubic filters, only with different B,C settings“ which is super because this whole kernel class could be covered then in imresize. Has someone the used function definition or point me to the used code? Thank you very much!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Mitchell interpolation definition

Post by snibgo »

The source code is in resize.c.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Mitchell interpolation definition

Post by fmw42 »

gubach
Posts: 45
Joined: 2013-12-13T11:13:29-07:00
Authentication code: 6789

Re: Mitchell interpolation definition

Post by gubach »

Thanks snibgo and fmw42!

Found this in resize.c and http://http.developer.nvidia.com/GPUGem ... _ch24.html :

Code: Select all

static double CubicBC(const double x,const ResizeFilter *resize_filter)
{
  /*
    Cubic Filters using B,C determined values:
       Mitchell-Netravali  B = 1/3 C = 1/3  "Balanced" cubic spline filter
       Catmull-Rom         B = 0   C = 1/2  Interpolatory and exact on linears
       Spline              B = 1   C = 0    B-Spline Gaussian approximation
       Hermite             B = 0   C = 0    B-Spline interpolator

    See paper by Mitchell and Netravali, Reconstruction Filters in Computer
    Graphics Computer Graphics, Volume 22, Number 4, August 1988
    http://www.cs.utexas.edu/users/fussell/courses/cs384g/lectures/mitchell/
    Mitchell.pdf.

    Coefficents are determined from B,C values:
       P0 = (  6 - 2*B       )/6 = coeff[0]
       P1 =         0
       P2 = (-18 +12*B + 6*C )/6 = coeff[1]
       P3 = ( 12 - 9*B - 6*C )/6 = coeff[2]
       Q0 = (      8*B +24*C )/6 = coeff[3]
       Q1 = (    -12*B -48*C )/6 = coeff[4]
       Q2 = (      6*B +30*C )/6 = coeff[5]
       Q3 = (    - 1*B - 6*C )/6 = coeff[6]

    which are used to define the filter:

       P0 + P1*x + P2*x^2 + P3*x^3      0 <= x < 1
       Q0 + Q1*x + Q2*x^2 + Q3*x^3      1 <= x < 2

    which ensures function is continuous in value and derivative (slope).
  */
  if (x < 1.0)
    return(resize_filter->coefficient[0]+x*(x*
      (resize_filter->coefficient[1]+x*resize_filter->coefficient[2])));
  if (x < 2.0)
    return(resize_filter->coefficient[3]+x*(resize_filter->coefficient[4]+x*
      (resize_filter->coefficient[5]+x*resize_filter->coefficient[6])));
  return(0.0);
}

Code: Select all

// Mitchell Netravali Reconstruction Filter

   // B = 1,   C = 0   - cubic B-spline

   // B = 1/3, C = 1/3 - recommended

   // B = 0,   C = 1/2 - Catmull-Rom spline


   float MitchellNetravali(float x, float B, float C)
{
  float ax = fabs(x);
  if (ax < 1) {
    return ((12 - 9 * B - 6 * C) * ax * ax * ax +
            (-18 + 12 * B + 6 * C) * ax * ax + (6 - 2 * B)) / 6;
  } else if ((ax >= 1) && (ax < 2)) {
      return ((-B - 6 * C) * ax * ax * ax +
              (6 * B + 30 * C) * ax * ax + (-12 * B - 48 * C) *
              ax + (8 * B + 24 * C)) / 6;
  } else {
      return 0;
  }
}
Post Reply