Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --kernel-size #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions blur_detection/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ def fix_image_size(image: numpy.array, expected_pixels: float = 2E6):
return cv2.resize(image, (0, 0), fx=ratio, fy=ratio)


def estimate_blur(image: numpy.array, threshold: int = 100):
def estimate_blur(image: numpy.array, threshold: int = 100, ksize: int = 1):
if image.ndim == 3:
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

blur_map = cv2.Laplacian(image, cv2.CV_64F)
blur_map = cv2.Laplacian(image, cv2.CV_64F, ksize=ksize)
score = numpy.var(blur_map)
return blur_map, score, bool(score < threshold)

Expand Down
3 changes: 2 additions & 1 deletion process.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def parse_args():
parser.add_argument('-s', '--save-path', type=str, default=None, help='path to save output')

parser.add_argument('-t', '--threshold', type=float, default=100.0, help='blurry threshold')
parser.add_argument('-k', '--kernel-size', type=int, default=1, help='kernel size')
parser.add_argument('-f', '--variable-size', action='store_true', help='fix the image size')

parser.add_argument('-v', '--verbose', action='store_true', help='set logging level to debug')
Expand Down Expand Up @@ -74,7 +75,7 @@ def find_images(image_paths, img_extensions=['.jpg', '.png', '.jpeg']):
else:
logging.warning('not normalizing image size for consistent scoring!')

blur_map, score, blurry = estimate_blur(image, threshold=args.threshold)
blur_map, score, blurry = estimate_blur(image, threshold=args.threshold, ksize=args.kernel_size)

logging.info(f'image_path: {image_path} score: {score} blurry: {blurry}')
results.append({'input_path': str(image_path), 'score': score, 'blurry': blurry})
Expand Down