Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added morphology example. Updated README.md with installation details.

  • Loading branch information...
commit 4cf5f37536c298bd0ad16e6fc44e4e144dafb627 1 parent 30501a8
@jesolem authored
Showing with 28 additions and 3 deletions.
  1. +7 −3 README.md
  2. +21 −0 examples/morphology.py
View
10 README.md
@@ -17,13 +17,17 @@ Many sections show applications that require smaller specialized Python modules.
### Structure
-*PCV/* the code.
+*PCV/* the code.
-*pcv_book/* contains a clean folder with the code exactly as used in the book at time of publication.
+*pcv_book/* contains a clean folder with the code exactly as used in the book at time of publication.
-*examples/* contains sample code.
+*examples/* contains sample code. Some examples use data available at [programmingcomputervision.com](http://programmingcomputervision.com/).
+### Installation
+Open a terminal in the PCV directory and run (with sudo if needed on your system):
+
+ python setup.py install
### License
View
21 examples/morphology.py
@@ -0,0 +1,21 @@
+from PIL import Image
+from numpy import *
+
+from scipy.ndimage import measurements,morphology
+
+"""
+This is the morphology example in section 1.4.
+"""
+
+# load image and threshold to make sure it is binary
+im = array(Image.open('houses.png').convert('L'))
+im = 1*(im<128)
+
+labels, nbr_objects = measurements.label(im)
+print "Number of objects:", nbr_objects
+
+# morphology - opening to separate objects better
+im_open = morphology.binary_opening(im,ones((9,5)),iterations=2)
+
+labels_open, nbr_objects_open = measurements.label(im_open)
+print "Number of objects:", nbr_objects_open
Please sign in to comment.
Something went wrong with that request. Please try again.