{"record":{"id":"29f3f7ffdbdce87c","repo":"Yalantis/uCrop","slug":"load-analyze-file-s-defines-an-image-with-u","errorCode":null,"errorMessage":"load_analyze(): File '%s' defines an image with %u dimensions, reading only the 4 first.","messagePattern":"load_analyze\\(\\): File '(.+?)' defines an image with %u dimensions, reading only the 4 first\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":58457,"sourceCode":"        cimg::invert_endianness((float*)(header + 76),4);\n        cimg::invert_endianness((float*)(header + 108),1);\n        cimg::invert_endianness((float*)(header + 112),1);\n      }\n\n      if (nfile_header==nfile) {\n        const unsigned int vox_offset = (unsigned int)*(float*)(header + 108);\n        std::fseek(nfile,vox_offset,SEEK_SET);\n      }\n\n      unsigned short *dim = (unsigned short*)(header + 40), dimx = 1, dimy = 1, dimz = 1, dimv = 1;\n      if (!dim[0])\n        cimg::warn(_cimg_instance\n                   \"load_analyze(): File '%s' defines an image with zero dimensions.\",\n                   cimg_instance,\n                   filename?filename:\"(FILE*)\");\n\n      if (dim[0]>4)\n        cimg::warn(_cimg_instance\n                   \"load_analyze(): File '%s' defines an image with %u dimensions, reading only the 4 first.\",\n                   cimg_instance,\n                   filename?filename:\"(FILE*)\",dim[0]);\n\n      if (dim[0]>=1) dimx = dim[1];\n      if (dim[0]>=2) dimy = dim[2];\n      if (dim[0]>=3) dimz = dim[3];\n      if (dim[0]>=4) dimv = dim[4];\n      float scalefactor = *(float*)(header + 112); if (scalefactor==0) scalefactor = 1;\n      const unsigned short datatype = *(unsigned short*)(header + 70);\n      if (voxel_size) {\n        const float *vsize = (float*)(header + 76);\n        voxel_size[0] = vsize[1]; voxel_size[1] = vsize[2]; voxel_size[2] = vsize[3];\n      }\n      delete[] header;\n\n      // Read pixel data.\n      assign(dimx,dimy,dimz,dimv);","sourceCodeStart":58439,"sourceCodeEnd":58475,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L58439-L58475","documentation":"load_analyze() supports at most 4 dimensions (x,y,z,v). When the ANALYZE header declares dim[0] > 4, the library warns and reads only the first 4 dimensions, silently ignoring the extra axes. The loaded image will be a lower-dimensional slice of the dataset than the file contains.","triggerScenarios":"CImg::load_analyze() on a 5D+ ANALYZE file, e.g. dim[0]=5 (x,y,z,v,time) fMRI/4D+ exports from tools that write time or vector series as a 5th dimension.","commonSituations":"4D+fMRI data with time as dim[5]; vector-valued datasets stored with an extra axis; files converted from NIfTI with >4 dims; mixing up dim[] slot order when hand-crafting headers.","solutions":["Reshape/re-export the data so extra dimensions become the vector (dim[4], v) or z axis, or split the file into one image per extra-dimension index.","Load each 4D sub-volume separately by generating one file per time-point/vector component.","If you truly need >4 dims, read the header/volumes yourself and stitch into a CImg list.","Check whether a NIfTI-1 variant keeps the needed dims and use load_nii if available."],"exampleFix":"// before\nimg.load_analyze(\"fmri5d.hdr\"); // dim[0]=5, extra axis silently dropped\n// after: split 5th axis into separate files, then loop\nfor (unsigned int t = 0; t < ntimes; ++t) { load_slice(\"fmri5d.hdr\", t).move_to(volumes); }","handlingStrategy":"validation","validationCode":"unsigned short dim0 = *(unsigned short*)(header + 40);\nif (dim0 > 4) handleExtraDimensions(dim0);","typeGuard":"bool analyzeHeaderAtMost4D(const unsigned char* header348) { return *(const unsigned short*)(header348 + 40) <= 4; }","tryCatchPattern":"try { img.load_analyze(path); } catch (...) { /* fall back to per-slice loading */ }","preventionTips":["Inspect dim[0] before loading files from 4D+/5D sources.","Split extra axes into the v dimension or separate files at export time.","Prefer NIfTI-1 for datasets with more than 4 dimensions."],"tags":["analyze","hdr","dimensions","data-loss"],"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-17T15:17:12.973Z"}