From f19d05d62d73442692333bcd29b5d37f4ea0103b Mon Sep 17 00:00:00 2001 From: Pavol Debnar Date: Sun, 5 Mar 2023 21:05:21 +0100 Subject: [PATCH] added script to show lowest image (laplacian) variance from folder (dataset) --- src/imgvar.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/imgvar.py diff --git a/src/imgvar.py b/src/imgvar.py new file mode 100644 index 0000000..c7976da --- /dev/null +++ b/src/imgvar.py @@ -0,0 +1,38 @@ +import cv2 +import numpy as np +import os +from imutils import paths +import argparse + + +def variance_of_laplacian(image): + return cv2.Laplacian(image, cv2.CV_64F).var() + + +def minVarInFolder(path): + minVar = 90000 + minPath="" + files = os.listdir(path) + for p in files: + if ".png" in p and ".mask" not in p: + print(path+p) + img = cv2.imread(path+p) + cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + var = variance_of_laplacian(img) + if var < minVar: + minPath = path+p + minVar = var + return minPath,minVar + +ap = argparse.ArgumentParser() +ap.add_argument("-i", "--images", required=True, + help="path to image") +args = vars(ap.parse_args()) + +path = args["images"] + +#img = cv2.imread(path) +#cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) +#var = variance_of_laplacian(img) + +print(minVarInFolder(path)) \ No newline at end of file