Yalantis/uCrop · error · CImgArgumentException

get_hessian(): Invalid specified axes

Error message

get_hessian(): Invalid specified axes '%s'.

What it means

CImg's get_hessian() computes Hessian components from pairs of axis letters supplied as a string (e.g. 'xx','xy','zz'). It first requires the axes string length to be even; an odd-length string means an incomplete axis pair, so it throws this CImgArgumentException before doing any work.

Solutions

  1. Count the characters of the axes string and make sure it contains complete pairs ('xx','xy','xz','yy','yz','zz')
  2. Fix the string to include both letters of each desired Hessian component, e.g. change 'xxy' to 'xxyy' or 'xy'
  3. Build the string programmatically by always appending two axis characters per component
  4. Note the same error text is reused at line 45670 for invalid axis letters - if the length is even, check for non x/y/z characters instead

Example fix

// before
img.get_hessian("xyy"); // odd length
// after
img.get_hessian("xyyy"); // complete pairs: xy, yy
Defensive patterns

Strategy: validation

Validate before calling

static bool isEvenAxisPairs(const std::string& axes) {
  return axes.size() % 2 == 0;
}
// only call get_hessian when isEvenAxisPairs(axes) is true

Type guard

bool isCompleteHessianComponent(const std::string& s) {
  return s.size() == 2; // one Hessian component = two axis letters
}

Try / catch

try {
  CImg<float> hess = img.get_hessian(axes);
} catch (CImgArgumentException& e) {
  std::fprintf(stderr, "axes must be pairs (len=%zu): %s\n",
               std::strlen(axes), e.what());
  CImg<float> hess = img.get_hessian(); // default: all components
}

Prevention

When it happens

Trigger: Calling get_hessian(axes) with a string whose length is not a multiple of 2 - e.g. 'x' (length 1), 'xxy' (length 3), or a typo'd/empty-ish string with a stray character.

Common situations: Hand-written axes strings where one letter of a pair was deleted or forgotten ('xyy' instead of 'xyyy'), building the string programmatically and appending a single axis instead of two, or truncation of a longer string.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

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

    /**
       \param axes Axes considered for the hessian computation, as a C-string (e.g "xy").
    **/
    CImgList<Tfloat> get_hessian(const char *const axes=0) const {
      CImgList<Tfloat> res;
      char __axes[12] = {};
      const char *_axes = axes?axes:__axes;
      if (!axes) {
        unsigned int k = 0;
        if (_width>1) { __axes[k++] = 'x'; __axes[k++] = 'x'; }
        if (_width>1 && _height>1) { __axes[k++] = 'x'; __axes[k++] = 'y'; }
        if (_width>1 && _depth>1) { __axes[k++] = 'x'; __axes[k++] = 'z'; }
        if (_height>1) { __axes[k++] = 'y'; __axes[k++] = 'y'; }
        if (_height>1 && _depth>1) { __axes[k++] = 'y'; __axes[k++] = 'z'; }
        if (_depth>1) { __axes[k++] = 'z'; __axes[k++] = 'z'; }
      }
      const unsigned int len = (unsigned int)std::strlen(_axes);
      if (len%2)
        throw CImgArgumentException(_cimg_instance
                                    "get_hessian(): Invalid specified axes '%s'.",
                                    cimg_instance,
                                    axes);
      CImg<Tfloat> hess;
      for (unsigned int k = 0; k<len; k+=2) {
        const char
          _axis1 = cimg::lowercase(_axes[k]),
          _axis2 = cimg::lowercase(_axes[k + 1]),
          axis1 = std::min(_axis1,_axis2),
          axis2 = std::max(_axis2,_axis2);
        if (axis1!='x' && axis1!='y' && axis1!='z' &&
            axis2!='x' && axis2!='y' && axis2!='z')
          throw CImgArgumentException(_cimg_instance
                                      "get_hessian(): Invalid specified axes '%s'.",
                                      cimg_instance,
                                      axes);
        const longT off = axis1=='x'?1:axis1=='y'?_width:_width*_height;

View on GitHub (pinned to f788b534b4)