{"record":{"id":"c324861f858f01bf","repo":"Yalantis/uCrop","slug":"blur-anisotropic-invalid-specified-diffusion-te","errorCode":null,"errorMessage":"blur_anisotropic(): Invalid specified diffusion tensor field (%u,%u,%u,%u,%p).","messagePattern":"blur_anisotropic\\(\\): Invalid specified diffusion tensor field \\(%u,%u,%u,%u,%p\\)\\.","errorType":"validation","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":44202,"sourceCode":"    /**\n       \\param G Field of square roots of diffusion tensors/vectors used to drive the smoothing.\n       \\param amplitude Amplitude of the smoothing.\n       \\param dl Spatial discretization.\n       \\param da Angular discretization.\n       \\param gauss_prec Precision of the diffusion process.\n       \\param interpolation_type Interpolation scheme.\n         Can be <tt>{ 0=nearest-neighbor | 1=linear | 2=Runge-Kutta }</tt>.\n       \\param is_fast_approx Tells if a fast approximation of the gaussian function is used or not.\n    **/\n    template<typename t>\n    CImg<T>& blur_anisotropic(const CImg<t>& G,\n                              const float amplitude=60, const float dl=0.8f, const float da=30,\n                              const float gauss_prec=2, const unsigned int interpolation_type=0,\n                              const bool is_fast_approx=1) {\n\n      // Check arguments and init variables.\n      if (!is_sameXYZ(G) || (G._spectrum!=3 && G._spectrum!=6))\n        throw CImgArgumentException(_cimg_instance\n                                    \"blur_anisotropic(): Invalid specified diffusion tensor field (%u,%u,%u,%u,%p).\",\n                                    cimg_instance,\n                                    G._width,G._height,G._depth,G._spectrum,G._data);\n      if (is_empty() || dl<0) return *this;\n      const float namplitude = amplitude>=0?amplitude:-amplitude*cimg::max(_width,_height,_depth)/100;\n      unsigned int iamplitude = cimg::round(namplitude);\n      const bool is_3d = (G._spectrum==6);\n      T val_min, val_max = max_min(val_min);\n      _cimg_abort_init_openmp;\n      cimg_abort_init;\n\n      if (da<=0) { // Iterated oriented Laplacians\n        CImg<Tfloat> velocity(_width,_height,_depth,_spectrum);\n        for (unsigned int iteration = 0; iteration<iamplitude; ++iteration) {\n          Tfloat *ptrd = velocity._data, veloc_max = 0;\n          if (is_3d) // 3D version\n            cimg_forC(*this,c) {\n              cimg_abort_test;","sourceCodeStart":44184,"sourceCodeEnd":44220,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L44184-L44220","documentation":"CImg's blur_anisotropic() expects the diffusion tensor field G to share the instance's width/height/depth and to have exactly 3 (2D tensor: P11,P12,P22) or 6 (3D tensor) channels. Any other shape throws this error before blurring starts.","triggerScenarios":"Passing a tensor field computed on a differently sized image; passing a gradient image with 1, 2 or more-than-6 spectra; passing an uninitialized or empty CImg as G.","commonSituations":"Computing structure tensors at a lower resolution for speed then forgetting to resize; constructing the tensor with Hessian components (4 channels in 2D) instead of the required 3; dimension mismatch after crop/resize.","solutions":["Ensure G has the same XYZ dimensions as the image (use resize or compute from the same source)","Ensure G._spectrum is exactly 3 for 2D tensors or 6 for 3D tensors","Add img.is_sameXYZ(G) && (G.spectrum()==3 || G.spectrum()==6) as an assert before calling"],"exampleFix":"// before\nCImg<float> G = img.get_gradient().resize_halfXY();\nimg.blur_anisotropic(G);\n// after\nCImg<float> G = img.get_gradient(); // same XYZ, spectrum reshaped as needed\nG.resize(img.width(), img.height(), img.depth(), 3, 3);\nimg.blur_anisotropic(G);","handlingStrategy":"validation","validationCode":"bool tensorOk = img.is_sameXYZ(G) && (G.spectrum()==3 || G.spectrum()==6);\nif (!tensorOk) G.resize(img.width(), img.height(), img.depth(), 3, 3);","typeGuard":"bool validTensorField(const CImg<T>& img, const CImg<float>& G) {\n  return img.is_sameXYZ(G) && (G.spectrum()==3 || G.spectrum()==6);\n}","tryCatchPattern":"try {\n  img.blur_anisotropic(G);\n} catch (cimg_library::CImgArgumentException& e) {\n  G.resize(img.width(), img.height(), img.depth(), 3, 3);\n  img.blur_anisotropic(G);\n}","preventionTips":["Build tensors (3 or 6 channels) from the same-resolution image","Never pass raw gradient stacks without checking spectrum count","Assert tensor shape in debug builds before heavy filtering"],"tags":["cimg","image-processing","blur","tensor","dimension-mismatch"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}