Yalantis/uCrop · error · CImgArgumentException

deriche(): Invalid specified axis '%c'.

Error message

deriche(): Invalid specified axis '%c'.

What it means

CImg's deriche() applies the recursive Deriche filter along one axis ('x','y','z' or 'c', case-insensitive after lowercase()). Any other character throws this error because the filter cannot resolve which image dimension to run along.

Solutions

  1. Pass one of 'x','y','z','c' (any case) as the axis argument
  2. Validate/normalize the axis string from config or user input before the call
  3. For a 2D image remember 'z' and 'c' are only valid if depth/spectrum > 1 conceptually, though the check here only validates the character

Example fix

// before
img.deriche(2.0f, 1, 'w');
// after
img.deriche(2.0f, 1, 'x');
Defensive patterns

Strategy: validation

Validate before calling

const char valid[] = {'x','y','z','c'};
if (!strchr(valid, (char)std::tolower((unsigned char)axis))) axis = 'x';

Type guard

bool validAxis(char a) { a = std::tolower((unsigned char)a); return a=='x'||a=='y'||a=='z'||a=='c'; }

Try / catch

try {
  img.deriche(sigma, order, axis);
} catch (cimg_library::CImgArgumentException& e) {
  img.deriche(sigma, order, 'x');
}

Prevention

When it happens

Trigger: Calling img.deriche(sigma, order, axis) with axis like 'X' handled fine but 'w','h','0', or an uninitialized char throwing; passing axis values from an external config mapping that uses different axis names.

Common situations: Typo in the axis parameter ('xx', 'X-axis'); axis read from user input or a config file with unexpected values; forgetting that CImg uses x/y/z/c not width/height.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/618331018150347b. Report an issue: GitHub.

Appendix: source

Thrown at ucrop/src/main/jni/CImg.h:43763

  double yn = 0, ya = 0; \
  if (boundary_conditions) { xn = xa = *(ptrX - off); yn = ya = (double)coefn*xn; } \
  for (int n = N - 1; n>=0; --n) { \
    const T xc = *(ptrX-=off); \
    const double yc = (double)(a2*xn + a3*xa - b1*yn - b2*ya); \
    xa = xn; xn = xc; ya = yn; yn = yc; \
    *ptrX = (T)(*(--ptrY)+yc); \
  }

      if (order>2)
        throw CImgArgumentException(_cimg_instance
                                    "deriche(): Invalid specified order '%d' "
                                    "('order' can be { 0=smoothing | 1=1st-derivative | 2=2nd-derivative }).",
                                    cimg_instance,
                                    order);

      const char naxis = cimg::lowercase(axis);
      if (naxis!='x' && naxis!='y' && naxis!='z' && naxis!='c')
        throw CImgArgumentException(_cimg_instance
                                    "deriche(): Invalid specified axis '%c'.",
                                    cimg_instance,
                                    axis);
      const double
        nsigma = sigma>=0?sigma:-sigma*(naxis=='x'?_width:
                                        naxis=='y'?_height:
                                        naxis=='z'?_depth:_spectrum)/100,
        nnsigma = nsigma<0.1f?0.1f:nsigma;

      if (is_empty() || (nsigma<0.1f && !order)) return *this;
      if (boundary_conditions>1) {
        const int w = width(), h = height(), d = depth(), s = spectrum(), border = (int)cimg::round(1 + 3*nnsigma);
        switch (naxis) {
        case 'x' :
          return draw_image(get_resize(w + 2*border,h,d,s,0,boundary_conditions,0.5).
                            deriche(nnsigma,order,naxis,1).columns(border,w - 1 + border));
        case 'y' :
          return draw_image(get_resize(w,h + 2*border,d,s,0,boundary_conditions,0,0.5).

View on GitHub (pinned to f788b534b4)