Yalantis/uCrop · error · CImgInstanceException

CImgList<%s>::FFT(): Specified real part (%u,%u,%u,%u,%p) an

Error message

CImgList<%s>::FFT(): Specified real part (%u,%u,%u,%u,%p) and imaginary part (%u,%u,%u,%u,%p) have different dimensions.

What it means

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.

Source

Thrown at ucrop/src/main/jni/CImg.h:47934

#endif
    }

    //! Compute n-D Fast Fourier Transform.
    /**
       \param[in,out] real Real part of the pixel values.
       \param[in,out] imag Imaginary part of the pixel values.
       \param is_inverse Tells if the forward (\c false) or inverse (\c true) FFT is computed.
       \param nb_threads Number of parallel threads used for the computation.
         Use \c 0 to set this to the number of available cpus.
    **/
    static void FFT(CImg<T>& real, CImg<T>& imag, const bool is_inverse=false,
                    const unsigned int nb_threads=0) {
      if (!real)
        throw CImgInstanceException("CImgList<%s>::FFT(): Empty specified real part.",
                                    pixel_type());
      if (!imag) imag.assign(real._width,real._height,real._depth,real._spectrum,(T)0);
      if (!real.is_sameXYZC(imag))
        throw CImgInstanceException("CImgList<%s>::FFT(): Specified real part (%u,%u,%u,%u,%p) and "
                                    "imaginary part (%u,%u,%u,%u,%p) have different dimensions.",
                                    pixel_type(),
                                    real._width,real._height,real._depth,real._spectrum,real._data,
                                    imag._width,imag._height,imag._depth,imag._spectrum,imag._data);
      cimg::unused(nb_threads);
#ifdef cimg_use_fftw3
      cimg::mutex(12);
#ifndef cimg_use_fftw3_singlethread
      fftw_plan_with_nthreads(nb_threads?nb_threads:cimg::nb_cpus());
#endif
      fftw_complex *data_in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*real._width*real._height*real._depth);
      if (!data_in)
        throw CImgInstanceException("CImgList<%s>::FFT(): Failed to allocate memory (%s) "
                                    "for computing FFT of image (%u,%u,%u,%u).",
                                    pixel_type(),
                                    cimg::strbuffersize(sizeof(fftw_complex)*real._width*
                                                        real._height*real._depth*real._spectrum),
                                    real._width,real._height,real._depth,real._spectrum);

View on GitHub (pinned to f788b534b4)

Solutions

  1. Make imag the same size as real before calling FFT (imag.assign(real.width(), real.height(), real.depth(), real.spectrum(), (T)0) then copy).
  2. Pass an empty (default-constructed) imag if you only have real data; it is auto-assigned to real's dimensions.
  3. Resize/crop the smaller part to match the other (CImg::resize).
  4. Verify with real.is_sameXYZC(imag) before calling FFT.

Example fix

// before
CImg<float> real(256,256), imag(128,128);
CImg<float>::FFT(real, imag); // dimension mismatch
// after
CImg<float> real(256,256), imag(256,256,1,1,0);
CImg<float>::FFT(real, imag);
Defensive patterns

Strategy: validation

Validate before calling

if (!real.is_sameXYZC(imag))
  imag.assign(real.width(), real.height(), real.depth(), real.spectrum(), (T)0); // zero-fill

Type guard

bool isCompatiblePair(const CImg<T>& r, const CImg<T>& i) { return i.is_empty() || r.is_sameXYZC(i); }

Try / catch

try { CImg<float>::FFT(real, imag); }
catch (CImgInstanceException& e) { /* log both shapes, re-assign imag to real's dims */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/53deb697bda4989e. Report an issue: GitHub.