{"record":{"id":"9b4e824fa8f59877","repo":"Yalantis/uCrop","slug":"blur-patch-invalid-size-for-specified-guide-ima","errorCode":null,"errorMessage":"blur_patch(): Invalid size for specified guide image (%u,%u,%u,%u,%p).","messagePattern":"blur_patch\\(\\): Invalid size for specified guide image \\(%u,%u,%u,%u,%p\\)\\.","errorType":"validation","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":45042,"sourceCode":"          cimg_for_in##N##XY(res,x0,y0,x1,y1,p,q) if (p!=x || q!=y) { \\\n            tfloat *pQ = Q._data; cimg_forC(_guide,c) { cimg_get##N##x##N(_guide,p,q,0,c,pQ,tfloat); pQ+=N2; } \\\n            tfloat distance2 = 0; \\\n            pQ = Q._data; cimg_for(P,_pP,tfloat) { const tfloat dI = *_pP - *(pQ++); distance2+=dI*dI; } \\\n            distance2/=Pnorm; \\\n            const tfloat dx = (tfloat)p - x, dy = (tfloat)q - y, \\\n              alldist = distance2 + (dx*dx+dy*dy)/sigma_s2, weight = std::exp(-alldist); \\\n            if (weight>weight_max) weight_max = weight; \\\n            sum_weights+=weight; \\\n            cimg_forC(res,c) res(x,y,c)+=(Tfloat)weight*(*this)(p,q,c); \\\n          } \\\n          sum_weights+=weight_max; cimg_forC(res,c) res(x,y,c)+=(Tfloat)weight_max*(*this)(x,y,c); \\\n          if (sum_weights>1e-10) cimg_forC(res,c) res(x,y,c)/=(Tfloat)sum_weights; \\\n          else cimg_forC(res,c) res(x,y,c) = (Tfloat)((*this)(x,y,c)); \\\n    } _cimg_abort_catch_openmp2 }\n\n      typedef _cimg_tfloat tfloat;\n      if (!is_sameXYZ(guide))\n        throw CImgArgumentException(_cimg_instance\n                                    \"blur_patch(): Invalid size for specified guide image (%u,%u,%u,%u,%p).\",\n                                    cimg_instance,\n                                    guide._width,guide._height,guide._depth,guide._spectrum,guide._data);\n      if (is_empty() || !patch_size || !lookup_size) return +*this;\n      Tfloat val_min, val_max = (Tfloat)max_min(val_min);\n      _cimg_abort_init_openmp;\n      cimg_abort_init;\n\n      CImg<Tfloat> res(_width,_height,_depth,_spectrum,0);\n      const CImg<tfloat>\n        __guide = guide?CImg<tfloat>(guide,guide.pixel_type()==cimg::type<tfloat>::string()):\n                        CImg<tfloat>(*this,pixel_type()==cimg::type<tfloat>::string()),\n        _guide = smoothness>0?__guide.get_blur(smoothness):__guide.get_shared();\n      CImg<tfloat> P(_guide._spectrum*patch_size*patch_size*(_depth>1?patch_size:1)), Q(P);\n\n      t guide_min = (t)0, guide_max = (t)0;\n      if (sigma_r<0) guide_max = guide.max_min(guide_min);\n      const float","sourceCodeStart":45024,"sourceCodeEnd":45060,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L45024-L45060","documentation":"CImg's blur_patch() (non-local means style patch-based blur) uses the guide image as a feature source sampled at the same coordinates as the source image, so the guide must have the same width, height and depth. Mismatch throws this argument-validation error before the expensive patch search begins.","triggerScenarios":"Calling img.blur_patch(guide, patch_size, lookup_size, ...) with a guide at different resolution (e.g. a denoised proxy at half size) or from a differently cropped image.","commonSituations":"Precomputing a guide/smoothed image at reduced resolution for performance; passing RGB guide for grayscale source is fine, but any XYZ difference is not; dimension drift after crop/resize operations.","solutions":["Resize the guide to match the source image's XYZ dimensions","Derive the guide from the exact same image geometry","Add an assert(img.is_sameXYZ(guide)) before the call"],"exampleFix":"// before\nimg.blur_patch(guideHalf, 4, 5, 0.1f);\n// after\nguideHalf.resize(img.width(), img.height(), img.depth(), -100, 3);\nimg.blur_patch(guideHalf, 4, 5, 0.1f);","handlingStrategy":"validation","validationCode":"if (!img.is_sameXYZ(guide)) guide.resize(img.width(), img.height(), img.depth(), -100, 3);","typeGuard":"bool guideMatches(const CImg<T>& img, const CImg<t>& guide) { return img.is_sameXYZ(guide); }","tryCatchPattern":"try {\n  img.blur_patch(guide, patchSize, lookupSize, sigmaSpatial);\n} catch (cimg_library::CImgArgumentException& e) {\n  guide.resize(img.width(), img.height(), img.depth(), -100, 3);\n  img.blur_patch(guide, patchSize, lookupSize, sigmaSpatial);\n}","preventionTips":["Don't downsample guides for performance without resizing back","Always pair blur_patch source and guide from the same geometry","Assert is_sameXYZ before expensive patch computations"],"tags":["cimg","image-processing","blur-patch","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"}