Correct getPixelIndexesAround
missing one pixel
This commit is contained in:
@@ -54,27 +54,31 @@ h_wImage = Image.new(MODE, (rImage.size[0], rImage.size[1]))
|
||||
h_wImagePixels = h_wImage.load()
|
||||
|
||||
# Wiener filter.
|
||||
def h_w(h, i, j):
|
||||
def h_w(hImage, h, i, j):
|
||||
# Equation (7)
|
||||
return h[i, j] * sigma(h, i, j) / (sigma(h, i, j) + sigma_0 ** 2)
|
||||
return h[i, j] * sigma(hImage, h, i, j) / (sigma(hImage, h, i, j) + sigma_0 ** 2)
|
||||
|
||||
# Minimum of the considered variances.
|
||||
def sigma(h, i, j):
|
||||
def sigma(hImage, h, i, j):
|
||||
# Equation (9)
|
||||
return sigma_q(h, i, j, Q)
|
||||
return sigma_q(hImage, h, i, j, Q)
|
||||
|
||||
def getPixelIndexesAround(i, numberOfPixelsInEachDirection):
|
||||
return range(i - numberOfPixelsInEachDirection, i + numberOfPixelsInEachDirection)
|
||||
return range(i - numberOfPixelsInEachDirection, i + numberOfPixelsInEachDirection + 1)
|
||||
|
||||
# Expand image with border pixels.
|
||||
def getPixelWithinImage(z, upperBound):
|
||||
return max(min(z, upperBound - 1), 0)
|
||||
|
||||
# Local variance obtained by Maximum A Posteriori (MAP).
|
||||
def sigma_q(h, i, j, q):
|
||||
def sigma_q(hImage, h, i, j, q):
|
||||
# Equation (8)
|
||||
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]))
|
||||
return max(0, (1 / q ** 2) * sum([h[getPixelWithinImage(x, hImage.size[0]), getPixelWithinImage(z, hImage.size[1])] ** 2 - sigma_0 ** 2 for (x, z) in B_q]))
|
||||
|
||||
for i in tqdm(range(rImage.size[0])):
|
||||
for j in range(rImage.size[1]):
|
||||
h_wImagePixels[i, j] = round(h_w(r, i, j))
|
||||
h_wImagePixels[i, j] = round(h_w(rImage, r, i, j))
|
||||
|
||||
h_wImage.rotate(-90).show()
|
Reference in New Issue
Block a user