Created
March 24, 2021 11:27
-
-
Save JackDesBwa/3f1bb745aa6de3a51f32c95932c988cf to your computer and use it in GitHub Desktop.
This script tries to find edges of a stereocard based on the algorithm proposed by Martin Schub at https://photo-3d.groups.io/g/main/message/125478
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
#!/usr/bin/env python3 | |
# This script tries to find edges of a stereocard based on the algorithm | |
# proposed by Martin Schub at https://photo-3d.groups.io/g/main/message/125478 | |
import sys | |
import numpy as np | |
from scipy.signal import argrelmax | |
from PIL import Image | |
import matplotlib.pyplot as plt | |
if len(sys.argv) != 2: | |
print('Usage: ' + sys.argv[0] + ' <image>') | |
sys.exit(1) | |
img = Image.open(sys.argv[1]).convert("L") | |
n = np.array(img) | |
h0 = np.abs(np.gradient(n.mean(axis=0))) | |
h1 = np.abs(np.gradient(n.mean(axis=1))) | |
m0 = h0.mean() | |
m1 = h1.mean() | |
max0 = argrelmax(np.maximum(5*m0, h0))[0] | |
max1 = argrelmax(np.maximum(5*m1, h1))[0] | |
print(max0, max1) | |
fig = plt.figure(figsize=(8, 8)) | |
gs = fig.add_gridspec(2, 2, width_ratios=(7, 2), height_ratios=(2, 7), | |
left=0.1, right=0.9, bottom=0.1, top=0.9, | |
wspace=0.05, hspace=0.05) | |
ax = fig.add_subplot(gs[1, 0]) | |
ax_histx = fig.add_subplot(gs[0, 0], sharex=ax) | |
ax_histy = fig.add_subplot(gs[1, 1], sharey=ax) | |
ax.imshow(img, cmap="gray") | |
ax_histx.plot(h0) | |
ax_histx.plot(max0, h0[max0], ' o') | |
histyy = np.arange(len(h1)) | |
ax_histy.plot(h1, histyy) | |
ax_histy.plot(h1[max1], max1, ' o') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment