Skip to content

Commit

Permalink
Removing pillow dependency
Browse files Browse the repository at this point in the history
- Replace with calls to matplotlib’s imsave and imread
  • Loading branch information
freeman-lab committed Sep 10, 2014
1 parent 97d79c1 commit 87280ec
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion python/doc/install_local.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Dependencies
~~~~~~~~~~~~
Along with Spark, thunder depends on these Python libraries (by installing using ``pip`` these will be added automatically).

`numpy <http://www.numpy.org/>`__, `scipy <http://www.scipy.org/>`__, `scikit-learn <http://scikit-learn.org/stable/>`__, `pillow <https://pypi.python.org/pypi/Pillow>`__, `matplotlib <matplotlib.sourceforge.net>`__
`numpy <http://www.numpy.org/>`__, `scipy <http://www.scipy.org/>`__, `scikit-learn <http://scikit-learn.org/stable/>`__, `matplotlib <matplotlib.sourceforge.net>`__

We recommend using the `Anaconda distribution <https://store.continuum.io/cshop/anaconda/>`_, which includes these dependencies (and many other useful packages). Especially if you aren't already using Python for scientific computing, it's a great way to start.

Expand Down
1 change: 0 additions & 1 deletion python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ argparse
numpy
scipy
scikit-learn
pillow
matplotlib
nose
15 changes: 8 additions & 7 deletions python/thunder/utils/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
from numpy import std
from math import isnan
from numpy import array, squeeze, sum, shape, reshape, transpose, maximum, minimum, float16, uint8, savetxt, size, arange
from PIL import Image
from matplotlib.pyplot import imsave
from matplotlib import cm
from thunder.utils.load import getdims, subtoind, isrdd, Dimensions


def arraytoim(mat, filename, format="tif"):
"""Write a numpy array to a png image. If mat is 3D,
def arraytoim(mat, filename, format="png"):
"""Write a 2D numpy array to a grayscale image. If mat is 3D,
will separately write each image along the 3rd dimension
Parameters
Expand All @@ -23,16 +24,16 @@ def arraytoim(mat, filename, format="tif"):
filename : str
Base filename for writing
format : str, optional, default = "tif"
Image format to write (see PIL for options)
format : str, optional, default = "png"
Image format to write (see matplotlib's imsave for options)
"""
dims = shape(mat)
if len(dims) > 2:
for z in range(0, dims[2]):
cdata = mat[:, :, z]
Image.fromarray(cdata).save(filename+"-"+str(z)+"."+format)
imsave(filename+"-"+str(z)+"."+format, cdata, cmap=cm.gray)
elif len(dims) == 2:
Image.fromarray(mat).save(filename+"."+format)
imsave(filename+"."+format, mat, cmap=cm.gray)
else:
raise NotImplementedError('array must be 2 or 3 dimensions for image writing')

Expand Down

0 comments on commit 87280ec

Please sign in to comment.