mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-01 12:50:48 +08:00
Replace assert statement with plot to show matches
This commit is contained in:
@@ -9,7 +9,7 @@ techniques to find instances of the "target image" in the "test image".
|
||||
|
||||
The output of ``match_template`` is an image where we can easily identify peaks
|
||||
by eye. Nevertheless, this example concludes with a simple peak extraction
|
||||
algorithm to quantify the locations of matches.
|
||||
algorithm to quantify the locations of matches (marked in red).
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
@@ -21,7 +21,10 @@ import matplotlib.pyplot as plt
|
||||
size = 100
|
||||
target = np.tri(size) + np.tri(size)[::-1]
|
||||
|
||||
plt.gray()
|
||||
#plt.gray()
|
||||
plt.figure(figsize=(9, 3))
|
||||
|
||||
plt.subplot(1, 3, 1)
|
||||
plt.imshow(target)
|
||||
plt.title("Target image")
|
||||
plt.axis('off')
|
||||
@@ -33,7 +36,7 @@ for x, y in target_positions:
|
||||
image[x:x+size, y:y+size] = target
|
||||
image += randn(400, 400)*2
|
||||
|
||||
plt.figure()
|
||||
plt.subplot(1, 3, 2)
|
||||
plt.imshow(image)
|
||||
plt.title("Test image")
|
||||
plt.axis('off')
|
||||
@@ -41,13 +44,11 @@ plt.axis('off')
|
||||
# Match the template.
|
||||
result = match_template(image, target, method='norm-corr')
|
||||
|
||||
plt.figure()
|
||||
plt.subplot(1, 3, 3)
|
||||
plt.imshow(result)
|
||||
plt.title("Result from ``match_template``")
|
||||
plt.title("Result from\n``match_template``")
|
||||
plt.axis('off')
|
||||
|
||||
plt.show()
|
||||
|
||||
# peak extraction algorithm.
|
||||
delta = 5
|
||||
found_positions = []
|
||||
@@ -64,6 +65,7 @@ for i in range(50):
|
||||
if len(found_positions) == len(target_positions):
|
||||
break
|
||||
|
||||
found_positions = np.sort(found_positions)
|
||||
assert np.all(found_positions == target_positions)
|
||||
|
||||
x_found, y_found = np.transpose(found_positions)
|
||||
plt.plot(x_found, y_found, 'ro')
|
||||
plt.autoscale(tight=True)
|
||||
plt.show()
|
||||
|
||||
Reference in New Issue
Block a user