Skip to content

Instantly share code, notes, and snippets.

@soravux
Created March 5, 2017 22:07
Show Gist options
  • Save soravux/e3be6f526b643d2aff8c9c4426360bd4 to your computer and use it in GitHub Desktop.
Save soravux/e3be6f526b643d2aff8c9c4426360bd4 to your computer and use it in GitHub Desktop.
import sys
import csv
import numpy as np
from scipy.misc import imread
output_file = 'sharpnesses.txt'
imgs = sys.argv[1:]
with open(output_file, 'w', newline='') as csvfile:
writer = csv.writer(csvfile, quoting=csv.QUOTE_MINIMAL)
for img in imgs:
im = imread(img).astype('float32') / 255.
# We suppose a Latitude-Longitude format, so we remove the ground (bottom part)
im = im[:np.round(im.shape[0]*0.47).astype('int'),:,:]
im_grayscale = np.dot(im, [0.299, 0.587, 0.114])
im_fft = np.abs(np.fft.fft2(im_grayscale))
sharpness = np.sum(im_fft.ravel() > 5) / im_grayscale.size
writer.writerow([img, sharpness])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment