2018-01-01 15:33:10 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import cv2
|
2018-01-01 20:49:00 +00:00
|
|
|
import numpy as np
|
2018-01-01 15:33:10 +00:00
|
|
|
from argparse import ArgumentParser
|
|
|
|
|
|
|
|
|
|
|
|
def laplacian_variance(image):
|
2018-01-01 20:49:00 +00:00
|
|
|
return cv2.Laplacian(image, cv2.CV_64F).var()
|
|
|
|
|
|
|
|
|
|
|
|
def fdibm(image):
|
|
|
|
F = np.fft.fft2(image)
|
|
|
|
Fcentered = np.fft.fftshift(F)
|
|
|
|
Fabs = np.abs(Fcentered)
|
|
|
|
Fmax = Fabs.max()
|
|
|
|
Th = np.count_nonzero(Fabs > Fmax/1000)
|
|
|
|
return Th / (F.shape[0] * F.shape[1])
|
2018-01-01 15:33:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
ap = ArgumentParser()
|
|
|
|
ap.add_argument('images', type=str, nargs='+', help='')
|
|
|
|
args = ap.parse_args()
|
|
|
|
|
|
|
|
image = cv2.imread(args.images[0])
|
2018-01-01 20:49:00 +00:00
|
|
|
grayscale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
2018-01-01 15:33:10 +00:00
|
|
|
|
2018-01-01 20:49:00 +00:00
|
|
|
print(fdibm(grayscale))
|