Brickle Macho
2013-05-16 02:19:35 UTC
I am porting some Matlab code to python. When I run the ported version
the output differs. It appears the difference may be due to how I have
translated Matlab's imfilter() and/or fspecial(). Below are my
translation, are there any Scipy/Matlab gurus that can let me know if
there are correct or if I have made some errors, or could suggest better
translations.
Matlab: imfilter(saliencyMap, fspecial('gaussian', [10, 10], 2.5))
Scipy: ndimage.gaussian_filter(saliencyMap, sigma=2.5)
Also the following. At the rsik of highlighting my lack of
understanding of the temrinology, Is uniform_filter the same as 'average'?
Matlab: imfilter(myLogAmplitude, fspecial('average', 3), 'replicate');
Scipy: scipy.ndimage.uniform_filter(mylogAmplitude, size=3, mode="nearest")
Thanks,
Michael.
--
If curious here are the 8 lines of matlab code I am trying to port:
%% Read image from file
inImg = im2double(rgb2gray(imread('yourImage.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);
the output differs. It appears the difference may be due to how I have
translated Matlab's imfilter() and/or fspecial(). Below are my
translation, are there any Scipy/Matlab gurus that can let me know if
there are correct or if I have made some errors, or could suggest better
translations.
Matlab: imfilter(saliencyMap, fspecial('gaussian', [10, 10], 2.5))
Scipy: ndimage.gaussian_filter(saliencyMap, sigma=2.5)
Also the following. At the rsik of highlighting my lack of
understanding of the temrinology, Is uniform_filter the same as 'average'?
Matlab: imfilter(myLogAmplitude, fspecial('average', 3), 'replicate');
Scipy: scipy.ndimage.uniform_filter(mylogAmplitude, size=3, mode="nearest")
Thanks,
Michael.
--
If curious here are the 8 lines of matlab code I am trying to port:
%% Read image from file
inImg = im2double(rgb2gray(imread('yourImage.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);