GreycLab / CImg

The CImg Library is a small and open-source C++ toolkit for image processing
http://cimg.eu
Other
1.46k stars 278 forks source link

[Enhancement] Feature request: L2 norm across z for CImg objects, L2 across depth for CImgList objects #395

Open KBentley57 opened 11 months ago

KBentley57 commented 11 months ago

HI All,

I use CImg quite a bit for image processing tasks, and if I'm obviously overlooking something, by all means just throw it at me.

I've been doing a few FFT's, and when calculating the magnitude, or power spectrum of the real and complex parts returned, I noticed that there's no magnitude() or norm() function that acts across the z axis for images, and across the stack for CImgList objects. I end up with code that has the form

cimg_library::CImg<float> Analytic(N,N,1,1,0.0f);

cimg_library::CImgList<float> CImg_FFT = Analytic.get_FFT('x',true);

cimg_library::CImg<float> CImg_FFT_magnitude = (CImg_FFT(0).get_pow(2) + CImg_FFT(1).get_pow(2)).sqrt();

While it works fine, it seems that there ought to be something like this

cimg_library::CImgList<float> CImg_FFT = Analytic.get_FFT('x',true);

cimg_library::CImg<float> CImg_FFT_magnitude = CImg_FFT.get_norm(2);

or possibly even

cimg_library::CImgList<float> CImg_FFT = Analytic.get_FFT('x',true);
CImg_FFT.norm(2);

If norm isn't the right term, replace with magnitude. Perhaps it's a better self documenting name anyways.

This would seem to put the CImgList class at least with parity against the CImg class, in that it has both a magnitude() and norm() function. Alternatively, I could compose the two images returned from the FFT into an image with two channels, but that seems kludgy and not really better than what I have in terms of the expressiveness of the code.

Thanks for your thoughts! I really appreciate this project and all who've contributed to it.

Kyle B