commit 83d987cba9ed0d80ee145e8797c93cdcbc1fc701
parent c2d40de0c1dea41320e984bbbc1a65c3d610baee
Author: Anders Damsgaard <anders.damsgaard@geo.au.dk>
Date: Thu, 13 Feb 2014 21:56:34 +0100
numpy/scipy as image processing libraries
Diffstat:
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/README.rst b/README.rst
@@ -7,7 +7,11 @@ https://github.com/anders-dc/cross-stitch
Requirements
------------
-Python 2 or 3, Python Imaging Library
+Python 2 or 3, Numpy, Scipy, and Matplotlib.
+
+To install these dependencies in Debian and its derivatives, run:
+
+ $ sudo apt-get install python python-numpy python-scipy python-matplotlib
License
-------
diff --git a/cross-stitch.py b/cross-stitch.py
@@ -2,7 +2,8 @@
import sys
import argparse
-import Image
+import scipy.ndimage
+import scipy.misc
import numpy as np
import matplotlib.pyplot as plt
@@ -18,26 +19,31 @@ parser.add_argument('--outfile', '-o', metavar='FILENAME', type=str, nargs=1,
required=True, help='save processed image as FILENAME')
parser.add_argument('--width', '-w', type=int, nargs=1, default=20,
help='canvas width, default value = 20')
+parser.add_argument('--n-colors', '-c', type=int, nargs=1, default=10,
+ help='number of colors in output image, default value = 10')
args = parser.parse_args()
infile = args.infile[0]
outfile = args.outfile[0]
-width = args.width
+width = args.width[0]
## Read image ##################################################################
try:
- im = Image.open(infile)
+ im = scipy.ndimage.imread(infile)
except IOError:
sys.stderr.write('could not open input file "' + infile + '"\n')
sys.exit(1)
## Downsampling ################################################################
-hw_ratio = float(im.size[1])/im.size[0]
-new_size = (width, int(round(hw_ratio*width)))
-im = im.resize(new_size)
+hw_ratio = float(im.shape[0])/im.shape[1]
+new_size = (int(round(hw_ratio*width)), width)
+im_small = scipy.misc.imresize(im, new_size)
## Process image colors ########################################################
## Generate output plot ########################################################
-
-
+fig = plt.figure()
+imgplot = plt.imshow(im_small)
+imgplot.set_interpolation('nearest')
+plt.grid()
+plt.savefig(outfile)