From 5f4dd4ed5f5fbc4c46ca95802dc5aa7ed221f5ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 28 Apr 2013 10:06:43 +0200 Subject: [PATCH] Fix print statement for Python 3 --- doc/examples/applications/plot_geometric.py | 8 +++++--- doc/examples/plot_gabor.py | 16 +++++++++------- doc/examples/plot_local_binary_pattern.py | 17 ++++++++++------- doc/examples/plot_polygon.py | 4 ++-- doc/examples/plot_segmentations.py | 1 + 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/doc/examples/applications/plot_geometric.py b/doc/examples/applications/plot_geometric.py index 337ecad7..141ef51f 100644 --- a/doc/examples/applications/plot_geometric.py +++ b/doc/examples/applications/plot_geometric.py @@ -7,6 +7,8 @@ In this example, we will see how to use geometric transformations in the context of image processing. """ +from __future__ import print_function + import math import numpy as np import matplotlib.pyplot as plt @@ -31,7 +33,7 @@ First we create a transformation using explicit parameters: tform = tf.SimilarityTransform(scale=1, rotation=math.pi / 2, translation=(0, 1)) -print tform._matrix +print(tform._matrix) """ Alternatively you can define a transformation by the transformation matrix @@ -49,8 +51,8 @@ systems: """ coord = [1, 0] -print tform2(coord) -print tform2.inverse(tform(coord)) +print(tform2(coord)) +print(tform2.inverse(tform(coord))) """ Image warping diff --git a/doc/examples/plot_gabor.py b/doc/examples/plot_gabor.py index c335016d..b3526943 100644 --- a/doc/examples/plot_gabor.py +++ b/doc/examples/plot_gabor.py @@ -12,6 +12,8 @@ kernels. The mean and variance of the filtered images are then used as features for classification, which is based on the least squared error for simplicity. """ +from __future__ import print_function + import matplotlib import matplotlib.pyplot as plt import numpy as np @@ -69,19 +71,19 @@ ref_feats[0, :, :] = compute_feats(brick, kernels) ref_feats[1, :, :] = compute_feats(grass, kernels) ref_feats[2, :, :] = compute_feats(wall, kernels) -print 'Rotated images matched against references using Gabor filter banks:' +print('Rotated images matched against references using Gabor filter banks:') -print 'original: brick, rotated: 30deg, match result:', +print('original: brick, rotated: 30deg, match result:', end='') feats = compute_feats(nd.rotate(brick, angle=190, reshape=False), kernels) -print image_names[match(feats, ref_feats)] +print(image_names[match(feats, ref_feats)]) -print 'original: brick, rotated: 70deg, match result:', +print('original: brick, rotated: 70deg, match result:', end='') feats = compute_feats(nd.rotate(brick, angle=70, reshape=False), kernels) -print image_names[match(feats, ref_feats)] +print(image_names[match(feats, ref_feats)]) -print 'original: grass, rotated: 145deg, match result:', +print('original: grass, rotated: 145deg, match result:', end='') feats = compute_feats(nd.rotate(grass, angle=145, reshape=False), kernels) -print image_names[match(feats, ref_feats)] +print(image_names[match(feats, ref_feats)]) def power(image, kernel): diff --git a/doc/examples/plot_local_binary_pattern.py b/doc/examples/plot_local_binary_pattern.py index d32a642f..5bb4359e 100644 --- a/doc/examples/plot_local_binary_pattern.py +++ b/doc/examples/plot_local_binary_pattern.py @@ -9,9 +9,12 @@ textures. For simplicity the histogram distributions are then tested against each other using the Kullback-Leibler-Divergence. """ +from __future__ import print_function + import numpy as np import matplotlib import matplotlib.pyplot as plt + from skimage.transform import rotate from skimage.feature import local_binary_pattern from skimage import data @@ -57,13 +60,13 @@ refs = { } # classify rotated textures -print 'Rotated images matched against references using LBP:' -print 'original: brick, rotated: 30deg, match result:', -print match(refs, rotate(brick, angle=30, resize=False)) -print 'original: brick, rotated: 70deg, match result:', -print match(refs, rotate(brick, angle=70, resize=False)) -print 'original: grass, rotated: 145deg, match result:', -print match(refs, rotate(grass, angle=145, resize=False)) +print('Rotated images matched against references using LBP:') +print('original: brick, rotated: 30deg, match result:', end='') +print(match(refs, rotate(brick, angle=30, resize=False))) +print('original: brick, rotated: 70deg, match result:', end='') +print(match(refs, rotate(brick, angle=70, resize=False))) +print('original: grass, rotated: 145deg, match result:', end='') +print(match(refs, rotate(grass, angle=145, resize=False))) # plot histograms of LBP of textures fig, ((ax1, ax2, ax3), (ax4, ax5, ax6)) = plt.subplots(nrows=2, ncols=3, diff --git a/doc/examples/plot_polygon.py b/doc/examples/plot_polygon.py index 078bb6cf..c605f12a 100644 --- a/doc/examples/plot_polygon.py +++ b/doc/examples/plot_polygon.py @@ -45,7 +45,7 @@ for _ in range(5): # approximate subdivided polygon with Douglas-Peucker algorithm appr_hand = approximate_polygon(new_hand, tolerance=0.02) -print "Number of coordinates:", len(hand), len(new_hand), len(appr_hand) +print("Number of coordinates:", len(hand), len(new_hand), len(appr_hand)) fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(9, 4)) @@ -70,7 +70,7 @@ for contour in find_contours(img, 0): ax2.plot(coords[:, 1], coords[:, 0], '-r', linewidth=2) coords2 = approximate_polygon(contour, tolerance=39.5) ax2.plot(coords2[:, 1], coords2[:, 0], '-g', linewidth=2) - print "Number of coordinates:", len(contour), len(coords), len(coords2) + print("Number of coordinates:", len(contour), len(coords), len(coords2)) ax2.axis((0, 800, 0, 800)) diff --git a/doc/examples/plot_segmentations.py b/doc/examples/plot_segmentations.py index 418a0903..55bb6082 100644 --- a/doc/examples/plot_segmentations.py +++ b/doc/examples/plot_segmentations.py @@ -58,6 +58,7 @@ of Quickshift, while ``n_segments`` chooses the number of centers for kmeans. Pascal Fua, and Sabine Suesstrunk, SLIC Superpixels Compared to State-of-the-art Superpixel Methods, TPAMI, May 2012. """ +from __future__ import print_function import matplotlib.pyplot as plt import numpy as np