-2

I am getting confused over all the different python datatypes. I wrote a face recognition algorithm in MATLAB, I want to redo it it Python. I am stuck trying to resize my images. How do I do that? Can someone link me to the things that i need to read to understand the difference in the functions between MATLAB in Python? Like MATLAB got imresize but Python got what?

Is there something like import all_matlab_functions so I can python in matlab language ?

I cant believe im struggling so hard. Help! My code below shows how stupid i am with python currently.

%matplotlib inline

import matplotlib.image as mpimg
import glob

import matplotlib.pyplot as plt

image_list = []
for filename in glob.glob('<directory>.pgm'):
    im = mpimg.imread(filename)
    image_list.append(im)  # read all image

from PIL import Image
haha = image_list[1].resize((10 10), resample=0) # try to resize image BUT FAIL
TheBlackCat
  • 9,791
  • 3
  • 24
  • 31
cschua
  • 43
  • 1
  • 9
  • 2
    Thats not how python works. Its not a 1 to 1 matlab to something else. Matlab is one thing, python is another different thing. It just happens that the way the languages have been designed, they share similarities. But if you want to do something in python, dont look how to do it in matlab and translate, find it how to do it in python. – Ander Biguri Jun 27 '16 at 15:28
  • Related: http://stackoverflow.com/questions/273946/how-do-i-resize-an-image-using-pil-and-maintain-its-aspect-ratio – Chris Mueller Jun 27 '16 at 15:33
  • You are asking multiple different questions, none of which are on-topic. Please explain exactly what you are trying to do, what you have done, and in what way it is not working. Also, IPython is just an interface for the Python language, the code is written in the Python language. – TheBlackCat Jun 27 '16 at 18:25

1 Answers1

0

using the jupyter qt-console interpreter, or jupyter notebook you can set the interpreter environment magic %pylab inline so that images will be displayed inline and the matplotlib.pylab namespace and numpy namespaces will be imported into the current namespace. All this means though is that you don't have to prefix the commands with matplotlib.pylab.plot or plt.plot, for example. You can just use plot().

%pylab inline
x = linsapce(1,2*pi,100)
y = sin(x)
plot(x,y)

matplotlib is meant to give good tools for plotting that look similar to matlab plotting, numpy for arrays and mathematics, and scipy gives you tools for more complex functions. For example, scipy.misc.imresize can do what you are looking for:

http://docs.scipy.org/doc/scipy-0.13.0/reference/generated/scipy.misc.imresize.html

If you are looking for a direct way to run your matlab programs outside of matlab, you might want to try Octave instead.

https://www.gnu.org/software/octave/

Vince W.
  • 3,561
  • 3
  • 31
  • 59