spectral residual saliency detection in C++ with CImg -


I am trying to apply the spectral residual approach to the salt search described in this letter: < P> There is a reference implementation in Matlab Code, which is derived from their website:

  Read image from image in clear clique %% file = im2double (rgb2gray (imread ('yourImage.jpg '))); InImg = imresize (inImg, 64 / size (inImg, 2)); %% spectral residual MYFFT = fft2 (inImg); MyLogAmplitude = Log (myFFT)); MyPhase = angle (myFFT); MySpectralResidual = myLogAmplitude - imfilter (myLogAmplitude, fspecial ('average', 3), 'replica'); SaliencyMap = abs (ifft2 (exp (mySpectralResidual + i * myPhase))). ^ 2; After %% effect saliencyMap = mat2gray (imfilter (selcharapmap, fspecial ('gaussi', [10, 10], 2.5))); Imshow (saliencyMap);   

I tried to translate it to C ++ with CIMG. Where I am failing here:

  myPhase = angle (myFFT);   

and here

  saliencyMap = abs (ifft2 (exp (mySpectralResidual + i * myPhase)). ^ 2;   

This is my code:

  #include & lt; CImg.h & gt; # Include & lt; iostream & gt; using the namespace cimg_library; int main () { CImg & lt; Unsigned four> image ("img2.jpg"); CImg & lt; float & gt; mask (3,3,1,1,1 / 9,0); image.resize (64,64 ); CImgList & gt; Float & gt; MyFFT = image.get_FFT (); Const CIMG & lt; float & gt; MyLogAmplitude = ((myFFT [0] .get_pow (2) + myFFT [1] .get_pow (2) Get_sqrt (); Get_log (); // Magneti Const Cimg  Mifex = MeriFatty [0] .get_atan2 (myFFT [1]); Consta Cia MG  A = Myelogamytti.jet_kanklev (mask); Const CIMG  MySparent receiptual = Myelogeplatie A-A; CImgList & lt; float & gt; Tmp = CImgList & lt; float & Gt; (MyResidual.get_exp (), MyFage); CImgList & lt; float & gt; MySalienceMap = tmp.get_FFT (true); CIMG visual display DAPP 0 (MySlasPanemanMap, "Image"); While (! Draw_disp0.is_closed ()) {draw_disp0.wait (); } Return 0; }   

Has anyone seen a clear mistake?

I think I can see two mistakes in your code:

  • First of all, atan2 () is the inverse logic in the call for MyPhase.

    CONST CIMG MIFFZ = My FFT [1] .get_atan2 (myFFT [0]);

    (but it is probably not more on the other side, and it is more serious, you can have values ​​coded as complex (amplitude, phase) There is an inverse FFT on a pair of, which is not expected by CIMG, as the FFT () function considers you to be a real (real, imaginary) pair of images, possibly a big difference in the result.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -