Add morphological reconstruction #215

Merged
merged 21 commits into from Aug 25, 2012

Projects

None yet

4 participants

@tonysyu
Member
tonysyu commented Jul 13, 2012

Add greyscale, morphological reconstruction adapted from CellProfiler.

Todo:

  • Clean up code (most of this is taken from CellProfiler with little modification).
  • Improve example: there could be more explanatory text (esp. for the white-tophat part). Also, the example was written before the plot2rst extension was added, so plot titles should probably be replaced by explanatory text.
@emmanuelle emmanuelle commented on an outdated diff Jul 20, 2012
skimage/morphology/tests/test_reconstruction.py
+
+def test_zeros():
+ """Test reconstruction with image and mask of zeros"""
+ assert np.all(reconstruction(np.zeros((5, 7)), np.zeros((5, 7))) == 0)
+
+
+def test_image_equals_mask():
+ """Test reconstruction where the image and mask are the same"""
+ assert np.all(reconstruction(np.ones((7, 5)), np.ones((7, 5))) == 1)
+
+
+def test_image_less_than_mask():
+ """Test reconstruction where the image is uniform and less than mask"""
+ image = np.ones((5, 5))
+ mask = np.ones((5, 5)) * 2
+ assert np.all(reconstruction(image,mask) == 1)
@emmanuelle
emmanuelle Jul 20, 2012 Member

whitespace after comma

@emmanuelle emmanuelle commented on an outdated diff Jul 20, 2012
skimage/morphology/tests/test_reconstruction.py
+ assert np.all(reconstruction(np.ones((7, 5)), np.ones((7, 5))) == 1)
+
+
+def test_image_less_than_mask():
+ """Test reconstruction where the image is uniform and less than mask"""
+ image = np.ones((5, 5))
+ mask = np.ones((5, 5)) * 2
+ assert np.all(reconstruction(image,mask) == 1)
+
+
+def test_one_image_peak():
+ """Test reconstruction with one peak pixel"""
+ image = np.ones((5, 5))
+ image[2, 2] = 2
+ mask = np.ones((5, 5)) * 3
+ assert np.all(reconstruction(image,mask) == 2)
@emmanuelle
emmanuelle Jul 20, 2012 Member

whitespace after comma

@emmanuelle
Member

Hi Tony, would you prefer me to comment on the diff, or to checkout your branch and work on it? If you're busy with other things the second solution might be better.

@tonysyu
Member
tonysyu commented Jul 20, 2012

If you have time to make changes directly to a branch, that'd be great.

@tonysyu
Member
tonysyu commented Aug 19, 2012

@emmanuelle I made some major changes in the last couple of days. I removed the tutorial because it needed a lot of work, but I replaced it with 2 examples. I also added the ability to do reconstruction by erosion and cleaned up the code a bit. If you have time to take a look at the revised PR, that'd be great.

@stefanv stefanv commented on the diff Aug 24, 2012
skimage/morphology/_greyreconstruct.pyx
@@ -0,0 +1,81 @@
+"""
+`reconstruction_loop` originally part of CellProfiler, code licensed under both GPL and BSD licenses.
+
+Website: http://www.cellprofiler.org
+Copyright (c) 2003-2009 Massachusetts Institute of Technology
+Copyright (c) 2009-2011 Broad Institute
+All rights reserved.
+Original author: Lee Kamentsky
+
+"""
+cimport cython
+
+
+@cython.boundscheck(False)
+def reconstruction_loop(unsigned int[:] ranks, int[:] prev, int[:] next,
@stefanv
stefanv Aug 24, 2012 Member

This does not work on Cython 0.15.

@tonysyu
tonysyu Aug 25, 2012 Member

Hmm, I thought we were pretty aggressive with our Cython dependency. Since it's a bit less stable than, say, numpy or matplotlib, I thought it was OK to use the latest stable version, i.e. 0.16. Thoughts? (Note: the website currently states 0.15 as the minimum requirement)

@stefanv
stefanv Aug 25, 2012 Member

I think that's fine, as long as we update the DEPENDS.txt

tonysyu added some commits Aug 25, 2012
@stefanv stefanv merged commit 544fec7 into scikit-image:master Aug 25, 2012
@amueller
Member

There seems to be lots of test failures because grey_reconstruct was moved. It seems to be imported in many places.

@amueller
Member

The actual error I get is (No module named rank_order)
File "/home/andy/checkout/scikits.image/skimage/morphology/greyreconstruct.py", line 14, in

@tonysyu
Member
tonysyu commented Aug 25, 2012

This should be addressed by PR #270. (I always forget to clean out *.pyc files)

@amueller
Member

Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment