Yalantis/uCrop · error · CImgArgumentException
project_matrix(): Specified dictionary (%u,%u,%u,%u) has an
Error message
project_matrix(): Specified dictionary (%u,%u,%u,%u) has an invalid size.
What it means
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.
Source
Thrown at ucrop/src/main/jni/CImg.h:33739
(only meaningful for matching pursuit and its variants).
\return A matrix W whose columns correspond to the sparse weights of associated to each input matrix column.
Thus, the matrix product D*W is an approximation of the input matrix.
**/
template<typename t>
CImg<T>& project_matrix(const CImg<t>& dictionary, const unsigned int method=0,
const unsigned int max_iter=0, const double max_residual=1e-6) {
return get_project_matrix(dictionary,method,max_iter,max_residual).move_to(*this);
}
template<typename t>
CImg<Tfloat> get_project_matrix(const CImg<t>& dictionary, const unsigned int method=0,
const unsigned int max_iter=0, const double max_residual=1e-6) const {
if (_depth!=1 || _spectrum!=1)
throw CImgInstanceException(_cimg_instance
"project_matrix(): Instance image is not a matrix.",
cimg_instance);
if (dictionary._height!=_height || dictionary._depth!=1 || dictionary._spectrum!=1)
throw CImgArgumentException(_cimg_instance
"project_matrix(): Specified dictionary (%u,%u,%u,%u) has an invalid size.",
cimg_instance,
dictionary._width,dictionary._height,dictionary._depth,dictionary._spectrum);
if (!method) return get_solve(dictionary);
// Compute norm of dictionary atoms.
CImg<Tfloat> dictionary_norm(dictionary._width);
cimg_pragma_openmp(parallel for
cimg_openmp_if(dictionary._width>=2 && dictionary._width*dictionary._height>=32))
cimg_forX(dictionary_norm,atom) {
Tfloat norm = 0;
cimg_forY(dictionary,s) norm+=cimg::sqr(dictionary(atom,s));
dictionary_norm[atom] = std::max((Tfloat)1e-8,std::sqrt(norm));
}
// Matching pursuit.
CImg<Tfloat> weights(_width,dictionary._width,1,1,0);
const unsigned int proj_step = method<3?1:method - 2;View on GitHub (pinned to f788b534b4)
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
Example fix
// before sig.get_project_matrix(dict); // sig 64x1, dict 128x1 // after CImg<float> dict2 = dict.get_resize(1, 64, 1, 1); // or rebuild dict with matching height sig.get_project_matrix(dict2);
Defensive patterns
Strategy: validation
Validate before calling
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"); Type guard
bool isValidDictionary(const CImg<T>& sig, const CImg<T>& dict) { return dict.height() == sig.height() && dict.depth() == 1 && dict.spectrum() == 1; } Try / catch
try { P = img.get_project_matrix(dict); } catch (CImgArgumentException& e) { /* rebuild/resize dictionary or report dimension mismatch */ } Prevention
- 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
When it happens
Trigger: Calling get_project_matrix(dictionary) where dictionary._height != instance._height, or dictionary has depth>1 / spectrum>1 (e.g. a color dictionary image).
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- project_matrix(): Instance image is not a matrix.
- cimg::SDL3_attr(): %s
- cimg::mod(): Specified modulo value is 0.
- cimg::fopen(): Specified file path is (null).
- cimg::fopen(): File '%s', specified mode is (null).
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/58ddba23506155e4.
Report an issue: GitHub.