Spaces:
Running
Running
import os | |
import numpy as np | |
import cv2 | |
from skimage.restoration import estimate_sigma | |
import logging | |
def brightness_check(image,thresh=0.37): | |
L,A,B = cv2.split(cv2.cvtColor(image,cv2.COLOR_BGR2LAB)) | |
norm_L = L/np.max(L) | |
L_mean = np.mean(norm_L) | |
if L_mean > thresh: | |
return "Image is bright enough to process object detection and segmentation task" | |
else: | |
return "image is not bright enough to process object detection and segmentation task " | |
def gaussian_noise_check(img,threshould=250): | |
# compute the Laplacian of the image and then return the focus | |
# measure, which is simply the variance of the Laplacian | |
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) | |
laplacian_value = cv2.Laplacian(gray, cv2.CV_64F).var() | |
logging.info(laplacian_value) | |
if laplacian_value <= threshould: | |
return "There is Blur/Gaussian noise in the image" | |
elif laplacian_value <= 3*threshould: | |
return " There is Blur/Gaussian noise in few regions of the image." | |
elif laplacian_value >= 3*threshould: | |
return "Image has high sharpness , no need to process futher." | |
def snr_check(image): | |
snr_text = None | |
snr_value = estimate_sigma(cv2.cvtColor(image,cv2.COLOR_RGB2GRAY), average_sigmas=False) | |
logging.info(snr_value) | |
if snr_value > 1 : | |
snr_text = "SnR is greater than 1 meaning : image has less noise " | |
else: | |
snr_text = "SnR is less than 1 Meaning : image has noise , it needs to be processed . " | |
return snr_text | |