is the lower number the more sharper? import cv2 import numpy as np import os Directory…
- User
is the lower number the more sharper? import cv2 import numpy as np import os
Directory containing the images
folder_path = 'C:\ProgramData\Bystronic\VAF'
Function to calculate sharpness of an image
def calculate_sharpness(image): gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) sobelx = cv2.Sobel(gray_image, cv2.CV_64F, 1, 0, ksize=3) sobely = cv2.Sobel(gray_image, cv2.CV_64F, 0, 1, ksize=3) gradient_magnitude = np.sqrt(sobelx2 + sobely2) gradient_magnitude = cv2.normalize(gradient_magnitude, None, alpha=0, beta=1, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_32F) sharpness_metric = np.mean(gradient_magnitude) return sharpness_metric
Loop over every jpg image in the folder and calculate the sharpness
for filename in os.listdir(folder_path): if filename.lower().endswith('.jpg'): image_path = os.path.join(folder_path, filename) image = cv2.imread(image_path)
if image is None: print(f"The image at {image_path} could not be loaded.") continue sharpness_metric = calculate_sharpness(image) print(f"Sharpness of {filename}: {sharpness_metric}") - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.