Yalantis/uCrop · error · CImgArgumentException
blur_anisotropic(): Invalid specified diffusion tensor field
Error message
blur_anisotropic(): Invalid specified diffusion tensor field (%u,%u,%u,%u,%p).
What it means
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.
Source
Thrown at ucrop/src/main/jni/CImg.h:44202
/**
\param G Field of square roots of diffusion tensors/vectors used to drive the smoothing.
\param amplitude Amplitude of the smoothing.
\param dl Spatial discretization.
\param da Angular discretization.
\param gauss_prec Precision of the diffusion process.
\param interpolation_type Interpolation scheme.
Can be <tt>{ 0=nearest-neighbor | 1=linear | 2=Runge-Kutta }</tt>.
\param is_fast_approx Tells if a fast approximation of the gaussian function is used or not.
**/
template<typename t>
CImg<T>& blur_anisotropic(const CImg<t>& G,
const float amplitude=60, const float dl=0.8f, const float da=30,
const float gauss_prec=2, const unsigned int interpolation_type=0,
const bool is_fast_approx=1) {
// Check arguments and init variables.
if (!is_sameXYZ(G) || (G._spectrum!=3 && G._spectrum!=6))
throw CImgArgumentException(_cimg_instance
"blur_anisotropic(): Invalid specified diffusion tensor field (%u,%u,%u,%u,%p).",
cimg_instance,
G._width,G._height,G._depth,G._spectrum,G._data);
if (is_empty() || dl<0) return *this;
const float namplitude = amplitude>=0?amplitude:-amplitude*cimg::max(_width,_height,_depth)/100;
unsigned int iamplitude = cimg::round(namplitude);
const bool is_3d = (G._spectrum==6);
T val_min, val_max = max_min(val_min);
_cimg_abort_init_openmp;
cimg_abort_init;
if (da<=0) { // Iterated oriented Laplacians
CImg<Tfloat> velocity(_width,_height,_depth,_spectrum);
for (unsigned int iteration = 0; iteration<iamplitude; ++iteration) {
Tfloat *ptrd = velocity._data, veloc_max = 0;
if (is_3d) // 3D version
cimg_forC(*this,c) {
cimg_abort_test;View on GitHub (pinned to f788b534b4)
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
Example fix
// before CImg<float> G = img.get_gradient().resize_halfXY(); img.blur_anisotropic(G); // after CImg<float> G = img.get_gradient(); // same XYZ, spectrum reshaped as needed G.resize(img.width(), img.height(), img.depth(), 3, 3); img.blur_anisotropic(G);
Defensive patterns
Strategy: validation
Validate before calling
bool tensorOk = img.is_sameXYZ(G) && (G.spectrum()==3 || G.spectrum()==6); if (!tensorOk) G.resize(img.width(), img.height(), img.depth(), 3, 3);
Type guard
bool validTensorField(const CImg<T>& img, const CImg<float>& G) {
return img.is_sameXYZ(G) && (G.spectrum()==3 || G.spectrum()==6);
} Try / catch
try {
img.blur_anisotropic(G);
} catch (cimg_library::CImgArgumentException& e) {
G.resize(img.width(), img.height(), img.depth(), 3, 3);
img.blur_anisotropic(G);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Tensor shape mismatch errors ("must have shape", "expected shape ... got ..."): when tensor dimensions disagree with what an op or layer was told to expect — this error's family across 6 libraries.
Related errors
- index(): Instance and specified colormap (%u,%u,%u,%u,%p) ha
- watershed(): image instance and specified priority (%u,%u,%u
- blur_bilateral(): Invalid size for specified guide image (%u
- blur_guided(): Invalid size for specified guide image (%u,%u
- blur_patch(): Invalid size for specified guide image (%u,%u,
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/c324861f858f01bf.
Report an issue: GitHub.