From a90096555ba7c252bf5dabea8d5e98f7f1d60fc1 Mon Sep 17 00:00:00 2001 From: Geoffrey French Date: Mon, 1 Sep 2014 22:59:59 +0100 Subject: [PATCH] Docstring and comment improvements and fixes in plot_windowed_histogram. Readability improvement to skimage/io/__init__.py --- doc/examples/plot_windowed_histogram.py | 10 ++++++++-- skimage/io/__init__.py | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/doc/examples/plot_windowed_histogram.py b/doc/examples/plot_windowed_histogram.py index 73cf82a7..8e2c4384 100644 --- a/doc/examples/plot_windowed_histogram.py +++ b/doc/examples/plot_windowed_histogram.py @@ -12,6 +12,12 @@ It then computes a sliding window histogram of the complete image using surrounding each pixel in the image is compared to that of the single coin, with a similarity measure being computed and displayed. +The histogram of the single coin is computed using `numpy.histogram` on a +box shaped region surrounding the coin, while the sliding window histograms +are computed using a disc shaped structural element of a slightly different +size. This is done in aid of demonstrating that the technique still finds +similarity inspite of these differences. + To demonstrate the rotational invariance of the technique, the same test is performed on a version of the coins image rotated by 45 degrees. """ @@ -34,7 +40,7 @@ def windowed_histogram_similarity(image, selem, reference_hist, n_bins): px_histograms = rank.windowed_histogram(image, selem, n_bins=n_bins) # Reshape coin histogram to (1,1,N) for broadcast when we want to use it in - # arithmetic operations with the windowed histograms fro the image + # arithmetic operations with the windowed histograms from the image reference_hist = reference_hist.reshape((1,1) + reference_hist.shape) # Compute Chi squared distance metric: sum((X-Y)^2 / (X+Y)); @@ -47,7 +53,7 @@ def windowed_histogram_similarity(image, selem, reference_hist, n_bins): frac[denom==0] = 0 chi_sqr = np.sum(frac, axis=2) * 0.5 - # Generate a similarity measure. It needs to be low when distance is high. + # Generate a similarity measure. It needs to be low when distance is high # and high when distance is low; taking the reciprocal will do this. # Chi squared will always be >= 0, add small value to prevent divide by 0. similarity = 1 / (chi_sqr + 1.0e-4) diff --git a/skimage/io/__init__.py b/skimage/io/__init__.py index 8f3b9bca..85461216 100644 --- a/skimage/io/__init__.py +++ b/skimage/io/__init__.py @@ -40,7 +40,10 @@ def _update_doc(doc): info_table = [(p, plugin_info(p).get('description', 'no description')) for p in available_plugins if not p == 'test'] - name_length = max([len(n) for (n, _) in info_table]) if len(info_table) > 0 else 0 + if len(info_table) > 0: + name_length = max([len(n) for (n, _) in info_table]) + else: + name_length = 0 description_length = WRAP_LEN - 1 - name_length column_lengths = [name_length, description_length]