From 53d3154f09d77bcd6ef9efae93bd6bba95f8df54 Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Mon, 14 Dec 2015 18:57:29 +1100 Subject: [PATCH] Use a strided 1-element array as dummy filter out When using generic_filter to build a graph, the numerical filter output is actually ignored. Building a full array, even of the smallest dtype, was wasteful. Using stride_tricks solves this by creating a single-element buffer into which all output is fed. --- skimage/future/graph/rag.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/skimage/future/graph/rag.py b/skimage/future/graph/rag.py index da5d8606..e97a2293 100644 --- a/skimage/future/graph/rag.py +++ b/skimage/future/graph/rag.py @@ -1,5 +1,6 @@ import networkx as nx import numpy as np +from numpy.lib.stride_tricks import as_strided from scipy import ndimage as ndi import math from ... import draw, measure, segmentation, util, color @@ -124,7 +125,9 @@ class RAG(nx.Graph): function=_add_edge_filter, footprint=fp, mode='nearest', - output=np.empty(label_image.shape, dtype=np.uint8), + output=as_strided(np.empty((1,), dtype=np.float_), + shape=label_image.shape, + strides=((0,) * label_image.ndim)), extra_arguments=(self,)) try: