From 605f05942f6ec7ffff544f6160f5f3e9807a705c Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Tue, 3 Feb 2015 14:58:57 +1100 Subject: [PATCH 01/10] Move RAG files to skimage.future --- skimage/{graph => future}/_ncut.py | 0 skimage/{graph => future}/_ncut_cy.pyx | 0 skimage/{graph => future}/graph_cut.py | 0 skimage/{graph => future}/graph_merge.py | 0 skimage/{graph => future}/rag.py | 0 skimage/{graph => future}/tests/test_rag.py | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename skimage/{graph => future}/_ncut.py (100%) rename skimage/{graph => future}/_ncut_cy.pyx (100%) rename skimage/{graph => future}/graph_cut.py (100%) rename skimage/{graph => future}/graph_merge.py (100%) rename skimage/{graph => future}/rag.py (100%) rename skimage/{graph => future}/tests/test_rag.py (100%) diff --git a/skimage/graph/_ncut.py b/skimage/future/_ncut.py similarity index 100% rename from skimage/graph/_ncut.py rename to skimage/future/_ncut.py diff --git a/skimage/graph/_ncut_cy.pyx b/skimage/future/_ncut_cy.pyx similarity index 100% rename from skimage/graph/_ncut_cy.pyx rename to skimage/future/_ncut_cy.pyx diff --git a/skimage/graph/graph_cut.py b/skimage/future/graph_cut.py similarity index 100% rename from skimage/graph/graph_cut.py rename to skimage/future/graph_cut.py diff --git a/skimage/graph/graph_merge.py b/skimage/future/graph_merge.py similarity index 100% rename from skimage/graph/graph_merge.py rename to skimage/future/graph_merge.py diff --git a/skimage/graph/rag.py b/skimage/future/rag.py similarity index 100% rename from skimage/graph/rag.py rename to skimage/future/rag.py diff --git a/skimage/graph/tests/test_rag.py b/skimage/future/tests/test_rag.py similarity index 100% rename from skimage/graph/tests/test_rag.py rename to skimage/future/tests/test_rag.py From 1b748668eecfd22e69ac7fa70356c8cdf917ad96 Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Tue, 3 Feb 2015 15:06:27 +1100 Subject: [PATCH 02/10] Move package to skimage.future.graph --- skimage/future/__init__.py | 0 skimage/future/graph/__init__.py | 12 ++++++++++++ skimage/future/{ => graph}/_ncut.py | 0 skimage/future/{ => graph}/_ncut_cy.pyx | 0 skimage/future/{ => graph}/graph_cut.py | 0 skimage/future/{ => graph}/graph_merge.py | 0 skimage/future/{ => graph}/rag.py | 2 +- skimage/future/{ => graph}/tests/test_rag.py | 0 skimage/graph/__init__.py | 4 ---- 9 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 skimage/future/__init__.py create mode 100644 skimage/future/graph/__init__.py rename skimage/future/{ => graph}/_ncut.py (100%) rename skimage/future/{ => graph}/_ncut_cy.pyx (100%) rename skimage/future/{ => graph}/graph_cut.py (100%) rename skimage/future/{ => graph}/graph_merge.py (100%) rename skimage/future/{ => graph}/rag.py (99%) rename skimage/future/{ => graph}/tests/test_rag.py (100%) diff --git a/skimage/future/__init__.py b/skimage/future/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/skimage/future/graph/__init__.py b/skimage/future/graph/__init__.py new file mode 100644 index 00000000..6b7e0aaa --- /dev/null +++ b/skimage/future/graph/__init__.py @@ -0,0 +1,12 @@ +from .graph_cut import cut_threshold, cut_normalized +from .rag import rag_mean_color, RAG, draw_rag +from .graph_merge import merge_hierarchical +ncut = cut_normalized + +__all__ = ['rag_mean_color', + 'cut_threshold', + 'cut_normalized', + 'ncut', + 'draw_rag', + 'merge_hierarchical', + 'RAG'] diff --git a/skimage/future/_ncut.py b/skimage/future/graph/_ncut.py similarity index 100% rename from skimage/future/_ncut.py rename to skimage/future/graph/_ncut.py diff --git a/skimage/future/_ncut_cy.pyx b/skimage/future/graph/_ncut_cy.pyx similarity index 100% rename from skimage/future/_ncut_cy.pyx rename to skimage/future/graph/_ncut_cy.pyx diff --git a/skimage/future/graph_cut.py b/skimage/future/graph/graph_cut.py similarity index 100% rename from skimage/future/graph_cut.py rename to skimage/future/graph/graph_cut.py diff --git a/skimage/future/graph_merge.py b/skimage/future/graph/graph_merge.py similarity index 100% rename from skimage/future/graph_merge.py rename to skimage/future/graph/graph_merge.py diff --git a/skimage/future/rag.py b/skimage/future/graph/rag.py similarity index 99% rename from skimage/future/rag.py rename to skimage/future/graph/rag.py index 120e9e91..e3d52875 100644 --- a/skimage/future/rag.py +++ b/skimage/future/graph/rag.py @@ -14,7 +14,7 @@ import numpy as np from scipy.ndimage import filters from scipy import ndimage as nd import math -from .. import draw, measure, segmentation, util, color +from ... import draw, measure, segmentation, util, color try: from matplotlib import colors from matplotlib import cm diff --git a/skimage/future/tests/test_rag.py b/skimage/future/graph/tests/test_rag.py similarity index 100% rename from skimage/future/tests/test_rag.py rename to skimage/future/graph/tests/test_rag.py diff --git a/skimage/graph/__init__.py b/skimage/graph/__init__.py index f93708c9..89260f1f 100644 --- a/skimage/graph/__init__.py +++ b/skimage/graph/__init__.py @@ -1,9 +1,5 @@ from .spath import shortest_path from .mcp import MCP, MCP_Geometric, MCP_Connect, MCP_Flexible, route_through_array -from .graph_cut import cut_threshold, cut_normalized -from .rag import rag_mean_color, RAG, draw_rag -from .graph_merge import merge_hierarchical -ncut = cut_normalized __all__ = ['shortest_path', From eeaf7662912d83a4417d53127c4db6f33b7adc33 Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Tue, 3 Feb 2015 15:08:12 +1100 Subject: [PATCH 03/10] Update bento file to moved RAG code --- bento.info | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bento.info b/bento.info index a36a4ebb..bfc607a8 100644 --- a/bento.info +++ b/bento.info @@ -33,7 +33,8 @@ UseBackends: Waf Library: Packages: skimage, skimage.color, skimage.data, skimage.draw, skimage.exposure, - skimage.feature, skimage.filters, skimage.graph, skimage.io, + skimage.feature, skimage.filters, skimage.future, skimage.future.graph, + skimage.graph, skimage.io, skimage.io._plugins, skimage.measure, skimage.morphology, skimage.scripts, skimage.restoration, skimage.segmentation, skimage.transform, skimage.util @@ -151,9 +152,9 @@ Library: Extension: skimage.feature._hessian_det_appx Sources: skimage/exposure/_hessian_det_appx.pyx - Extension: skimage.graph._ncut_cy + Extension: skimage.future.graph._ncut_cy Sources: - skimage/graph/_ncut_cy.pyx + skimage/future/graph/_ncut_cy.pyx Extension: skimage.external.tifffile._tifffile Sources: skimage/external/tifffile/_tifffile.c From 483d7d669baa37b79605f594db3f5884f1806832 Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Tue, 3 Feb 2015 15:10:54 +1100 Subject: [PATCH 04/10] Update plot_rag examples to use skimage.future --- doc/examples/plot_rag.py | 2 +- doc/examples/plot_rag_draw.py | 3 ++- doc/examples/plot_rag_mean_color.py | 3 ++- doc/examples/plot_rag_merge.py | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/doc/examples/plot_rag.py b/doc/examples/plot_rag.py index e44f4094..d4f2711c 100644 --- a/doc/examples/plot_rag.py +++ b/doc/examples/plot_rag.py @@ -14,7 +14,7 @@ The example below also shows how to use a custom function to select the larger weight instead. """ -from skimage.graph import rag +from skimage.future.graph import rag import networkx as nx from matplotlib import pyplot as plt import numpy as np diff --git a/doc/examples/plot_rag_draw.py b/doc/examples/plot_rag_draw.py index 0c1e1abc..bdc39678 100644 --- a/doc/examples/plot_rag_draw.py +++ b/doc/examples/plot_rag_draw.py @@ -6,7 +6,8 @@ Drawing Region Adjacency Graphs (RAGs) This example constructs a Region Adjacency Graph (RAG) and draws it with the `rag_draw` method. """ -from skimage import graph, data, segmentation +from skimage import data, segmentation +from skimage.future import graph from matplotlib import pyplot as plt, colors diff --git a/doc/examples/plot_rag_mean_color.py b/doc/examples/plot_rag_mean_color.py index ab962e65..4b2bfcae 100644 --- a/doc/examples/plot_rag_mean_color.py +++ b/doc/examples/plot_rag_mean_color.py @@ -9,7 +9,8 @@ difference in mean color. We then join regions with similar mean color. """ -from skimage import graph, data, io, segmentation, color +from skimage import data, io, segmentation, color +from skimage.future import graph from matplotlib import pyplot as plt diff --git a/doc/examples/plot_rag_merge.py b/doc/examples/plot_rag_merge.py index d454a096..37712d5b 100644 --- a/doc/examples/plot_rag_merge.py +++ b/doc/examples/plot_rag_merge.py @@ -10,7 +10,8 @@ until no highly similar region pairs remain. """ -from skimage import graph, data, io, segmentation, color +from skimage import data, io, segmentation, color +from skimage.future import graph import numpy as np From 5bd36730fc2cd2aa160ef00246fb3635cf334a0a Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Tue, 3 Feb 2015 15:13:02 +1100 Subject: [PATCH 05/10] Update plot_ncut example to use skimage.future --- doc/examples/plot_ncut.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/examples/plot_ncut.py b/doc/examples/plot_ncut.py index 6b8a62ab..5596a297 100644 --- a/doc/examples/plot_ncut.py +++ b/doc/examples/plot_ncut.py @@ -12,7 +12,8 @@ References Pattern Analysis and Machine Intelligence, IEEE Transactions on, vol. 22, no. 8, pp. 888-905, August 2000. """ -from skimage import graph, data, io, segmentation, color +from skimage import data, io, segmentation, color +from skimage.future import graph from matplotlib import pyplot as plt From d2d50e93911693c326b057a4c48f0a47d520f0a1 Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Tue, 3 Feb 2015 15:20:57 +1100 Subject: [PATCH 06/10] Add package docstring for skimage.future --- skimage/future/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/skimage/future/__init__.py b/skimage/future/__init__.py index e69de29b..121ff925 100644 --- a/skimage/future/__init__.py +++ b/skimage/future/__init__.py @@ -0,0 +1,6 @@ +"""Functionality with an experimental API. Although you can count on the +functions in this package being around in the future, the API may change with +any version update **and will not follow the skimage two-version deprecation +path**. Therefore, use the functions herein with care, and do not use them in +production code that will depend on updated skimage versions. +""" From 008775853fb1a4e0a648f26dfe7cceb60ced7a76 Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Tue, 3 Feb 2015 15:34:56 +1100 Subject: [PATCH 07/10] Fix setup.py cascade --- skimage/future/graph/setup.py | 30 ++++++++++++++++++++++++++++++ skimage/future/setup.py | 12 ++++++++++++ skimage/graph/setup.py | 3 --- skimage/setup.py | 1 + 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 skimage/future/graph/setup.py create mode 100644 skimage/future/setup.py diff --git a/skimage/future/graph/setup.py b/skimage/future/graph/setup.py new file mode 100644 index 00000000..059a0779 --- /dev/null +++ b/skimage/future/graph/setup.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +from skimage._build import cython +import os.path + +base_path = os.path.abspath(os.path.dirname(__file__)) + + +def configuration(parent_package='', top_path=None): + from numpy.distutils.misc_util import Configuration, get_numpy_include_dirs + + config = Configuration('graph', parent_package, top_path) + config.add_data_dir('tests') + + # This function tries to create C files from the given .pyx files. If + # it fails, try to build with pre-generated .c files. + cython(['_ncut_cy.pyx'], working_path=base_path) + config.add_extension('_ncut_cy', sources=['_ncut_cy.c'], + include_dirs=[get_numpy_include_dirs()]) + return config + +if __name__ == '__main__': + from numpy.distutils.core import setup + setup(maintainer='scikit-image Developers', + maintainer_email='scikit-image@googlegroups.com', + description='Graph-based Image-processing Algorithms', + url='https://github.com/scikit-image/scikit-image', + license='Modified BSD', + **(configuration(top_path='').todict()) + ) diff --git a/skimage/future/setup.py b/skimage/future/setup.py new file mode 100644 index 00000000..aaded0c7 --- /dev/null +++ b/skimage/future/setup.py @@ -0,0 +1,12 @@ + +def configuration(parent_package='skimage', top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('future', parent_package, top_path) + config.add_subpackage('graph') + return config + +if __name__ == "__main__": + from numpy.distutils.core import setup + + config = configuration(top_path='').todict() + setup(**config) diff --git a/skimage/graph/setup.py b/skimage/graph/setup.py index edc7b653..4c6aba06 100644 --- a/skimage/graph/setup.py +++ b/skimage/graph/setup.py @@ -17,7 +17,6 @@ def configuration(parent_package='', top_path=None): cython(['_spath.pyx'], working_path=base_path) cython(['_mcp.pyx'], working_path=base_path) cython(['heap.pyx'], working_path=base_path) - cython(['_ncut_cy.pyx'], working_path=base_path) config.add_extension('_spath', sources=['_spath.c'], include_dirs=[get_numpy_include_dirs()]) @@ -25,8 +24,6 @@ def configuration(parent_package='', top_path=None): include_dirs=[get_numpy_include_dirs()]) config.add_extension('heap', sources=['heap.c'], include_dirs=[get_numpy_include_dirs()]) - config.add_extension('_ncut_cy', sources=['_ncut_cy.c'], - include_dirs=[get_numpy_include_dirs()]) return config if __name__ == '__main__': diff --git a/skimage/setup.py b/skimage/setup.py index 94d00ea8..b33f5e81 100644 --- a/skimage/setup.py +++ b/skimage/setup.py @@ -14,6 +14,7 @@ def configuration(parent_package='', top_path=None): config.add_subpackage('feature') config.add_subpackage('restoration') config.add_subpackage('filters') + config.add_subpackage('future') config.add_subpackage('graph') config.add_subpackage('io') config.add_subpackage('measure') From 9cbeeca0df1233bbd0530a94c24158313281a2d3 Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Tue, 3 Feb 2015 15:52:26 +1100 Subject: [PATCH 08/10] Update RAG doctest to use future --- skimage/future/graph/rag.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/skimage/future/graph/rag.py b/skimage/future/graph/rag.py index e3d52875..9e882bae 100644 --- a/skimage/future/graph/rag.py +++ b/skimage/future/graph/rag.py @@ -251,7 +251,8 @@ def rag_mean_color(image, labels, connectivity=2, mode='distance', Examples -------- - >>> from skimage import data, graph, segmentation + >>> from skimage import data, segmentation + >>> from skimage.future import graph >>> img = data.astronaut() >>> labels = segmentation.slic(img) >>> rag = graph.rag_mean_color(img, labels) From e5fe82d6f32f75f03b2de7c24c667b345862f4a8 Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Tue, 3 Feb 2015 16:20:15 +1100 Subject: [PATCH 09/10] Fix even more tests still importing skimage.graph --- skimage/future/graph/graph_cut.py | 6 ++++-- skimage/future/graph/rag.py | 3 ++- skimage/future/graph/tests/test_rag.py | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/skimage/future/graph/graph_cut.py b/skimage/future/graph/graph_cut.py index b4658bd1..d727eeac 100644 --- a/skimage/future/graph/graph_cut.py +++ b/skimage/future/graph/graph_cut.py @@ -37,7 +37,8 @@ def cut_threshold(labels, rag, thresh, in_place=True): Examples -------- - >>> from skimage import data, graph, segmentation + >>> from skimage import data, segmentation + >>> from skimage.future import graph >>> img = data.astronaut() >>> labels = segmentation.slic(img) >>> rag = graph.rag_mean_color(img, labels) @@ -107,7 +108,8 @@ def cut_normalized(labels, rag, thresh=0.001, num_cuts=10, in_place=True, Examples -------- - >>> from skimage import data, graph, segmentation + >>> from skimage import data, segmentation + >>> from skimage.future import graph >>> img = data.astronaut() >>> labels = segmentation.slic(img, compactness=30, n_segments=400) >>> rag = graph.rag_mean_color(img, labels, mode='similarity') diff --git a/skimage/future/graph/rag.py b/skimage/future/graph/rag.py index 9e882bae..b0fd9240 100644 --- a/skimage/future/graph/rag.py +++ b/skimage/future/graph/rag.py @@ -365,7 +365,8 @@ def draw_rag(labels, rag, img, border_color=None, node_color='#ffff00', Examples -------- - >>> from skimage import data, graph, segmentation + >>> from skimage import data, segmentation + >>> from skimage.future import graph >>> img = data.coffee() >>> labels = segmentation.slic(img) >>> g = graph.rag_mean_color(img, labels) diff --git a/skimage/future/graph/tests/test_rag.py b/skimage/future/graph/tests/test_rag.py index cfa49cdf..1cac2b2d 100644 --- a/skimage/future/graph/tests/test_rag.py +++ b/skimage/future/graph/tests/test_rag.py @@ -1,5 +1,5 @@ import numpy as np -from skimage import graph +from skimage.future import graph from skimage._shared.version_requirements import is_installed from numpy.testing.decorators import skipif from skimage import segmentation From 0d1a2ef1faa6a732b59816bc07f281e519f3aa4f Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Wed, 4 Feb 2015 00:37:48 +1100 Subject: [PATCH 10/10] Import graph into future parent package --- skimage/future/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/skimage/future/__init__.py b/skimage/future/__init__.py index 121ff925..0292a6ef 100644 --- a/skimage/future/__init__.py +++ b/skimage/future/__init__.py @@ -4,3 +4,7 @@ any version update **and will not follow the skimage two-version deprecation path**. Therefore, use the functions herein with care, and do not use them in production code that will depend on updated skimage versions. """ + +from . import graph + +__all__ = ['graph']