From e23543506a88c2a0ac8bf3ea6d9a06a7cb39c79a Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Thu, 21 Mar 2024 16:19:40 +0100 Subject: [PATCH] Correct `getPixelIndexesAround` missing one pixel --- algorithms/context-adaptive_interpolator.py | 20 ++++--- articles/Wu_ICIP_2012/Wu_ICIP_2012.xopp.xml | 66 ++++++++++++++++++++- 2 files changed, 76 insertions(+), 10 deletions(-) diff --git a/algorithms/context-adaptive_interpolator.py b/algorithms/context-adaptive_interpolator.py index e2e22f5..9e1e027 100644 --- a/algorithms/context-adaptive_interpolator.py +++ b/algorithms/context-adaptive_interpolator.py @@ -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() \ No newline at end of file diff --git a/articles/Wu_ICIP_2012/Wu_ICIP_2012.xopp.xml b/articles/Wu_ICIP_2012/Wu_ICIP_2012.xopp.xml index 114d423..881bdad 100644 --- a/articles/Wu_ICIP_2012/Wu_ICIP_2012.xopp.xml +++ b/articles/Wu_ICIP_2012/Wu_ICIP_2012.xopp.xml @@ -3,11 +3,73 @@ Xournal++ document - see https://github.com/xournalpp/xournalpp - + + 189.86619681 100.34185993 471.59663745 100.34185993 + 120.55679195 76.98175099 511.06617071 76.98175099 + 138.76572286 98.20363699 179.89327241 98.20363699 + 77.41941258 191.18816635 176.69579401 191.18816635 + 459.62811852 572.05461786 536.40914164 572.05461786 + 317.65695169 582.93401670 532.98492755 582.93401670 + 318.11393371 592.53780953 387.53102537 592.53780953 + 416.26214183 593.68105666 535.59895730 593.68105666 + 315.63638411 603.43834410 376.18976816 603.43834410 + 139.45716122 378.70050804 208.05241843 378.70050804 + 238.08555064 378.74488474 297.87494090 378.74488474 + 78.93345214 390.08937388 297.08516010 390.08937388 + 78.17899617 400.72696244 242.72783939 400.72696244 + 252.20626186 400.18370744 298.78562791 400.18370744 + 78.66667086 411.37732832 172.83413256 411.37732832 + 182.94980638 411.63570950 294.96144099 411.63570950 + 78.08589681 419.59506323 154.70364562 419.59506323 + - + + 113.05686107 672.66922409 296.44277736 672.66922409 + 68.34184527 684.77824724 258.51710426 684.77824724 + 68.65223203 695.80774312 251.55692143 695.80774312 + 265.11010524 694.69722094 300.10903449 694.69722094 + 69.92480524 705.80446462 296.15811274 705.80446462 + 318.78699653 78.11439441 546.53326986 78.11439441 + 319.41066029 90.02207601 377.41961748 90.02207601 + 552.10787178 85.59945343 552.10787178 126.11819116 + repeating + 397.41758794 131.64524977 543.52425391 131.64524977 + 319.44638779 143.33844575 544.00302913 143.33844575 + 317.17219592 154.11187377 380.89626753 154.11187377 + 381.80490880 164.49886246 381.80490880 188.35804957 489.83885903 188.35804957 489.83885903 164.49886246 381.80490880 164.49886246 + 348.99269109 201.41457550 348.99269109 201.41457550 + 388.18232038 201.93517385 546.06093760 201.93517385 + 319.37134969 220.11630584 378.22128431 220.11630584 + 412.37380430 220.97571258 412.37380430 220.97571258 + 457.79604024 220.16517707 544.99387050 220.16517707 + 319.80731485 233.35482844 447.33989804 233.35482844 + ? + 319.62726476 245.41541137 547.50943859 245.41541137 + 320.65995162 255.84081489 426.42661319 255.84081489 + 460.62299210 255.14965818 545.51262246 255.14965818 + 317.55386354 266.63303688 543.52005731 266.63303688 + 318.81349069 276.95931983 344.64999234 276.95931983 + 351.98632538 288.04530323 351.98632538 311.85561911 521.50559156 311.85561911 521.50559156 288.04530323 351.98632538 288.04530323 + 347.10946908 326.05904278 347.10946908 326.05904278 + 381.87150597 326.28160757 542.83764148 326.28160757 + 375.30918646 343.68874121 389.86257172 343.68874121 + 421.06640653 342.80204789 545.51093442 342.80204789 + 318.14104183 356.92187196 367.54199113 356.92187196 + 498.40787923 356.59210742 547.53351612 356.59210742 + 320.38333045 373.41431942 457.43886341 373.41431942 + 468.04976568 376.74471216 548.60279193 376.74471216 + 317.06105133 391.69800003 447.08294363 391.69800003 + 318.71726415 422.41714400 341.09904824 421.28413071 + a bit unclear + a bit unclear + 376.61315431 446.50303023 543.67687816 446.50303023 + 320.00841558 458.41942838 544.00912156 458.41942838 + 320.17024017 470.35877206 361.63802376 470.35877206 + for a single image it seems + 481.89488071 701.82269553 492.75675922 701.82269553 +