{"record":{"id":"7f6a96489fa513bf","repo":"Yalantis/uCrop","slug":"get-gradient-invalid-specified-axes-s","errorCode":null,"errorMessage":"get_gradient(): Invalid specified axes '%s'.","messagePattern":"get_gradient\\(\\): Invalid specified axes '(.+?)'\\.","errorType":"validation","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":45536,"sourceCode":"       - 4 = Using Deriche recursive filter.\n       - 5 = Using Van Vliet recursive filter.\n    **/\n    CImgList<Tfloat> get_gradient(const char *const axes=0, const int scheme=0) const {\n      CImgList<Tfloat> res;\n      char __axes[4] = {};\n      const char *_axes = axes?axes:__axes;\n      if (!axes) {\n        unsigned int k = 0;\n        if (_width>1) __axes[k++] = 'x';\n        if (_height>1) __axes[k++] = 'y';\n        if (_depth>1) __axes[k++] = 'z';\n      }\n\n      CImg<Tfloat> grad;\n      while (*_axes) {\n        const char axis = cimg::lowercase(*(_axes++));\n        if (axis!='x' && axis!='y' && axis!='z')\n          throw CImgArgumentException(_cimg_instance\n                                      \"get_gradient(): Invalid specified axes '%s'.\",\n                                      cimg_instance,\n                                      axes);\n        const longT off = axis=='x'?1:axis=='y'?_width:_width*_height;\n        if ((axis=='x' && _width==1) || (axis=='y' && _height==1) || (axis=='z' && _depth==1)) {\n          grad.assign(_width,_height,_depth,_spectrum,0).move_to(res);\n          continue;\n        }\n\n        const int _scheme = axis=='z' && (scheme==2 || scheme==3)?0:scheme;\n        switch (_scheme) {\n        case -1 : { // Backward finite differences\n          grad.assign(_width,_height,_depth,_spectrum);\n          cimg_pragma_openmp(parallel for cimg_openmp_collapse(3) cimg_openmp_if_size(size(),16384))\n          cimg_forXYZC(*this,x,y,z,c) {\n            const ulongT pos = offset(x,y,z,c);\n            if ((axis=='x' && !x) || (axis=='y' && !y) || (axis=='z' && !z))\n              grad[pos] = 0;","sourceCodeStart":45518,"sourceCodeEnd":45554,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L45518-L45554","documentation":"CImg's get_gradient() computes image gradients along the axes given as a string. Each character of the axes string must be 'x', 'y' or 'z'; the library validates the string character-by-character and throws this CImgArgumentException if any character is not one of the three allowed axis letters.","triggerScenarios":"Calling get_gradient(axes) (or gradient() which delegates to it) with an axes string containing any character other than 'x','y','z' (or 'X','Y','Z', which are lowercased) - e.g. 'w', 't', 'xy z', or a string with trailing whitespace/punctuation.","commonSituations":"Typo in the axes string ('X,Y' with commas), porting code that used axis indices or different axis names, accidentally passing a user/config string with spaces, or handling 4D images where a developer passes 't' for the time axis which get_gradient does not support.","solutions":["Inspect the axes string at the throw site and remove/replace any character that is not 'x','y' or 'z' (case-insensitive)","Use only concatenated axis letters with no separators, e.g. 'xy' or 'xyz'","Lowercase/normalize user-supplied axis names before passing them, or build the string programmatically from a whitelist","If you need derivatives along other dimensions (spectrum/time), compute them with get_derivative() along that dimension instead"],"exampleFix":"// before\nimg.get_gradient(\"x,t\");\n// after\nimg.get_gradient(\"x\"); // or \"xy\" / \"xyz\" - only x,y,z are valid","handlingStrategy":"validation","validationCode":"static bool isValidAxes(const std::string& axes) {\n  for (char c : axes) {\n    char l = (char)std::tolower((unsigned char)c);\n    if (l != 'x' && l != 'y' && l != 'z') return false;\n  }\n  return !axes.empty();\n}\n// call only if isValidAxes(axes)\nCImg<float> grad = img.get_gradient(axes.c_str());","typeGuard":"bool isCimgAxis(char c) {\n  char l = (char)std::tolower((unsigned char)c);\n  return l == 'x' || l == 'y' || l == 'z';\n}","tryCatchPattern":"try {\n  CImg<float> grad = img.get_gradient(axes);\n} catch (CImgArgumentException& e) {\n  std::fprintf(stderr, \"bad axes string '%s': %s\\n\", axes.c_str(), e.what());\n  // fall back to default full gradient\n  CImg<float> grad = img.get_gradient(\"xy\");\n}","preventionTips":["Build axes strings from a whitelist enum instead of free text","Strip whitespace/separators ('x,y' is invalid) before passing","Normalize case with cimg::lowercase or std::tolower","Never pass 't' or 'c' - get_gradient only supports x,y,z"],"tags":["cimg","argument-validation","axes-string"],"backgroundTag":"invalid-enum-value","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}