Merge branch 'feature/focus-detection' into dev
This commit is contained in:
commit
08b0f76933
2 changed files with 49 additions and 0 deletions
0
src/focusdetection/__init__.py
Normal file
0
src/focusdetection/__init__.py
Normal file
49
src/focusdetection/focusdetection.py
Normal file
49
src/focusdetection/focusdetection.py
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
from os.path import abspath
|
||||||
|
import cv2
|
||||||
|
import pandas
|
||||||
|
import numpy
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
#parser = argparse.ArgumentParser()
|
||||||
|
#parser.add_argument('images', type=os.path.abspath, metavar='image-location', nargs='+',
|
||||||
|
# help='path(s) to input image(s)')
|
||||||
|
#args = vars(parser.parse_args())
|
||||||
|
#
|
||||||
|
#imagePaths = args["images"]
|
||||||
|
|
||||||
|
def laplacian_variance(image):
|
||||||
|
return cv2.Laplacian(image, cv2.CV_64F).var()
|
||||||
|
|
||||||
|
def fast_fourier(image, size=60, thresh=10):
|
||||||
|
(h, w) = image.shape
|
||||||
|
(xCenter, yCenter) = (int(w/ 2), int(h/2))
|
||||||
|
fft = numpy.fft.fft2(image)
|
||||||
|
fftShift = numpy.fft.fftshift(fft)
|
||||||
|
fftShift[yCenter -size:yCenter + size, xCenter - size:xCenter + size] = 0
|
||||||
|
fftShift = numpy.fft.ifftshift(fftShift)
|
||||||
|
recon = numpy.fft.ifft2(fftShift)
|
||||||
|
magnitude = 20 * numpy.log(numpy.abs(recon))
|
||||||
|
mean = numpy.mean(magnitude)
|
||||||
|
return (mean, mean <= thresh)
|
||||||
|
|
||||||
|
def laplacian_variance_method():
|
||||||
|
column_labels = ['Path', 'Laplacian Variance']
|
||||||
|
df = pandas.DataFrame(columns = column_labels)
|
||||||
|
index = 0
|
||||||
|
|
||||||
|
for imagePath in imagePaths:
|
||||||
|
index += 1
|
||||||
|
if index % 10 == 0:
|
||||||
|
print("Processing image " + str(index) + "/" + str(len(imagePaths)))
|
||||||
|
image = cv2.imread(imagePath)
|
||||||
|
image_grey = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
||||||
|
var = laplacian_variance(image_grey)
|
||||||
|
df.loc[len(df.index)] = [imagePath, var]
|
||||||
|
|
||||||
|
mean_lap_var = df["Laplacian Variance"].mean()
|
||||||
|
df_not_blurred = df[df['Laplacian Variance']>mean_lap_var]
|
||||||
|
df_blurred = df[df['Laplacian Variance']<=mean_lap_var]
|
||||||
|
|
||||||
|
#def fast_fourier_transform_method():
|
Reference in a new issue