diff --git a/doc/examples/plot_adapt_rgb.py b/doc/examples/plot_adapt_rgb.py index f6aca943..d267cc4a 100644 --- a/doc/examples/plot_adapt_rgb.py +++ b/doc/examples/plot_adapt_rgb.py @@ -49,10 +49,11 @@ image = data.astronaut() fig = plt.figure(figsize=(14, 7)) ax_each = fig.add_subplot(121) -ax_hsv = fig.add_subplot(122) +ax_hsv = fig.add_subplot(122) -# We use 1 - sobel_each(image) but this will not work if image is not normalized -ax_each.imshow( rescale_intensity(1-sobel_each(image))) +# We use 1 - sobel_each(image) +# but this will not work if image is not normalized +ax_each.imshow(rescale_intensity(1 - sobel_each(image))) ax_each.set_xticks([]), ax_each.set_yticks([]) ax_each.set_title("Sobel filter computed\n on individual RGB channels") @@ -108,8 +109,9 @@ def sobel_gray(image): fig = plt.figure(figsize=(7, 7)) ax = fig.add_subplot(111) -# We use 1 - sobel_gray(image) but this will not work if image is not normalized -ax.imshow( rescale_intensity(1 - sobel_gray(image)), cmap=plt.cm.gray) +# We use 1 - sobel_gray(image) +# but this will not work if image is not normalized +ax.imshow(rescale_intensity(1 - sobel_gray(image)), cmap=plt.cm.gray) ax.set_xticks([]), ax.set_yticks([]) ax.set_title("Sobel filter computed\n on the converted grayscale image") diff --git a/doc/examples/plot_canny.py b/doc/examples/plot_canny.py index f01e6e2d..7d770787 100644 --- a/doc/examples/plot_canny.py +++ b/doc/examples/plot_canny.py @@ -53,4 +53,3 @@ fig.subplots_adjust(wspace=0.02, hspace=0.02, top=0.9, bottom=0.02, left=0.02, right=0.98) plt.show() - diff --git a/doc/examples/plot_circular_elliptical_hough_transform.py b/doc/examples/plot_circular_elliptical_hough_transform.py index 1d36e1b8..684ad30b 100755 --- a/doc/examples/plot_circular_elliptical_hough_transform.py +++ b/doc/examples/plot_circular_elliptical_hough_transform.py @@ -116,7 +116,7 @@ from skimage.draw import ellipse_perimeter image_rgb = data.coffee()[0:220, 160:420] image_gray = color.rgb2gray(image_rgb) edges = canny(image_gray, sigma=2.0, - low_threshold=0.55, high_threshold=0.8) + low_threshold=0.55, high_threshold=0.8) # Perform a Hough Transform # The accuracy corresponds to the bin size of a major axis. diff --git a/doc/examples/plot_convex_hull.py b/doc/examples/plot_convex_hull.py index d792138e..be50f541 100644 --- a/doc/examples/plot_convex_hull.py +++ b/doc/examples/plot_convex_hull.py @@ -32,12 +32,12 @@ original_image = np.copy(image) chull = convex_hull_image(image) image[chull] += 1 # image is now: -#[[ 0. 0. 0. 0. 0. 0. 0. 0. 0.] -# [ 0. 0. 0. 0. 2. 0. 0. 0. 0.] -# [ 0. 0. 0. 2. 1. 2. 0. 0. 0.] -# [ 0. 0. 2. 1. 1. 1. 2. 0. 0.] -# [ 0. 2. 1. 1. 1. 1. 1. 2. 0.] -# [ 0. 0. 0. 0. 0. 0. 0. 0. 0.]] +# [[ 0. 0. 0. 0. 0. 0. 0. 0. 0.] +# [ 0. 0. 0. 0. 2. 0. 0. 0. 0.] +# [ 0. 0. 0. 2. 1. 2. 0. 0. 0.] +# [ 0. 0. 2. 1. 1. 1. 2. 0. 0.] +# [ 0. 2. 1. 1. 1. 1. 1. 2. 0.] +# [ 0. 0. 0. 0. 0. 0. 0. 0. 0.]] fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 6)) diff --git a/doc/examples/plot_gabor.py b/doc/examples/plot_gabor.py index 36d20836..0ecc8468 100644 --- a/doc/examples/plot_gabor.py +++ b/doc/examples/plot_gabor.py @@ -4,8 +4,8 @@ Gabor filter banks for texture classification ============================================= In this example, we will see how to classify textures based on Gabor filter -banks. Frequency and orientation representations of the Gabor filter are similar -to those of the human visual system. +banks. Frequency and orientation representations of the Gabor filter are +similar to those of the human visual system. The images are filtered using the real parts of various different Gabor filter kernels. The mean and variance of the filtered images are then used as features diff --git a/doc/examples/plot_gabors_from_astronaut.py b/doc/examples/plot_gabors_from_astronaut.py index d7edfa51..ed429203 100644 --- a/doc/examples/plot_gabors_from_astronaut.py +++ b/doc/examples/plot_gabors_from_astronaut.py @@ -11,8 +11,8 @@ Please find below a short answer ;-) This simple example shows how to get Gabor-like filters [1]_ using just a simple image. In our example, we use a photograph of the astronaut Eileen -Collins. Gabor filters are good approximations of the "Simple Cells" [2]_ -receptive fields [3]_ found in the mammalian primary visual cortex (V1) +Collins. Gabor filters are good approximations of the "Simple Cells" [2]_ +receptive fields [3]_ found in the mammalian primary visual cortex (V1) (for details, see e.g. the Nobel-prize winning work of Hubel & Wiesel done in the 60s [4]_ [5]_). diff --git a/doc/examples/plot_holes_and_peaks.py b/doc/examples/plot_holes_and_peaks.py index 791c69ee..90af1cbe 100644 --- a/doc/examples/plot_holes_and_peaks.py +++ b/doc/examples/plot_holes_and_peaks.py @@ -21,6 +21,7 @@ image = data.moon() # Rescale image intensity so that we can see dim features. image = rescale_intensity(image, in_range=(50, 200)) + # convenience function for plotting images def imshow(image, title, **kwargs): fig, ax = plt.subplots(figsize=(5, 4)) @@ -28,6 +29,7 @@ def imshow(image, title, **kwargs): ax.axis('off') ax.set_title(title) + imshow(image, 'Original image') """ @@ -50,7 +52,7 @@ mask = image filled = reconstruction(seed, mask, method='erosion') -imshow(filled, 'after filling holes',vmin=image.min(), vmax=image.max()) +imshow(filled, 'after filling holes', vmin=image.min(), vmax=image.max()) """ .. image:: PLOT2RST.current_figure diff --git a/doc/examples/plot_line_hough_transform.py b/doc/examples/plot_line_hough_transform.py index 4293c409..7ee3f1f7 100644 --- a/doc/examples/plot_line_hough_transform.py +++ b/doc/examples/plot_line_hough_transform.py @@ -16,16 +16,16 @@ Algorithm overview Usually, lines are parameterised as :math:`y = mx + c`, with a gradient :math:`m` and y-intercept `c`. However, this would mean that :math:`m` goes to infinity for vertical lines. Instead, we therefore construct a segment -perpendicular to the line, leading to the origin. The line is represented by the -length of that segment, :math:`r`, and the angle it makes with the x-axis, +perpendicular to the line, leading to the origin. The line is represented by +the length of that segment, :math:`r`, and the angle it makes with the x-axis, :math:`\theta`. The Hough transform constructs a histogram array representing the parameter -space (i.e., an :math:`M \times N` matrix, for :math:`M` different values of the -radius and :math:`N` different values of :math:`\theta`). For each parameter -combination, :math:`r` and :math:`\theta`, we then find the number of non-zero -pixels in the input image that would fall close to the corresponding line, and -increment the array at position :math:`(r, \theta)` appropriately. +space (i.e., an :math:`M \times N` matrix, for :math:`M` different values of +the radius and :math:`N` different values of :math:`\theta`). For each +parameter combination, :math:`r` and :math:`\theta`, we then find the number of +non-zero pixels in the input image that would fall close to the corresponding +line, and increment the array at position :math:`(r, \theta)` appropriately. We can think of each non-zero pixel "voting" for potential line candidates. The local maxima in the resulting histogram indicates the parameters of the most @@ -35,13 +35,13 @@ corresponding to the normal vector angles of each line. Another approach is the Progressive Probabilistic Hough Transform [1]_. It is based on the assumption that using a random subset of voting points give a good approximation to the actual result, and that lines can be extracted during the -voting process by walking along connected components. This returns the beginning -and end of each line segment, which is useful. +voting process by walking along connected components. This returns the +beginning and end of each line segment, which is useful. The function `probabilistic_hough` has three parameters: a general threshold -that is applied to the Hough accumulator, a minimum line length and the line gap -that influences line merging. In the example below, we find lines longer than 10 -with a gap less than 3 pixels. +that is applied to the Hough accumulator, a minimum line length and the line +gap that influences line merging. In the example below, we find lines longer +than 10 with a gap less than 3 pixels. References ---------- @@ -84,9 +84,9 @@ ax[0].set_title('Input image') ax[0].axis('image') ax[1].imshow(np.log(1 + h), - extent=[np.rad2deg(theta[-1]), np.rad2deg(theta[0]), - d[-1], d[0]], - cmap=plt.cm.gray, aspect=1/1.5) + extent=[np.rad2deg(theta[-1]), np.rad2deg(theta[0]), + d[-1], d[0]], + cmap=plt.cm.gray, aspect=1/1.5) ax[1].set_title('Hough transform') ax[1].set_xlabel('Angles (degrees)') ax[1].set_ylabel('Distance (pixels)') @@ -106,7 +106,8 @@ ax[2].axis('image') image = data.camera() edges = canny(image, 2, 1, 25) -lines = probabilistic_hough_line(edges, threshold=10, line_length=5, line_gap=3) +lines = probabilistic_hough_line(edges, threshold=10, line_length=5, + line_gap=3) fig2, ax = plt.subplots(1, 3, figsize=(8, 3)) diff --git a/doc/examples/plot_local_binary_pattern.py b/doc/examples/plot_local_binary_pattern.py index c0169cc1..f35c9f50 100644 --- a/doc/examples/plot_local_binary_pattern.py +++ b/doc/examples/plot_local_binary_pattern.py @@ -108,11 +108,13 @@ def highlight_bars(bars, indexes): image = data.load('brick.png') lbp = local_binary_pattern(image, n_points, radius, METHOD) + def hist(ax, lbp): n_bins = lbp.max() + 1 return ax.hist(lbp.ravel(), normed=True, bins=n_bins, range=(0, n_bins), facecolor='0.5') + # plot histograms of LBP of textures fig, (ax_img, ax_hist) = plt.subplots(nrows=2, ncols=3, figsize=(9, 6)) plt.gray() diff --git a/doc/examples/plot_local_equalize.py b/doc/examples/plot_local_equalize.py index 507921b7..cce8fa42 100644 --- a/doc/examples/plot_local_equalize.py +++ b/doc/examples/plot_local_equalize.py @@ -4,8 +4,8 @@ Local Histogram Equalization ============================ This examples enhances an image with low contrast, using a method called *local -histogram equalization*, which spreads out the most frequent intensity values in -an image. +histogram equalization*, which spreads out the most frequent intensity values +in an image. The equalized image [1]_ has a roughly linear cumulative distribution function for each pixel neighborhood. diff --git a/doc/examples/plot_local_otsu.py b/doc/examples/plot_local_otsu.py index 655e9328..210d5c03 100644 --- a/doc/examples/plot_local_otsu.py +++ b/doc/examples/plot_local_otsu.py @@ -5,8 +5,8 @@ Local Otsu Threshold This example shows how Otsu's threshold [1]_ method can be applied locally. For each pixel, an "optimal" threshold is determined by maximizing the variance -between two classes of pixels of the local neighborhood defined by a structuring -element. +between two classes of pixels of the local neighborhood defined by a +structuring element. The example compares the local threshold with the global threshold. @@ -41,12 +41,12 @@ fig, ax = plt.subplots(2, 2, figsize=(8, 5)) ax1, ax2, ax3, ax4 = ax.ravel() fig.colorbar(ax1.imshow(img, cmap=plt.cm.gray), - ax=ax1, orientation='horizontal') + ax=ax1, orientation='horizontal') ax1.set_title('Original') ax1.axis('off') fig.colorbar(ax2.imshow(local_otsu, cmap=plt.cm.gray), - ax=ax2, orientation='horizontal') + ax=ax2, orientation='horizontal') ax2.set_title('Local Otsu (radius=%d)' % radius) ax2.axis('off') diff --git a/doc/examples/plot_marked_watershed.py b/doc/examples/plot_marked_watershed.py index 3315595a..8180f982 100644 --- a/doc/examples/plot_marked_watershed.py +++ b/doc/examples/plot_marked_watershed.py @@ -8,7 +8,7 @@ is, for separating different objects in an image. Here a marker image is built from the region of low gradient inside the image. In a gradient image, the areas of high values provide barriers that help to -segment the image. +segment the image. Using markers on the lower values will ensure that the segmented objects are found. @@ -32,7 +32,7 @@ image = img_as_ubyte(data.camera()) # denoise image denoised = rank.median(image, disk(2)) -# find continuous region (low gradient - +# find continuous region (low gradient - # where less than 10 for this image) --> markers # disk(5) is used here to get a more smooth image markers = rank.gradient(denoised, disk(5)) < 10 @@ -61,5 +61,6 @@ ax3.set_title("Segmented") for ax in axes: ax.axis('off') -fig.subplots_adjust(hspace=0.01, wspace=0.01, top=0.9, bottom=0, left=0, right=1) +fig.subplots_adjust(hspace=0.01, wspace=0.01, top=0.9, bottom=0, + left=0, right=1) plt.show() diff --git a/doc/examples/plot_matching.py b/doc/examples/plot_matching.py index 314c45d2..0b09662d 100644 --- a/doc/examples/plot_matching.py +++ b/doc/examples/plot_matching.py @@ -39,8 +39,9 @@ from skimage.measure import ransac checkerboard = img_as_float(data.checkerboard()) img_orig = np.zeros(list(checkerboard.shape) + [3]) img_orig[..., 0] = checkerboard -gradient_r, gradient_c = np.mgrid[0:img_orig.shape[0], - 0:img_orig.shape[1]] / float(img_orig.shape[0]) +gradient_r, gradient_c = (np.mgrid[0:img_orig.shape[0], + 0:img_orig.shape[1]] + / float(img_orig.shape[0])) img_orig[..., 1] = gradient_r img_orig[..., 2] = gradient_c img_orig = rescale_intensity(img_orig) @@ -72,7 +73,7 @@ def gaussian_weights(window_ext, sigma=1): def match_corner(coord, window_ext=5): - r, c = np.round(coord).astype(np.intp) + r, c = np.round(coord).astype(np.intp) window_orig = img_orig[r-window_ext:r+window_ext+1, c-window_ext:c+window_ext+1, :] diff --git a/doc/examples/plot_phase_unwrap.py b/doc/examples/plot_phase_unwrap.py index f2bbbc4c..edb061aa 100644 --- a/doc/examples/plot_phase_unwrap.py +++ b/doc/examples/plot_phase_unwrap.py @@ -32,7 +32,8 @@ ax1, ax2, ax3, ax4 = ax.ravel() fig.colorbar(ax1.imshow(image, cmap='gray', vmin=0, vmax=4 * np.pi), ax=ax1) ax1.set_title('Original') -fig.colorbar(ax2.imshow(image_wrapped, cmap='gray', vmin=-np.pi, vmax=np.pi), ax=ax2) +fig.colorbar(ax2.imshow(image_wrapped, cmap='gray', vmin=-np.pi, vmax=np.pi), + ax=ax2) ax2.set_title('Wrapped phase') fig.colorbar(ax3.imshow(image_unwrapped, cmap='gray'), ax=ax3) @@ -71,11 +72,11 @@ fig.colorbar(ax1.imshow(np.ma.array(image, mask=mask), cmap='jet'), ax=ax1) ax1.set_title('Original') fig.colorbar(ax2.imshow(image_wrapped, cmap='jet', vmin=-np.pi, vmax=np.pi), - ax=ax2) + ax=ax2) ax2.set_title('Wrapped phase') fig.colorbar(ax3.imshow(image_unwrapped_no_wrap_around, cmap='jet'), - ax=ax3) + ax=ax3) ax3.set_title('Unwrapped without wrap_around') fig.colorbar(ax4.imshow(image_unwrapped_wrap_around, cmap='jet'), ax=ax4) diff --git a/doc/examples/plot_polygon.py b/doc/examples/plot_polygon.py index 821c4558..98a81359 100644 --- a/doc/examples/plot_polygon.py +++ b/doc/examples/plot_polygon.py @@ -18,26 +18,26 @@ from skimage.measure import find_contours, approximate_polygon, \ hand = np.array([[1.64516129, 1.16145833], - [1.64516129, 1.59375 ], - [1.35080645, 1.921875 ], - [1.375 , 2.18229167], - [1.68548387, 1.9375 ], + [1.64516129, 1.59375], + [1.35080645, 1.921875], + [1.375, 2.18229167], + [1.68548387, 1.9375], [1.60887097, 2.55208333], [1.68548387, 2.69791667], [1.76209677, 2.56770833], [1.83064516, 1.97395833], - [1.89516129, 2.75 ], - [1.9516129 , 2.84895833], + [1.89516129, 2.75], + [1.9516129, 2.84895833], [2.01209677, 2.76041667], [1.99193548, 1.99479167], [2.11290323, 2.63020833], - [2.2016129 , 2.734375 ], + [2.2016129, 2.734375], [2.25403226, 2.60416667], - [2.14919355, 1.953125 ], + [2.14919355, 1.953125], [2.30645161, 2.36979167], [2.39112903, 2.36979167], - [2.41532258, 2.1875 ], - [2.1733871 , 1.703125 ], + [2.41532258, 2.1875], + [2.1733871, 1.703125], [2.07782258, 1.16666667]]) # subdivide polygon using 2nd degree B-Splines diff --git a/doc/examples/plot_pyramid.py b/doc/examples/plot_pyramid.py index b1e22022..eba42206 100644 --- a/doc/examples/plot_pyramid.py +++ b/doc/examples/plot_pyramid.py @@ -5,8 +5,8 @@ Build image pyramids The `pyramid_gaussian` function takes an image and yields successive images shrunk by a constant scale factor. Image pyramids are often used, e.g., to -implement algorithms for denoising, texture discrimination, and scale- invariant -detection. +implement algorithms for denoising, texture discrimination, and scale- +invariant detection. """ import numpy as np diff --git a/doc/examples/plot_regionprops.py b/doc/examples/plot_regionprops.py index c4a8fc29..f9caede1 100644 --- a/doc/examples/plot_regionprops.py +++ b/doc/examples/plot_regionprops.py @@ -18,7 +18,7 @@ from skimage.transform import rotate image = np.zeros((600, 600)) rr, cc = ellipse(300, 350, 100, 220) -image[rr,cc] = 1 +image[rr, cc] = 1 image = rotate(image, angle=15, order=0) diff --git a/doc/examples/plot_segmentations.py b/doc/examples/plot_segmentations.py index d62d12a9..7f0c5752 100644 --- a/doc/examples/plot_segmentations.py +++ b/doc/examples/plot_segmentations.py @@ -46,13 +46,15 @@ color-space and distance in image-space, given by ``ratio``. SLIC - K-Means based image segmentation --------------------------------------- -This algorithm simply performs K-means in the 5d space of color information -and image location and is therefore closely related to quickshift. As the + +This algorithm simply performs K-means in the 5d space of color information and +image location and is therefore closely related to quickshift. As the clustering method is simpler, it is very efficient. It is essential for this algorithm to work in Lab color space to obtain good results. The algorithm quickly gained momentum and is now widely used. See [3] for details. The -``compactness`` parameter trades off color-similarity and proximity, as in the case -of Quickshift, while ``n_segments`` chooses the number of centers for kmeans. +``compactness`` parameter trades off color-similarity and proximity, as in the +case of Quickshift, while ``n_segments`` chooses the number of centers for +kmeans. .. [3] Radhakrishna Achanta, Appu Shaji, Kevin Smith, Aurelien Lucchi, Pascal Fua, and Sabine Suesstrunk, SLIC Superpixels Compared to diff --git a/doc/examples/plot_ssim.py b/doc/examples/plot_ssim.py index 319c72fe..1592136b 100644 --- a/doc/examples/plot_ssim.py +++ b/doc/examples/plot_ssim.py @@ -51,10 +51,12 @@ mse_none = mse(img, img) ssim_none = ssim(img, img, dynamic_range=img.max() - img.min()) mse_noise = mse(img, img_noise) -ssim_noise = ssim(img, img_noise, dynamic_range=img_const.max() - img_const.min()) +ssim_noise = ssim(img, img_noise, + dynamic_range=img_const.max() - img_const.min()) mse_const = mse(img, img_const) -ssim_const = ssim(img, img_const, dynamic_range=img_noise.max() - img_noise.min()) +ssim_const = ssim(img, img_const, + dynamic_range=img_noise.max() - img_noise.min()) label = 'MSE: %2.f, SSIM: %.2f' diff --git a/doc/examples/plot_tinting_grayscale_images.py b/doc/examples/plot_tinting_grayscale_images.py index f4dde6fd..008ed065 100644 --- a/doc/examples/plot_tinting_grayscale_images.py +++ b/doc/examples/plot_tinting_grayscale_images.py @@ -82,6 +82,7 @@ Now, let's create a little utility function to take an RGB image and: """ + def colorize(image, hue, saturation=1): """ Add color of the given hue to an RGB image. @@ -92,6 +93,7 @@ def colorize(image, hue, saturation=1): hsv[:, :, 0] = hue return color.hsv2rgb(hsv) + """ Notice that we need to bump up the saturation; images with zero saturation are grayscale, so we need to a non-zero value to actually see the color we've set. @@ -150,6 +152,7 @@ plt.show() .. image:: PLOT2RST.current_figure For coloring multiple regions, you may also be interested in -`skimage.color.label2rgb `_. +`skimage.color.label2rgb +`_. """