TL;DR: What are the major key components (and how to calculate them) of an image to find the quality of an image and detect the problem in the image.
I have multiple problems with my data. A few of them being Blur, Extremely Dark, Extremely Bright Image, Camera Flash on Image, Uneven Brightness / Intensity.
I have found a few Solutions to the problems such as:
Blur: Finding the threshold of images using Laplace Variance and Fast Fourier Transformation
Camera Flash: By Seprating the background from foreground and finding the bright pixels and STD
Apart from these, I have written some functions to find some basic values about image. Please correct the methodology if wrong:
def overall_brightness(image:str, method:str='LAB', normalize:bool=True)->float:
'''
Find the brightness value of an image
args:
image: Path of Image
method: Using any of the colorspace (GRAY, LAB, HSV)
normalize: Whether to return the normalize value between 0-1
'''
image = cv2.imread(image)
if method == 'LAB':
L, A, B = cv2.split(cv2.cvtColor(image, cv2.COLOR_BGR2LAB))
if normalize:
L = L/np.max(L)
return np.mean(L)
elif method == 'HSV':
H, S, V = cv2.split(cv2.cvtColor(image, cv2.COLOR_BGR2HSV))
if normalize:
V = V/np.max(V)
return np.mean(V)
elif method == 'GRAY':
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
if normalize:
gray = gray / np.max(gray)
return np.mean(gray)
def overall_contrast(image, method:str='RMS')->float:
'''
Find the overall contrast
args:
image: Image string or Path of Image
method: Standard Deviation (RMS) method or the alternate channel method using (LAB or YUV) colorspace
'''
image = cv2.imread(image)
def alternate(channel:np.ndarray)->float:
'''
Alternate method to find the contrast
'''
min_ = np.min(channel)
max_ = np.max(channel)
contrast = (max_ - min_)/(max_ + min_)
return contrast
if method == 'RMS':
image = cv2.imread(image)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
return gray.std()
elif method == 'LAB':
L, A, B = cv2.split(cv2.cvtColor(image, cv2.COLOR_BGR2LAB))
return alternate(L)
elif method == 'YUV':
Y, U, V = cv2.split(cv2.cvtColor(image,cv2.COLOR_BGR2YUV))
return alternate(Y)
Some of the samples of Image are as: