Fix print statement for Python 3

This commit is contained in:
Johannes Schönberger
2013-04-28 10:06:43 +02:00
parent eec4aff913
commit 5f4dd4ed5f
5 changed files with 27 additions and 19 deletions
+5 -3
View File
@@ -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
+9 -7
View File
@@ -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):
+10 -7
View File
@@ -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,
+2 -2
View File
@@ -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))
+1
View File
@@ -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