{"record":{"id":"8aca6803481bb360","repo":"Yalantis/uCrop","slug":"cimglist-s-fft-specified-real-and-imaginary-8aca68","errorCode":null,"errorMessage":"CImgList<%s>::FFT(): Specified real and imaginary parts (%u,%u,%u,%u) have non 2^N dimension along the Z-axis.","messagePattern":"CImgList<(.+?)>::FFT\\(\\): Specified real and imaginary parts \\(%u,%u,%u,%u\\) have non 2\\^N dimension along the Z-axis\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":47872,"sourceCode":"                T &ir = real(x,j,z,c), &ii = imag(x,j,z,c), &nir = real(x,nj,z,c), &nii = imag(x,nj,z,c);\n                const float tmpr = (float)(wr*nir - wi*nii), tmpi = (float)(wr*nii + wi*nir);\n                nir = (T)(ir - tmpr);\n                nii = (T)(ii - tmpi);\n                ir+=(T)tmpr;\n                ii+=(T)tmpi;\n              }\n              const float nwr = wr*ca-wi*sa;\n              wi = wi*ca + wr*sa;\n              wr = nwr;\n            }\n          }\n        }\n        if (is_inverse) { real/=N; imag/=N; }\n      } break;\n      default : { // Fourier along Z, using built-in functions\n        const unsigned int N = real._depth, N2 = N>>1;\n        if (((N - 1)&N) && N!=1)\n          throw CImgInstanceException(\"CImgList<%s>::FFT(): Specified real and imaginary parts (%u,%u,%u,%u) \"\n                                      \"have non 2^N dimension along the Z-axis.\",\n                                      pixel_type(),\n                                      real._width,real._height,real._depth,real._spectrum);\n\n        for (unsigned int i = 0, j = 0; i<N2; ++i) {\n          if (j>i) cimg_forXYC(real,x,y,c) {\n              cimg::swap(real(x,y,i,c),real(x,y,j,c));\n              cimg::swap(imag(x,y,i,c),imag(x,y,j,c));\n              if (j<N2) {\n                const unsigned int ri = N - 1 - i, rj = N - 1 - j;\n                cimg::swap(real(x,y,ri,c),real(x,y,rj,c));\n                cimg::swap(imag(x,y,ri,c),imag(x,y,rj,c));\n              }\n            }\n          for (unsigned int m = N, n = N2; (j+=n)>=m; j-=m, m = n, n>>=1) {}\n        }\n        for (unsigned int delta = 2; delta<=N; delta<<=1) {\n          const unsigned int delta2 = (delta>>1);","sourceCodeStart":47854,"sourceCodeEnd":47890,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L47854-L47890","documentation":"Built-in radix-2 FFT constraint applied to real._depth: computing along the Z-axis (the default case of the axis switch) without FFTW3 requires the image depth to be 1 or a power of 2. Otherwise this CImgInstanceException is thrown. Z-axis FFT is used for volumetric (3D) data.","triggerScenarios":"Calling FFT() along the Z-axis on a 3D image (CImg with _depth>1, e.g. a MRI/CT volume or image sequence) whose depth is not a power of two, in a build without cimg_use_fftw3.","commonSituations":"Medical volumes with arbitrary slice counts (e.g. 120 slices), temporal stacks of N frames that are not 2^N, or 2D images accidentally treated as volumes.","solutions":["Pad the volume depth to the next power of 2 (zero-pad slices) before FFT.","Build CImg with cimg_use_fftw3 to support arbitrary depths.","Crop the volume to a power-of-two number of slices.","Pre-check depth before calling FFT and pad programmatically."],"exampleFix":"// before\nvol.FFT(true, false, 'z'); // depth 120 not 2^N\n// after\nunsigned int d2 = 1; while (d2 < vol.depth()) d2 <<= 1;\nvol.get_resize(vol.width(), vol.height(), d2, -100, 0).FFT(true, false, 'z');","handlingStrategy":"validation","validationCode":"unsigned int d = vol.depth();\nbool isPow2 = d == 1 || ((d & (d - 1)) == 0);\nif (!isPow2) vol.resize(vol.width(), vol.height(), nextPow2(d), vol.spectrum(), 0);","typeGuard":"bool isPowerOfTwo(unsigned int n) { return n == 1 || (n && !(n & (n - 1))); }","tryCatchPattern":"try { vol.FFT(is_inverse, false, 'z'); }\ncatch (CImgInstanceException& e) { /* zero-pad slices to 2^N and retry */ }","preventionTips":["Zero-pad volume slice count to a power of two before Z-axis FFT","Reconstruct/normalize volumes to 2^N slice counts during acquisition/import","Prefer FFTW3-enabled builds for arbitrary-depth volumes"],"tags":["cimg","fft","power-of-two","volume"],"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-17T15:17:12.973Z"}