Skip to content

Instantly share code, notes, and snippets.

@meresmclr
Last active June 26, 2016 15:34
Show Gist options
  • Save meresmclr/dbef4c170471bd227863ca1f755d8ca2 to your computer and use it in GitHub Desktop.
Save meresmclr/dbef4c170471bd227863ca1f755d8ca2 to your computer and use it in GitHub Desktop.
Matlab Python workaround for N-D array passing. Matlab R2014b-R2016a
% 200x320 image is now in variable X
load clown
% I ravel X to a row vector, and unravel with Numpy
Xp = py.numpy.reshape(X(:)',size(X),'F');
% Apply Gaussian filter to image
Yp = py.skimage.filters.gaussian(Xp,3);
% now let's come back to Matlab
% Y is a regular Matlab 2-D matrix
Y = reshape(cell2mat(cell(Yp.ravel('F').tolist())),size(X));
%map comes from when you load clown
figure
subplot(1,2,1), imshow(X,map),title('original')
subplot(1,2,2), imshow(Y,map),title('filtered by Python Scikit-Image')
%======================================================================
% now let's do something similar in Matlab--
% note I didn't make the filter truncation radius the same, so the numerical results differ.
F = fspecial('gaussian',[15,15],3);
M = imfilter(X,F);
imshow(M,map)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment