From e6bda5accd0d9133e37eb1d9ed456c5191d8db19 Mon Sep 17 00:00:00 2001 From: Geoffrey French Date: Mon, 1 Sep 2014 23:41:03 +0100 Subject: [PATCH] Fix to skimage.filter.rank.windowed_histogram docstring. Better explanation of technique in plot_windowed_histogram example, along with (hopefully correct) citations. Relevant additions to release_dev.txt and CONTRIBUTORS.txt. --- CONTRIBUTORS.txt | 3 +++ doc/examples/plot_windowed_histogram.py | 30 +++++++++++++++++++------ doc/release/release_dev.txt | 1 + skimage/filter/rank/generic.py | 8 +++---- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 30f432f4..b0a82519 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -185,3 +185,6 @@ - Adam Feuer PIL Image import and export improvements + +- Geoffrey French + skimage.filters.rank.windowed_histogram and plot_windowed_histogram example. \ No newline at end of file diff --git a/doc/examples/plot_windowed_histogram.py b/doc/examples/plot_windowed_histogram.py index 8e2c4384..2cc77139 100644 --- a/doc/examples/plot_windowed_histogram.py +++ b/doc/examples/plot_windowed_histogram.py @@ -4,22 +4,38 @@ from __future__ import division Sliding window histogram ======================== -This example extracts a single coin from the `skimage.data.coins` image and -generates a histogram of its greyscale values. +Histogram matching can be used for object detection in images [1]_. +This example extracts a single coin from the `skimage.data.coins` image +and uses histogram matching to attempt to locate it within the original +image. -It then computes a sliding window histogram of the complete image using -`skimage.filter.rank.windowed_histogram`. The local histogram for the region -surrounding each pixel in the image is compared to that of the single coin, -with a similarity measure being computed and displayed. +First, a box-shaped region of the image containing the target coin is +extracted and a histogram of its greyscale values is computed. + +Next, for each pixel in the test image, a histogram of the greyscale values +in a region of the image surrounding the pixel is computed. +`skimage.filter.rank.windowed_histogram` is used for this task, as it +employs an efficient sliding window based algorithm that is able to compute +these histograms quickly [2]_. +The local histogram for the region 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. +similarity in spite 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. + +References +---------- +.. [1] Porikli, F. "Integral Histogram: A Fast Way to Extract Histograms + in Cartesian Spaces" CVPR, 2005. Vol. 1. IEEE, 2005 +.. [2] S.Perreault and P.Hebert. Median filtering in constant time. + Trans. Image Processing, 16(9):2389-2394, 2007. """ import numpy as np import matplotlib diff --git a/doc/release/release_dev.txt b/doc/release/release_dev.txt index cbeded27..77c8d102 100644 --- a/doc/release/release_dev.txt +++ b/doc/release/release_dev.txt @@ -20,6 +20,7 @@ Region Adjacency Graphs - Similarity RAGs (#1080) - Normalized Cut on RAGs (#1080) - RAG Drawing (#1087) +Sliding Windowed Histogram (#1127) Improvements ------------ diff --git a/skimage/filter/rank/generic.py b/skimage/filter/rank/generic.py index cec1624d..018d7c0b 100644 --- a/skimage/filter/rank/generic.py +++ b/skimage/filter/rank/generic.py @@ -895,10 +895,10 @@ def windowed_histogram(image, selem, out=None, mask=None, shift_x=False, shift_y out : 3-D array with float dtype of dimensions (H,W,N), where (H,W) are the dimensions of the input image and N is n_bins or image.max()+1 if no value is provided as a parameter. Effectively, each pixel - is an N-dimensional feature vector that is the histogram. - The sum of the elements in the feature vector will be 1, unless - no pixels in the window were covered by both selem and mask, in which - case all elements will be 0. + is a N-D feature vector that is the histogram. The sum of the + elements in the feature vector will be 1, unless no pixels in the + window were covered by both selem and mask, in which case all + elements will be 0. Examples --------