Created
September 29, 2015 06:49
-
-
Save yosemitebandit/ef5b1342c264937698b1 to your computer and use it in GitHub Desktop.
trying to find "corners" of puzzle pieces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from skimage import feature | |
from skimage import filters | |
from skimage import io | |
from skimage import measure | |
# Load the image. | |
source = 'a.jpg' | |
piece = io.imread(source, as_grey=True) | |
# Find edges with the Canny filter. | |
low = 0.0 | |
otsu = filters.threshold_otsu(piece, nbins=256) | |
sigma = 3 | |
canny_edges = feature.canny(piece, sigma=sigma, low_threshold=low, | |
high_threshold=otsu) | |
canny_edges = np.logical_not(canny_edges) | |
# Get corners. | |
dist = 20 | |
sensitivity = 0.05 | |
window = 13 | |
coords = feature.corner_peaks( | |
feature.corner_harris(canny_edges, k=sensitivity), min_distance=dist) | |
# Display results. | |
fig, (ax1, ax2, ax3) = plt.subplots(nrows=1, ncols=3, figsize=(20, 8)) | |
ax1.imshow(piece, cmap=plt.cm.gray) | |
ax1.axis('off') | |
ax2.imshow(canny_edges, cmap=plt.cm.gray) | |
ax2.axis('off') | |
ax2.set_title('Canny filter, $\sigma=%s$' % sigma, fontsize=20) | |
ax3.imshow(canny_edges, cmap=plt.cm.gray) | |
ax3.plot(coords[:, 1], coords[:, 0], '+r', markersize=12) | |
ax3.axis('off') | |
ax3.set_title('Harris corners', fontsize=20) | |
fig.subplots_adjust(wspace=0.02, hspace=0.02, top=0.9, | |
bottom=0.02, left=0.02, right=0.98) | |
plt.show() | |
fig.savefig('out.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment