Changeset 2193
- Timestamp:
- 01/12/08 23:51:23 (5 years ago)
- Location:
- www/study
- Files:
-
- 2 edited
-
part3.html (modified) (5 diffs)
-
study.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
www/study/part3.html
r2190 r2193 263 263 <p> <b>Riemersma dithering</b> parses the image following a plane-filling 264 264 <b>Hilbert curve</b> and only propagates the error of the last <i>q</i> 265 pixels, weigh ing it with an exponential rule. The method is interesting and265 pixels, weighting it with an exponential rule. The method is interesting and 266 266 inventive, unfortunately the results are disappointing: structural artifacts 267 267 are worse than with other error diffusion methods (shown here with <i>q = … … 492 492 493 493 <p> The results on the vertical gradient indicate poor block-choosing. In 494 order to improve it, we introduce a modified, weigh ed intra-block error494 order to improve it, we introduce a modified, weighted intra-block error 495 495 distribution matrix, still based on the original Floyd-Steinberg matrix: </p> 496 496 … … 500 500 × 501 501 <img src="fig3-5-5b.png" width="81" height="81" 502 class="math" alt="weigh ed 2×2 matrix" />502 class="math" alt="weighted 2×2 matrix" /> 503 503 = 504 504 <img src="fig3-5-5.png" width="241" height="161" 505 class="math" alt="weigh ed 2×2 propagation matrix" />505 class="math" alt="weighted 2×2 propagation matrix" /> 506 506 </p> 507 507 … … 510 510 <p style="text-align: center;"> 511 511 <img src="out3-5-5.png" width="256" height="256" 512 class="inline" alt="weigh ed full 2×2 block Floyd-Steinberg" />512 class="inline" alt="weighted full 2×2 block Floyd-Steinberg" /> 513 513 <img src="grad3-5-5.png" width="32" height="256" 514 class="inline" alt="weigh ed full 2×2 block Floyd-Steinberg gradient" />514 class="inline" alt="weighted full 2×2 block Floyd-Steinberg gradient" /> 515 515 </p> 516 516 … … 528 528 <li> subpixel <b>a</b>’s error is harder to compensate than subpixel 529 529 <b>d</b>’s because its immediate neighbours are already in the block 530 being processed, so we weigh the sub-block matching in order to530 being processed, so we weight the sub-block matching in order to 531 531 prioritise pixel <b>a</b>’s matching. </li> 532 532 </ul> -
www/study/study.py
r2190 r2193 1540 1540 TILES22, DIFF_EVEN22, True, True).save("out3-5-4.png") 1541 1541 1542 DIFF_WEIGH ED22 = \1542 DIFF_WEIGHTED22 = \ 1543 1543 [[51./128, 33./128], 1544 1544 [25./128, 19./128]] … … 1555 1555 1556 1556 test351(grad256bw, ERROR_FSTEIN, 1557 TILES22, DIFF_WEIGH ED22, True, False).save("grad3-5-5.png")1557 TILES22, DIFF_WEIGHTED22, True, False).save("grad3-5-5.png") 1558 1558 test351(lenna256bw, ERROR_FSTEIN, 1559 TILES22, DIFF_WEIGH ED22, True, False).save("out3-5-5.png")1559 TILES22, DIFF_WEIGHTED22, True, False).save("out3-5-5.png") 1560 1560 1561 1561 # Output 3.6.1: sub-block error diffusion 1562 def test361(src, tiles, propagate, diff): 1563 (w, h) = src.size() 1562 def test361(src, tiles, propagate, diff, gamma): 1563 (w, h) = src.size() 1564 # Gamma correction 1565 if gamma: 1566 ctoi = Gamma.CtoI 1567 itoc = Gamma.ItoC 1568 else: 1569 ctoi = itoc = lambda x : x 1564 1570 # Propagating the error to a temporary buffer is becoming more and 1565 1571 # more complicated. We decide to use an intermediate matrix instead. … … 1567 1573 for y in range(h): 1568 1574 for x in range(w): 1569 tmp[y][x] = Gamma.CtoI(src.getGray(x, y))1575 tmp[y][x] = ctoi(src.getGray(x, y)) 1570 1576 dest = Image((w, h)) 1571 1577 # Analyse tile list … … 1581 1587 for j in range(ty): 1582 1588 for i in range(tx): 1583 cur[j][i] = Gamma.ItoC(tmp[y * ty + j][x * tx + i])1589 cur[j][i] = itoc(tmp[y * ty + j][x * tx + i]) 1584 1590 # Select closest block 1585 1591 dist = tx * ty … … 1601 1607 for j in range(ty): 1602 1608 for i in range(tx): 1603 e = Gamma.CtoI(cur[j][i]) - Gamma.CtoI(tiles[best][j][i])1609 e = ctoi(cur[j][i]) - ctoi(tiles[best][j][i]) 1604 1610 m = propagate[j][i] 1605 1611 for py in range(len(m)): … … 1633 1639 if chapter(3): 1634 1640 test361(grad256bw, TILES22, 1635 ERROR_SUBFS22, DIFF_WEIGH ED22).save("grad3-6-1.png")1641 ERROR_SUBFS22, DIFF_WEIGHTED22, False).save("grad3-6-1.png") 1636 1642 test361(lenna256bw, TILES22, 1637 ERROR_SUBFS22, DIFF_WEIGH ED22).save("out3-6-1.png")1643 ERROR_SUBFS22, DIFF_WEIGHTED22, False).save("out3-6-1.png") 1638 1644 1639 1645 test361(grad256bw, LINES22, 1640 ERROR_SUBFS22, DIFF_WEIGH ED22).save("grad3-6-2.png")1646 ERROR_SUBFS22, DIFF_WEIGHTED22, False).save("grad3-6-2.png") 1641 1647 test361(lenna256bw, LINES22, 1642 ERROR_SUBFS22, DIFF_WEIGH ED22).save("out3-6-2.png")1648 ERROR_SUBFS22, DIFF_WEIGHTED22, False).save("out3-6-2.png") 1643 1649 1644 1650 def colorise(val): … … 1714 1720 TILES33.append(mat) 1715 1721 1716 DIFF_WEIGH ED33 = \1722 DIFF_WEIGHTED33 = \ 1717 1723 [[15./64, 10./64, 6./64], 1718 1724 [10./64, 6./64, 4./64], … … 1721 1727 if chapter(3): 1722 1728 test361(grad256bw, TILES33, 1723 ERROR_SUBFS33, DIFF_WEIGH ED33).save("grad3-6-3.png")1729 ERROR_SUBFS33, DIFF_WEIGHTED33, False).save("grad3-6-3.png") 1724 1730 test361(lenna256bw, TILES33, 1725 ERROR_SUBFS33, DIFF_WEIGH ED33).save("out3-6-3.png")1731 ERROR_SUBFS33, DIFF_WEIGHTED33, False).save("out3-6-3.png") 1726 1732 test361(grad256bw, SQUARES33, 1727 ERROR_SUBFS33, DIFF_WEIGH ED33).save("grad3-6-4.png")1733 ERROR_SUBFS33, DIFF_WEIGHTED33, False).save("grad3-6-4.png") 1728 1734 test361(lenna256bw, SQUARES33, 1729 ERROR_SUBFS33, DIFF_WEIGH ED33).save("out3-6-4.png")1735 ERROR_SUBFS33, DIFF_WEIGHTED33, False).save("out3-6-4.png") 1730 1736 1731 1737 # XXX: hack, we modify ERROR_SUBFS33 because it's so much more convenient … … 2026 2032 if chapter(4): 2027 2033 test361(grad256bw, GREY22, 2028 ERROR_SUBFS22, DIFF_WEIGH ED22).save("grad4-3-1.png")2034 ERROR_SUBFS22, DIFF_WEIGHTED22, True).save("grad4-3-1.png") 2029 2035 test361(lenna256bw, GREY22, 2030 ERROR_SUBFS22, DIFF_WEIGH ED22).save("out4-3-1.png")2036 ERROR_SUBFS22, DIFF_WEIGHTED22, True).save("out4-3-1.png") 2031 2037 2032 2038 # Output 4.3.2: 4-colour block error diffusion with only line tiles … … 2041 2047 if chapter(4): 2042 2048 test361(grad256bw, GREYLINES22, 2043 ERROR_SUBFS22, DIFF_WEIGH ED22).save("grad4-3-2.png")2049 ERROR_SUBFS22, DIFF_WEIGHTED22, True).save("grad4-3-2.png") 2044 2050 test361(lenna256bw, GREYLINES22, 2045 ERROR_SUBFS22, DIFF_WEIGH ED22).save("out4-3-2.png")2051 ERROR_SUBFS22, DIFF_WEIGHTED22, True).save("out4-3-2.png") 2046 2052 2047 2053 ##############################################################################
Note: See TracChangeset
for help on using the changeset viewer.
