text
stringlengths
1
93.6k
val += math.pow((pixel - mu), 2)
return val / len(x)
def _uicm(x):
R = x[:, :, 0].flatten()
G = x[:, :, 1].flatten()
B = x[:, :, 2].flatten()
RG = R - G
YB = ((R + G) / 2) - B
mu_a_RG = mu_a(RG)
mu_a_YB = mu_a(YB)
s_a_RG = s_a(RG, mu_a_RG)
s_a_YB = s_a(YB, mu_a_YB)
l = math.sqrt((math.pow(mu_a_RG, 2) + math.pow(mu_a_YB, 2)))
r = math.sqrt(s_a_RG + s_a_YB)
return (-0.0268 * l) + (0.1586 * r)
def sobel(x):
dx = ndimage.sobel(x, 0)
dy = ndimage.sobel(x, 1)
mag = np.hypot(dx, dy)
mag *= 255.0 / np.max(mag)
return mag
def eme(x, window_size):
"""
Enhancement measure estimation
x.shape[0] = height
x.shape[1] = width
"""
# if 4 blocks, then 2x2...etc.
k1 = x.shape[1] // window_size
k2 = x.shape[0] // window_size
# weight
w = 2. / (k1 * k2)
blocksize_x = window_size
blocksize_y = window_size
# make sure image is divisible by window_size - doesn't matter if we cut out some pixels
x = x[:blocksize_y * k2, :blocksize_x * k1]
val = 0
for l in range(k1):
for k in range(k2):
block = x[k * window_size:window_size * (k + 1), l * window_size:window_size * (l + 1)]
max_ = np.max(block)
min_ = np.min(block)
# bound checks, can't do log(0)
if min_ == 0.0:
val += 0
elif max_ == 0.0:
val += 0
else:
val += math.log(max_ / min_)
return w * val
def _uism(x):
"""
Underwater Image Sharpness Measure
"""
# get image channels
R = x[:, :, 0]
G = x[:, :, 1]
B = x[:, :, 2]
# first apply Sobel edge detector to each RGB component
Rs = sobel(R)
Gs = sobel(G)
Bs = sobel(B)
# multiply the edges detected for each channel by the channel itself
R_edge_map = np.multiply(Rs, R)
G_edge_map = np.multiply(Gs, G)
B_edge_map = np.multiply(Bs, B)
# get eme for each channel
r_eme = eme(R_edge_map, 8)
g_eme = eme(G_edge_map, 8)
b_eme = eme(B_edge_map, 8)
# coefficients
lambda_r = 0.299
lambda_g = 0.587
lambda_b = 0.144
return (lambda_r * r_eme) + (lambda_g * g_eme) + (lambda_b * b_eme)
def plip_g(x, mu=1026.0):
return mu - x
def plip_theta(g1, g2, k):