{"record":{"id":"ddbb5ab2ad5d6bc9","repo":"Yalantis/uCrop","slug":"matchpatch-specified-patch-size-ux-ux-u-is-big-ddbb5a","errorCode":null,"errorMessage":"matchpatch(): Specified patch size %ux%ux%u is bigger than the dimensions of the patch image image (%u,%u,%u,%u,%p).","messagePattern":"matchpatch\\(\\): Specified patch size %ux%ux%u is bigger than the dimensions of the patch image image \\(%u,%u,%u,%u,%p\\)\\.","errorType":"validation","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":46284,"sourceCode":"                           const float patch_penalization,\n                           const CImg<t1> &guide,\n                           const bool is_matching_score,\n                           CImg<t2> &matching_score) const {\n      if (is_empty()) return CImg<intT>::const_empty();\n      if (patch_image._spectrum!=_spectrum)\n        throw CImgArgumentException(_cimg_instance\n                                    \"matchpatch(): Instance image and specified patch image (%u,%u,%u,%u,%p) \"\n                                    \"have different spectrums.\",\n                                    cimg_instance,\n                                    patch_image._width,patch_image._height,patch_image._depth,patch_image._spectrum,\n                                    patch_image._data);\n      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);","sourceCodeStart":46266,"sourceCodeEnd":46302,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L46266-L46302","documentation":"After checking the patch size against the instance image, matchpatch() also requires the patch window to fit inside the supplied patch image, since patches are sampled from it. If patch_width/height/depth exceeds patch_image's corresponding dimension, the library throws this CImgArgumentException reporting both the patch size and the patch image's full dimensions and data pointer.","triggerScenarios":"Calling matchpatch(patch_image, ...) where patch_width > patch_image._width, patch_height > patch_image._height, or patch_depth > patch_image._depth - e.g. a patch atlas smaller than the requested patch window, or a 2D patch image with a 3D patch depth.","commonSituations":"Building a patch dictionary from crops and forgetting its size, reusing patch-size constants from a different configuration, or cropping the patch image after the patch size was fixed.","solutions":["Ensure patch_image is at least patch_width x patch_height x patch_depth in size","Reduce the patch dimensions to fit within patch_image","Resize or rebuild the patch image/atlas to accommodate the desired patch window","Use patch_depth=1 when patch_image is 2D"],"exampleFix":"// before\natlas.matchpatch(patches, 16, 16, 1); // atlas is 8x4\n// after\nCImg<unsigned char> bigger_atlas = atlas.get_resize(16, 16);\natlas = bigger_atlas; // or reduce patch size to fit\natlas.matchpatch(patches, 8, 4, 1);","handlingStrategy":"validation","validationCode":"if (pw > (unsigned)patch_image.width() || ph > (unsigned)patch_image.height() ||\n    pd > (unsigned)patch_image.depth()) {\n  pw = std::min(pw, (unsigned)patch_image.width());\n  ph = std::min(ph, (unsigned)patch_image.height());\n  pd = std::min(pd, (unsigned)patch_image.depth());\n}\nCImg<intT> matches = img.matchpatch(patch_image, pw, ph, pd);","typeGuard":"template<typename T, typename t>\nbool patchFitsPatchImage(unsigned pw, unsigned ph, unsigned pd,\n                         const CImg<t>& patch_image) {\n  return pw <= (unsigned)patch_image.width() &&\n         ph <= (unsigned)patch_image.height() &&\n         pd <= (unsigned)patch_image.depth();\n}","tryCatchPattern":"try {\n  CImg<intT> matches = img.matchpatch(patch_image, pw, ph, pd);\n} catch (CImgArgumentException& e) {\n  std::fprintf(stderr, \"patch too large for patch image: %s\\n\", e.what());\n  // enlarge atlas or reduce patch size before retrying\n}","preventionTips":["Record the patch atlas dimensions alongside it and validate patch size against them","Keep one shared constant for patch size used by both image and patch image paths","Use patch_depth=1 with 2D patch atlases","Rebuild the atlas if it gets cropped/resized during preprocessing"],"tags":["cimg","image-dimensions","patch-matching"],"backgroundTag":"value-out-of-range","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"}