Correct getPixelIndexesAround missing one pixel

This commit is contained in:
Benjamin Loison 2024-03-21 16:19:40 +01:00
parent 13de984d59
commit e23543506a
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8
2 changed files with 76 additions and 10 deletions

View File

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

View File

@ -3,11 +3,73 @@
<title>Xournal++ document - see https://github.com/xournalpp/xournalpp</title>
<page width="612.00000000" height="792.00000000">
<background type="pdf" domain="absolute" filename="/home/benjamin/Desktop/bens_folder/school/ens/asp/aria/internship/work/articles/Wu_ICIP_2012/Wu_ICIP_2012.pdf" pageno="1"/>
<layer/>
<layer>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">189.86619681 100.34185993 471.59663745 100.34185993</stroke>
<stroke tool="highlighter" color="#ffff007f" width="8.50000000" fill="128">120.55679195 76.98175099 511.06617071 76.98175099</stroke>
<stroke tool="highlighter" color="#ffff007f" width="8.50000000" fill="128">138.76572286 98.20363699 179.89327241 98.20363699</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">77.41941258 191.18816635 176.69579401 191.18816635</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">459.62811852 572.05461786 536.40914164 572.05461786</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">317.65695169 582.93401670 532.98492755 582.93401670</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">318.11393371 592.53780953 387.53102537 592.53780953</stroke>
<stroke tool="highlighter" color="#ff00007f" width="8.50000000" fill="128">416.26214183 593.68105666 535.59895730 593.68105666</stroke>
<stroke tool="highlighter" color="#ff00007f" width="8.50000000" fill="128">315.63638411 603.43834410 376.18976816 603.43834410</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">139.45716122 378.70050804 208.05241843 378.70050804</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">238.08555064 378.74488474 297.87494090 378.74488474</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">78.93345214 390.08937388 297.08516010 390.08937388</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">78.17899617 400.72696244 242.72783939 400.72696244</stroke>
<stroke tool="highlighter" color="#ff00007f" width="8.50000000" fill="128">252.20626186 400.18370744 298.78562791 400.18370744</stroke>
<stroke tool="highlighter" color="#ff00007f" width="8.50000000" fill="128">78.66667086 411.37732832 172.83413256 411.37732832</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">182.94980638 411.63570950 294.96144099 411.63570950</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">78.08589681 419.59506323 154.70364562 419.59506323</stroke>
</layer>
</page>
<page width="612.00000000" height="792.00000000">
<background type="pdf" pageno="2"/>
<layer/>
<layer>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">113.05686107 672.66922409 296.44277736 672.66922409</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">68.34184527 684.77824724 258.51710426 684.77824724</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">68.65223203 695.80774312 251.55692143 695.80774312</stroke>
<stroke tool="highlighter" color="#ffff007f" width="8.50000000" fill="128">265.11010524 694.69722094 300.10903449 694.69722094</stroke>
<stroke tool="highlighter" color="#ffff007f" width="8.50000000" fill="128">69.92480524 705.80446462 296.15811274 705.80446462</stroke>
<stroke tool="highlighter" color="#ffff007f" width="8.50000000" fill="128">318.78699653 78.11439441 546.53326986 78.11439441</stroke>
<stroke tool="highlighter" color="#ffff007f" width="8.50000000" fill="128">319.41066029 90.02207601 377.41961748 90.02207601</stroke>
<stroke tool="pen" ts="0" fn="" color="#000000ff" width="1.41000000" fill="255">552.10787178 85.59945343 552.10787178 126.11819116</stroke>
<text font="Sans" size="11.00000000" x="556.68595380" y="95.00859413" color="#000000ff" ts="0" fn="">repeating</text>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">397.41758794 131.64524977 543.52425391 131.64524977</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">319.44638779 143.33844575 544.00302913 143.33844575</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">317.17219592 154.11187377 380.89626753 154.11187377</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">381.80490880 164.49886246 381.80490880 188.35804957 489.83885903 188.35804957 489.83885903 164.49886246 381.80490880 164.49886246</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">348.99269109 201.41457550 348.99269109 201.41457550</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">388.18232038 201.93517385 546.06093760 201.93517385</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">319.37134969 220.11630584 378.22128431 220.11630584</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">412.37380430 220.97571258 412.37380430 220.97571258</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">457.79604024 220.16517707 544.99387050 220.16517707</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">319.80731485 233.35482844 447.33989804 233.35482844</stroke>
<text font="Sans" size="11.00000000" x="325.95857855" y="232.00175549" color="#00c0ffff" ts="0" fn="">?</text>
<stroke tool="highlighter" color="#ffff007f" width="8.50000000" fill="128">319.62726476 245.41541137 547.50943859 245.41541137</stroke>
<stroke tool="highlighter" color="#ffff007f" width="8.50000000" fill="128">320.65995162 255.84081489 426.42661319 255.84081489</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">460.62299210 255.14965818 545.51262246 255.14965818</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">317.55386354 266.63303688 543.52005731 266.63303688</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">318.81349069 276.95931983 344.64999234 276.95931983</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">351.98632538 288.04530323 351.98632538 311.85561911 521.50559156 311.85561911 521.50559156 288.04530323 351.98632538 288.04530323</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">347.10946908 326.05904278 347.10946908 326.05904278</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">381.87150597 326.28160757 542.83764148 326.28160757</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">375.30918646 343.68874121 389.86257172 343.68874121</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">421.06640653 342.80204789 545.51093442 342.80204789</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">318.14104183 356.92187196 367.54199113 356.92187196</stroke>
<stroke tool="highlighter" color="#ffff007f" width="8.50000000" fill="128">498.40787923 356.59210742 547.53351612 356.59210742</stroke>
<stroke tool="highlighter" color="#ffff007f" width="8.50000000" fill="128">320.38333045 373.41431942 457.43886341 373.41431942</stroke>
<stroke tool="pen" ts="0" fn="" color="#00c0ffff" width="1.41000000" fill="255">468.04976568 376.74471216 548.60279193 376.74471216</stroke>
<stroke tool="pen" ts="0" fn="" color="#00c0ffff" width="1.41000000" fill="255">317.06105133 391.69800003 447.08294363 391.69800003</stroke>
<stroke tool="highlighter" color="#00c0ff7f" width="8.50000000" fill="128">318.71726415 422.41714400 341.09904824 421.28413071</stroke>
<text font="Sans" size="11.00000000" x="496.83511099" y="426.93788671" color="#00c0ffff" ts="0" fn="">a bit unclear</text>
<text font="Sans" size="11.00000000" x="551.03425504" y="385.12907290" color="#00c0ffff" ts="0" fn="">a bit unclear</text>
<stroke tool="highlighter" color="#ff00007f" width="8.50000000" fill="128">376.61315431 446.50303023 543.67687816 446.50303023</stroke>
<stroke tool="highlighter" color="#ff00007f" width="8.50000000" fill="128">320.00841558 458.41942838 544.00912156 458.41942838</stroke>
<stroke tool="highlighter" color="#ff00007f" width="8.50000000" fill="128">320.17024017 470.35877206 361.63802376 470.35877206</stroke>
<text font="Sans" size="11.00000000" x="370.49258802" y="710.75351140" color="#00c0ffff" ts="0" fn="">for a single image it seems</text>
<stroke tool="highlighter" color="#ff00007f" width="8.50000000" fill="128">481.89488071 701.82269553 492.75675922 701.82269553</stroke>
</layer>
</page>
<page width="612.00000000" height="792.00000000">
<background type="pdf" pageno="3"/>