{"record":{"id":"0c97289f2252eb26","repo":"Yalantis/uCrop","slug":"matchpatch-specified-guide-u-u-u-u-p-has","errorCode":null,"errorMessage":"matchpatch(): Specified guide (%u,%u,%u,%u,%p) has invalid dimensions considering instance and patch image (%u,%u,%u,%u,%p).","messagePattern":"matchpatch\\(\\): Specified guide \\(%u,%u,%u,%u,%p\\) has invalid dimensions considering instance and patch image \\(%u,%u,%u,%u,%p\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":46296,"sourceCode":"      if (patch_width>_width || patch_height>_height || patch_depth>_depth)\n        throw CImgArgumentException(_cimg_instance\n                                    \"matchpatch(): Specified patch size %ux%ux%u is bigger than the dimensions \"\n                                    \"of the instance image.\",\n                                    cimg_instance,patch_width,patch_height,patch_depth);\n      if (patch_width>patch_image._width || patch_height>patch_image._height || patch_depth>patch_image._depth)\n        throw CImgArgumentException(_cimg_instance\n                                    \"matchpatch(): Specified patch size %ux%ux%u is bigger than the dimensions \"\n                                    \"of the patch image image (%u,%u,%u,%u,%p).\",\n                                    cimg_instance,patch_width,patch_height,patch_depth,\n                                    patch_image._width,patch_image._height,patch_image._depth,patch_image._spectrum,\n                                    patch_image._data);\n      const unsigned int\n        _constraint = patch_image._depth>1?3:2,\n        constraint = guide._spectrum>_constraint?_constraint:0;\n\n      if (guide &&\n          (guide._width!=_width || guide._height!=_height || guide._depth!=_depth || guide._spectrum<_constraint))\n        throw CImgArgumentException(_cimg_instance\n                                    \"matchpatch(): Specified guide (%u,%u,%u,%u,%p) has invalid dimensions \"\n                                    \"considering instance and patch image (%u,%u,%u,%u,%p).\",\n                                    cimg_instance,\n                                    guide._width,guide._height,guide._depth,guide._spectrum,guide._data,\n                                    patch_image._width,patch_image._height,patch_image._depth,patch_image._spectrum,\n                                    patch_image._data);\n\n      CImg<intT> a_map(_width,_height,_depth,patch_image._depth>1?3:2);\n      CImg<ucharT> is_updated(_width,_height,_depth,1,3);\n      CImg<floatT> score(_width,_height,_depth), penalty;\n      const float _patch_penalization = cimg::abs(patch_penalization);\n      const bool allow_identity = patch_penalization>=0;\n      if (_patch_penalization!=0)\n        penalty.assign(patch_image._width,patch_image._height,patch_image._depth,1,0);\n\n      const int\n        psizew = (int)patch_width,  psizew1 = psizew/2, psizew2 = psizew - psizew1 - 1,\n        psizeh = (int)patch_height, psizeh1 = psizeh/2, psizeh2 = psizeh - psizeh1 - 1,","sourceCodeStart":46278,"sourceCodeEnd":46314,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L46278-L46314","documentation":"matchpatch() accepts an optional guide image (typically a previous displacement field) whose spatial dimensions must equal the instance image's, and whose spectrum must be at least 2 (or 3 for volumetric patch images, _constraint). If the guide is non-empty and violates these constraints, the library throws this CImgArgumentException, printing both the guide's and patch image's dimensions.","triggerScenarios":"Calling matchpatch(..., guide, ...) where guide._width/_height/_depth differ from the instance, or guide._spectrum < 2 (2D) / < 3 (3D patch images) - e.g. a scalar guide image or a guide from a differently-sized previous run.","commonSituations":"Feeding a single-channel prior instead of a vector-valued flow guide, reusing a guide computed on a resized/cropped version of the image, or using a 2D guide with volumetric patch matching.","solutions":["Ensure the guide has the same width/height/depth as the instance image","Ensure guide._spectrum >= 2 (2D) or >= 3 (3D patch images) - the guide normally stores displacement components per channel","Resize/rebuild the guide (guide.resize(_width,_height,_depth,needed_spectrum)) before the call","Pass an empty CImg (default-constructed) if no guidance is desired - empty guides bypass the check"],"exampleFix":"// before\nCImg<float> guide = previous_guide; // resized image, 5x5 vs 100x100 instance\nCImg<intT> matches = img.matchpatch(patches, 7, 7, 1, guide);\n// after\nprevious_guide.resize(img.width(), img.height(), img.depth(), previous_guide.spectrum());\nCImg<intT> matches = img.matchpatch(patches, 7, 7, 1, previous_guide);","handlingStrategy":"validation","validationCode":"const unsigned int needS = patch_image._depth > 1 ? 3 : 2;\nif (guide && (guide._width != img._width || guide._height != img._height ||\n              guide._depth != img._depth || guide._spectrum < needS)) {\n  guide.resize(img.width(), img.height(), img.depth(), needS);\n}\nCImg<intT> matches = img.matchpatch(patch_image, pw, ph, pd, guide);","typeGuard":"template<typename T, typename t>\nbool isMatchpatchGuideValid(const CImg<T>& inst, const CImg<t>& guide,\n                            const CImg<t>& patch_image) {\n  const unsigned int needS = patch_image._depth > 1 ? 3 : 2;\n  return !guide || (guide._width == inst._width && guide._height == inst._height &&\n                    guide._depth == inst._depth && guide._spectrum >= needS);\n}","tryCatchPattern":"try {\n  CImg<intT> matches = img.matchpatch(patch_image, pw, ph, pd, guide);\n} catch (CImgArgumentException& e) {\n  std::fprintf(stderr, \"invalid matchpatch guide: %s\\n\", e.what());\n  CImg<intT> matches = img.matchpatch(patch_image, pw, ph, pd); // no guidance\n}","preventionTips":["Guides must match instance width/height/depth and spectrum >= 2 (3D patches need >= 3)","Resize/recompute the guide when the instance image changes size","Pass an empty CImg instead of a mis-sized prior to disable guidance","Keep guides for 3D patch matching at 3+ channels (flow vector + score)"],"tags":["cimg","image-dimensions","patch-matching"],"backgroundTag":"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"}