WIP: Context-Adaptive Interpolator (CAI)
This commit is contained in:
@@ -43,19 +43,28 @@ for m in range(1, IImage.size[0] - 1):
|
||||
r[m - 1, n - 1] = round(newPixel)
|
||||
|
||||
Q = 3
|
||||
# $\sigma_0^2$ is the noise variance.
|
||||
sigma_0 = sqrt(9)
|
||||
|
||||
def wienerFilter():
|
||||
# Wiener filter.
|
||||
def h_w(i, j):
|
||||
# Equation (7)
|
||||
hw[i, j] = h[i, j] * sigma(i, j) / (sigma(i, j) + sigma_0 ** 2)
|
||||
return h[i, j] * sigma(i, j) / (sigma(i, j) + sigma_0 ** 2)
|
||||
|
||||
# Minimum of the considered variances.
|
||||
def sigma(i, j):
|
||||
# Equation (9)
|
||||
return sigma_q(i, j, Q)
|
||||
|
||||
def getPixelIndexesAround(i, numberOfPixelsInEachDirection):
|
||||
return range(i - numberOfPixelsInEachDirection, i + numberOfPixelsInEachDirection)
|
||||
|
||||
# Local variance obtained by Maximum A Posteriori (MAP).
|
||||
def sigma_q(i, j, q):
|
||||
# Equation (8)
|
||||
# TODO:
|
||||
pass
|
||||
numberOfPixelsInEachDirection = (q - 1) // 2
|
||||
B_q = [(x, z) for x in getPixelIndexesAround(i, numberOfPixelsInEachDirection) for z in getPixelIndexesAround(j, numberOfPixelsInEachDirection)]
|
||||
return max(0, (1 / q ** 2) * sum([h[x, z] ** 2 - sigma_0 ** 2 for (x, z) in B_q]))
|
||||
|
||||
# Why need to rotate the image? See #14.
|
||||
rImage.rotate(-90).show()
|
Reference in New Issue
Block a user