title: Why is the output different for code ported from MATLAB to Python?
body: <p><strong>EDIT:</strong>  <em>After some more testing and a response form the scipy mailing list, the issue appears to be with fspecial().  To get the same output I need to generate the same kind of kernel in Python as the Matlab fspecial command is producing.  For now I will try to export the kernel from matlab and work from there.   Added as a edit since question has been "closed"</em></p>
  
  <hr>
  
  <p>I am trying to port the following MATLAB code to Python.  It seems to work but the output is different form MATLAB.  I think the problem is with apply a "mean" filter to the log(amplituide). Any help appreciated.</p>
  
  <p>The MATLAB code is from: <a href="http://www.klab.caltech.edu/~xhou/projects/spectralResidual/spectralresidual.html" rel="nofollow noreferrer">http://www.klab.caltech.edu/~xhou/projects/spectralResidual/spectralresidual.html</a></p>
  
  <pre><code>%% Read image from file
  inImg = im2double(rgb2gray(imread('1.jpg')));
  inImg = imresize(inImg, 64/size(inImg, 2));
  
  %% Spectral Residual
  myFFT = fft2(inImg);
  myLogAmplitude = log(abs(myFFT));
  myPhase = angle(myFFT);
  mySpectralResidual = myLogAmplitude - imfilter(myLogAmplitude, fspecial('average', 3), 'replicate');
  saliencyMap = abs(ifft2(exp(mySpectralResidual + i*myPhase))).^2;
  
  %% After Effect
  saliencyMap = mat2gray(imfilter(saliencyMap, fspecial('gaussian', [10, 10], 2.5)));
  imshow(saliencyMap);
  </code></pre>
  
  <p>Here is my attempt in python:</p>
  
  <pre><code>from skimage import img_as_float                                                       
  from skimage.io import imread
  from skimage.color import rgb2gray                                                    
  from scipy import fftpack, ndimage, misc                                        
  from scipy.ndimage import uniform_filter
  from matplotlib.pyplot as plt
  
  # Read image from file
  image = img_as_float(rgb2gray(imread('1.jpg')))
  image = misc.imresize(image, 64.0 / image.shape[0])
  
  # Spectral Residual
  fft = fftpack.fft2(image)                                                   
  logAmplitude = np.log(np.abs(fft))                                          
  phase = np.angle(fft)                                                       
  avgLogAmp = uniform_filter(logAmplitude, size=3, mode="nearest") #Is this same a applying "mean" filter            
  spectralResidual = logAmplitude - avgLogAmp                                 
  saliencyMap = np.abs(fftpack.ifft2(np.exp(spectralResidual + 1j * phase))) ** 2
  
  # After Effect
  saliencyMap = ndimage.gaussian_filter(sm, sigma=2.5)
  plt.imshow(sm)
  plt.show()
  </code></pre>
  
  <p>For completness here is a input image and the output from MATLAB and python.</p>
  
  <p><img src="https://i.stack.imgur.com/tv6VE.jpg" alt="Input Image, Island"> 
  <img src="https://i.stack.imgur.com/lk2X9.jpg" alt="Saliency Map (MATLAB)">
  <img src="https://i.stack.imgur.com/SyEd3.png" alt="Saliency Map (PYTHON)"></p>