{"record":{"id":"58ddba23506155e4","repo":"Yalantis/uCrop","slug":"project-matrix-specified-dictionary-u-u-u","errorCode":null,"errorMessage":"project_matrix(): Specified dictionary (%u,%u,%u,%u) has an invalid size.","messagePattern":"project_matrix\\(\\): Specified dictionary \\(%u,%u,%u,%u\\) has an invalid size\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":33739,"sourceCode":"                           (only meaningful for matching pursuit and its variants).\n       \\return A matrix W whose columns correspond to the sparse weights of associated to each input matrix column.\n               Thus, the matrix product D*W is an approximation of the input matrix.\n    **/\n    template<typename t>\n    CImg<T>& project_matrix(const CImg<t>& dictionary, const unsigned int method=0,\n                            const unsigned int max_iter=0, const double max_residual=1e-6) {\n      return get_project_matrix(dictionary,method,max_iter,max_residual).move_to(*this);\n    }\n\n    template<typename t>\n    CImg<Tfloat> get_project_matrix(const CImg<t>& dictionary, const unsigned int method=0,\n                                    const unsigned int max_iter=0, const double max_residual=1e-6) const {\n      if (_depth!=1 || _spectrum!=1)\n        throw CImgInstanceException(_cimg_instance\n                                    \"project_matrix(): Instance image is not a matrix.\",\n                                    cimg_instance);\n      if (dictionary._height!=_height || dictionary._depth!=1 || dictionary._spectrum!=1)\n        throw CImgArgumentException(_cimg_instance\n                                    \"project_matrix(): Specified dictionary (%u,%u,%u,%u) has an invalid size.\",\n                                    cimg_instance,\n                                    dictionary._width,dictionary._height,dictionary._depth,dictionary._spectrum);\n      if (!method) return get_solve(dictionary);\n\n      // Compute norm of dictionary atoms.\n      CImg<Tfloat> dictionary_norm(dictionary._width);\n      cimg_pragma_openmp(parallel for\n                         cimg_openmp_if(dictionary._width>=2 && dictionary._width*dictionary._height>=32))\n      cimg_forX(dictionary_norm,atom) {\n        Tfloat norm = 0;\n        cimg_forY(dictionary,s) norm+=cimg::sqr(dictionary(atom,s));\n        dictionary_norm[atom] = std::max((Tfloat)1e-8,std::sqrt(norm));\n      }\n\n      // Matching pursuit.\n      CImg<Tfloat> weights(_width,dictionary._width,1,1,0);\n      const unsigned int proj_step = method<3?1:method - 2;","sourceCodeStart":33721,"sourceCodeEnd":33757,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L33721-L33757","documentation":"get_project_matrix() additionally validates the supplied dictionary: it must have the same height as the instance, and depth/spectrum equal to 1. Otherwise CImgArgumentException reports the dictionary's actual (w,h,d,c) dimensions.","triggerScenarios":"Calling get_project_matrix(dictionary) where dictionary._height != instance._height, or dictionary has depth>1 / spectrum>1 (e.g. a color dictionary image).","commonSituations":"Mismatched feature dimension between signal and dictionary (different number of rows); dictionary built from patches of a different size; dictionary stored as multi-channel image.","solutions":["Resize/rebuild the dictionary so its height equals the instance height (dictionary rows == signal length)","Ensure dictionary is a 2D single-channel image (depth=1, spectrum=1)","Log both dimensions (instance height vs dictionary height) to diagnose the mismatch"],"exampleFix":"// before\nsig.get_project_matrix(dict); // sig 64x1, dict 128x1\n// after\nCImg<float> dict2 = dict.get_resize(1, 64, 1, 1); // or rebuild dict with matching height\nsig.get_project_matrix(dict2);","handlingStrategy":"validation","validationCode":"if (dict.height() != img.height() || dict.depth() != 1 || dict.spectrum() != 1) throw std::invalid_argument(\"dictionary must match instance height and be 2D single-channel\");","typeGuard":"bool isValidDictionary(const CImg<T>& sig, const CImg<T>& dict) { return dict.height() == sig.height() && dict.depth() == 1 && dict.spectrum() == 1; }","tryCatchPattern":"try { P = img.get_project_matrix(dict); } catch (CImgArgumentException& e) { /* rebuild/resize dictionary or report dimension mismatch */ }","preventionTips":["Build dictionary and signals from the same patch size","Log both (w,h,d,c) tuples on mismatch","Centralize dictionary construction so dimensions stay consistent"],"tags":["cimg","project-matrix","dictionary-size","sparse-coding"],"backgroundTag":"invalid-argument-value","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"}