{"record":{"id":"53deb697bda4989e","repo":"Yalantis/uCrop","slug":"cimglist-s-fft-specified-real-part-u-u-u","errorCode":null,"errorMessage":"CImgList<%s>::FFT(): Specified real part (%u,%u,%u,%u,%p) and imaginary part (%u,%u,%u,%u,%p) have different dimensions.","messagePattern":"CImgList<(.+?)>::FFT\\(\\): Specified real part \\(%u,%u,%u,%u,%p\\) and imaginary part \\(%u,%u,%u,%u,%p\\) have different dimensions\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":47934,"sourceCode":"#endif\n    }\n\n    //! Compute n-D Fast Fourier Transform.\n    /**\n       \\param[in,out] real Real part of the pixel values.\n       \\param[in,out] imag Imaginary part of the pixel values.\n       \\param is_inverse Tells if the forward (\\c false) or inverse (\\c true) FFT is computed.\n       \\param nb_threads Number of parallel threads used for the computation.\n         Use \\c 0 to set this to the number of available cpus.\n    **/\n    static void FFT(CImg<T>& real, CImg<T>& imag, const bool is_inverse=false,\n                    const unsigned int nb_threads=0) {\n      if (!real)\n        throw CImgInstanceException(\"CImgList<%s>::FFT(): Empty specified real part.\",\n                                    pixel_type());\n      if (!imag) imag.assign(real._width,real._height,real._depth,real._spectrum,(T)0);\n      if (!real.is_sameXYZC(imag))\n        throw CImgInstanceException(\"CImgList<%s>::FFT(): Specified real part (%u,%u,%u,%u,%p) and \"\n                                    \"imaginary part (%u,%u,%u,%u,%p) have different dimensions.\",\n                                    pixel_type(),\n                                    real._width,real._height,real._depth,real._spectrum,real._data,\n                                    imag._width,imag._height,imag._depth,imag._spectrum,imag._data);\n      cimg::unused(nb_threads);\n#ifdef cimg_use_fftw3\n      cimg::mutex(12);\n#ifndef cimg_use_fftw3_singlethread\n      fftw_plan_with_nthreads(nb_threads?nb_threads:cimg::nb_cpus());\n#endif\n      fftw_complex *data_in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*real._width*real._height*real._depth);\n      if (!data_in)\n        throw CImgInstanceException(\"CImgList<%s>::FFT(): Failed to allocate memory (%s) \"\n                                    \"for computing FFT of image (%u,%u,%u,%u).\",\n                                    pixel_type(),\n                                    cimg::strbuffersize(sizeof(fftw_complex)*real._width*\n                                                        real._height*real._depth*real._spectrum),\n                                    real._width,real._height,real._depth,real._spectrum);","sourceCodeStart":47916,"sourceCodeEnd":47952,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L47916-L47952","documentation":"The static CImg<T>::FFT(real, imag) requires the real and imaginary parts to have identical width, height, depth and spectrum (is_sameXYZC). If imag was not empty (so it was not auto-zero-filled) but its dimensions differ from real, this CImgInstanceException is thrown, printing both shapes and data pointers. FFT pairs must be congruent complex arrays.","triggerScenarios":"Calling CImg<T>::FFT(real, imag) where both images are non-empty but sized differently, e.g. real is 256x256 and imag is 128x128, or they differ only in spectrum/depth; also when a previous FFT's output (interleaved spectrum layout) is passed back with mismatched cropping.","commonSituations":"Loading real and imaginary parts from separate files of different sizes, cropping one part but not the other, or mixing results from images of different resolutions.","solutions":["Make imag the same size as real before calling FFT (imag.assign(real.width(), real.height(), real.depth(), real.spectrum(), (T)0) then copy).","Pass an empty (default-constructed) imag if you only have real data; it is auto-assigned to real's dimensions.","Resize/crop the smaller part to match the other (CImg::resize).","Verify with real.is_sameXYZC(imag) before calling FFT."],"exampleFix":"// before\nCImg<float> real(256,256), imag(128,128);\nCImg<float>::FFT(real, imag); // dimension mismatch\n// after\nCImg<float> real(256,256), imag(256,256,1,1,0);\nCImg<float>::FFT(real, imag);","handlingStrategy":"validation","validationCode":"if (!real.is_sameXYZC(imag))\n  imag.assign(real.width(), real.height(), real.depth(), real.spectrum(), (T)0); // zero-fill","typeGuard":"bool isCompatiblePair(const CImg<T>& r, const CImg<T>& i) { return i.is_empty() || r.is_sameXYZC(i); }","tryCatchPattern":"try { CImg<float>::FFT(real, imag); }\ncatch (CImgInstanceException& e) { /* log both shapes, re-assign imag to real's dims */ }","preventionTips":["Pass an empty imag when you only have real data (auto zero-filled)","After cropping/resizing one part, resize the other identically","Call is_sameXYZC() as an assertion before FFT"],"tags":["cimg","fft","shape-mismatch"],"backgroundTag":"shape-mismatch","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"}