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.

Revisions

  1. soravux created this gist Mar 5, 2017.
    23 changes: 23 additions & 0 deletions compute_smoothness.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    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])