WIP: Context-Adaptive Interpolator (CAI)

This commit is contained in:
Benjamin Loison 2024-03-21 13:00:51 +01:00
parent d43ff5777f
commit 739317fa63
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8
2 changed files with 18 additions and 7 deletions

View File

@ -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()

View File

@ -712,10 +712,10 @@ and considered here?</text>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">47.45419049 151.33026173 73.89024898 151.33026173</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">117.99112359 174.92225050 291.80041063 174.92225050</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">47.90409179 185.51778172 106.48776344 185.51778172</stroke>
<stroke tool="highlighter" color="#ffff007f" width="8.50000000" fill="128">79.84740241 197.12191732 180.26366418 197.12191732</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">79.84740241 197.12191732 180.26366418 197.12191732</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">91.25706084 205.78669895 91.25706084 233.33486307 257.24161221 233.33486307 257.24161221 205.78669895 91.25706084 205.78669895</stroke>
<stroke tool="highlighter" color="#ffff007f" width="8.50000000" fill="128">74.52609696 243.52963985 94.17824960 241.75708008</stroke>
<stroke tool="highlighter" color="#ffff007f" width="8.50000000" fill="128">124.26769196 243.44950274 264.89012007 243.44950274</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">74.52609696 243.52963985 94.17824960 241.75708008</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">124.26769196 243.44950274 264.89012007 243.44950274</stroke>
<stroke tool="highlighter" color="#ffff007f" width="8.50000000" fill="128">45.89230932 257.64400315 82.97993299 254.67293541</stroke>
<stroke tool="highlighter" color="#ffff007f" width="8.50000000" fill="128">122.83964251 257.92927196 169.60141510 257.92927196</stroke>
<stroke tool="highlighter" color="#ffff007f" width="8.50000000" fill="128">208.12297469 255.97655874 294.58478097 255.97655874</stroke>
@ -956,6 +956,8 @@ values, is it?</text>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">104.65768433 161.09030151 263.06051594 161.09030151</stroke>
<stroke tool="highlighter" color="#ffff007f" width="8.50000000" fill="128">240.77893066 150.39559937 297.05985950 150.39559937</stroke>
<stroke tool="highlighter" color="#ffff007f" width="8.50000000" fill="128">50.38613892 162.83441162 91.31531997 162.83441162</stroke>
<text font="Sans" size="11.00000000" x="320.14147949" y="16.07629395" color="#00c0ffff" ts="0" fn="">guess that no Wavelet coefficients are involved here
but only the image itself</text>
</layer>
</page>
<page width="612.00000000" height="792.00000000">