{"record":{"id":"756ddaa0ab6783c0","repo":"Yalantis/uCrop","slug":"cimglist-s-fft-specified-real-and-imaginary-756dda","errorCode":null,"errorMessage":"CImgList<%s>::FFT(): Specified real and imaginary parts (%u,%u,%u,%u) have non 2^N dimension along the Y-axis.","messagePattern":"CImgList<(.+?)>::FFT\\(\\): Specified real and imaginary parts \\(%u,%u,%u,%u\\) have non 2\\^N dimension along the Y-axis\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":47826,"sourceCode":"                T &ir = real(j,y,z,c), &ii = imag(j,y,z,c), &nir = real(nj,y,z,c), &nii = imag(nj,y,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      case 'y' : { // Fourier along Y, using built-in functions\n        const unsigned int N = real._height, 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 Y-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_forXZC(real,x,z,c) {\n              cimg::swap(real(x,i,z,c),real(x,j,z,c));\n              cimg::swap(imag(x,i,z,c),imag(x,j,z,c));\n              if (j<N2) {\n                const unsigned int ri = N - 1 - i, rj = N - 1 - j;\n                cimg::swap(real(x,ri,z,c),real(x,rj,z,c));\n                cimg::swap(imag(x,ri,z,c),imag(x,rj,z,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":47808,"sourceCodeEnd":47844,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L47808-L47844","documentation":"Same built-in radix-2 constraint as the X-axis case, but applied to real._height: when FFT() computes along the Y-axis (axis='y') without FFTW3, the height must be 1 or a power of 2, otherwise this CImgInstanceException is thrown. The check is ((N-1)&N) && N!=1 with N=real._height.","triggerScenarios":"Calling FFT() with axis='y' (or CImgList FFT along Y) on an image whose _height is not a power of two, in a build without cimg_use_fftw3.","commonSituations":"Images sized to display resolution (e.g. 1920x1080 -> height 1080 not 2^N), video frames, or scanning/sensor rows counts that are arbitrary.","solutions":["Pad/crop the image height to the next power of 2 before the FFT.","Compile with cimg_use_fftw3 to lift the power-of-two restriction.","Resize the image (CImg::resize) to power-of-two dimensions.","Pre-check height: if ((h & (h-1)) != 0) pad first."],"exampleFix":"// before\nimg.FFT(true, false, 'y'); // height 1080 not 2^N\n// after\nconst unsigned int h2 = 1; while (h2 < img.height()) h2 <<= 1;\nimg.get_resize(img.width(), h2, -100, -100, 0).FFT(true, false, 'y');","handlingStrategy":"validation","validationCode":"unsigned int h = img.height();\nbool isPow2 = h == 1 || ((h & (h - 1)) == 0);\nif (!isPow2) img.resize(img.width(), nextPow2(h), img.depth(), img.spectrum(), 0);","typeGuard":"bool isPowerOfTwo(unsigned int n) { return n == 1 || (n && !(n & (n - 1))); }","tryCatchPattern":"try { img.FFT(is_inverse, false, 'y'); }\ncatch (CImgInstanceException& e) { /* pad height and retry */ }","preventionTips":["Check image height (e.g. 1080 is not 2^N) before Y-axis FFT without FFTW3","Standardize pipeline resolutions to power-of-two heights","Compile with cimg_use_fftw3 to avoid the restriction entirely"],"tags":["cimg","fft","power-of-two","image-dimensions"],"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"}