Changeset 1978


Ignore:
Timestamp:
Nov 16, 2007, 4:11:12 PM (13 years ago)
Author:
Sam Hocevar
Message:
  • No longer pass the idiotic "name" parameter to tests.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • www/study/study.py

    r1973 r1978  
    5454# Output 1.1.2: 40% threshold
    5555# Output 1.1.3: 60% threshold
    56 def test11x(src, threshold, name):
     56def test11x(src, threshold):
    5757    (w, h) = src.size()
    5858    dest = Image((w, h))
     
    6161            c = src.getGray(x, y) > threshold
    6262            dest.setGray(x, y, c)
    63     dest.writePng(name)
    64 
    65 test11x(lenna256bw, 0.5, "out1-1-1.png")
    66 test11x(lenna256bw, 0.4, "out1-1-2.png")
    67 test11x(lenna256bw, 0.6, "out1-1-3.png")
    68 test11x(gradient256bw, 0.5, "grad1-1-1.png")
    69 test11x(gradient256bw, 0.4, "grad1-1-2.png")
    70 test11x(gradient256bw, 0.6, "grad1-1-3.png")
     63    return dest
     64
     65test11x(lenna256bw, 0.5).writePng("out1-1-1.png")
     66test11x(lenna256bw, 0.4).writePng("out1-1-2.png")
     67test11x(lenna256bw, 0.6).writePng("out1-1-3.png")
     68test11x(gradient256bw, 0.5).writePng("grad1-1-1.png")
     69test11x(gradient256bw, 0.4).writePng("grad1-1-2.png")
     70test11x(gradient256bw, 0.6).writePng("grad1-1-3.png")
    7171
    7272# Output 1.2.1: 3-colour threshold
    7373# Output 1.2.2: 5-colour threshold
    74 def test12x(src, colors, name):
     74def test12x(src, colors):
    7575    (w, h) = src.size()
    7676    dest = Image((w, h))
     
    8282            c = math.floor(c * p) / q
    8383            dest.setGray(x, y, c)
    84     dest.writePng(name)
    85 
    86 test12x(lenna256bw, 3, "out1-2-1.png")
    87 test12x(lenna256bw, 5, "out1-2-2.png")
    88 test12x(gradient256bw, 3, "grad1-2-1.png")
    89 test12x(gradient256bw, 5, "grad1-2-2.png")
     84    return dest
     85
     86test12x(lenna256bw, 3).writePng("out1-2-1.png")
     87test12x(lenna256bw, 5).writePng("out1-2-2.png")
     88test12x(gradient256bw, 3).writePng("grad1-2-1.png")
     89test12x(gradient256bw, 5).writePng("grad1-2-2.png")
    9090
    9191# Pattern 2.1.1: a 50% halftone pattern with various block sizes
     
    111111
    112112# Output 2.1.1: 20/40/60/80% threshold with 25/50/75% patterns inbetween:
    113 def test211(src, name):
     113def test211(src):
    114114    (w, h) = src.size()
    115115    dest = Image((w, h))
     
    128128                c = 1.
    129129            dest.setGray(x, y, c)
    130     dest.writePng(name)
    131 
    132 test211(lenna256bw, "out2-1-1.png")
    133 test211(gradient256bw, "grad2-1-1.png")
     130    return dest
     131
     132test211(lenna256bw).writePng("out2-1-1.png")
     133test211(gradient256bw).writePng("grad2-1-1.png")
    134134
    135135# Pattern 2.2.1: vertical, mixed and horizontal black-white halftones
     
    182182     [ 11,  5,  2,  6, 12],]
    183183
    184 def test23x(src, mat, name):
     184def test23x(src, mat):
    185185    (w, h) = src.size()
    186186    dest = Image((w, h))
     
    193193            c = c > threshold
    194194            dest.setGray(x, y, c)
    195     dest.writePng(name)
    196 
    197 test23x(lenna256bw, DITHER_BAYER44, "out2-3-1.png")
    198 test23x(gradient256bw, DITHER_BAYER44, "grad2-3-1.png")
    199 
    200 test23x(lenna256bw, DITHER_CLUSTER44, "out2-3-2.png")
    201 test23x(gradient256bw, DITHER_CLUSTER44, "grad2-3-2.png")
    202 
    203 test23x(lenna256bw, DITHER_LINE53, "out2-3-3.png")
    204 test23x(gradient256bw, DITHER_LINE53, "grad2-3-3.png")
     195    return dest
     196
     197test23x(lenna256bw, DITHER_BAYER44).writePng("out2-3-1.png")
     198test23x(gradient256bw, DITHER_BAYER44).writePng("grad2-3-1.png")
     199
     200test23x(lenna256bw, DITHER_CLUSTER44).writePng("out2-3-2.png")
     201test23x(gradient256bw, DITHER_CLUSTER44).writePng("grad2-3-2.png")
     202
     203test23x(lenna256bw, DITHER_LINE53).writePng("out2-3-3.png")
     204test23x(gradient256bw, DITHER_LINE53).writePng("grad2-3-3.png")
    205205
    206206# Output 2.4.1: uniform random dithering
    207 def test241(src, name):
     207def test241(src):
    208208    random.seed(0)
    209209    (w, h) = src.size()
     
    214214            d = c > random.random()
    215215            dest.setGray(x, y, d)
    216     dest.writePng(name)
    217 
    218 test241(lenna256bw, "out2-4-1.png")
    219 test241(gradient256bw, "grad2-4-1.png")
     216    return dest
     217
     218test241(lenna256bw).writePng("out2-4-1.png")
     219test241(gradient256bw).writePng("grad2-4-1.png")
    220220
    221221# Output 2.4.2: random dithering
    222 def test242(src, name):
     222def test242(src):
    223223    random.seed(0)
    224224    (w, h) = src.size()
     
    229229            d = c > random.gauss(0.5, 0.15)
    230230            dest.setGray(x, y, d)
    231     dest.writePng(name)
    232 
    233 test242(lenna256bw, "out2-4-2.png")
    234 test242(gradient256bw, "grad2-4-2.png")
     231    return dest
     232
     233test242(lenna256bw).writePng("out2-4-2.png")
     234test242(gradient256bw).writePng("grad2-4-2.png")
    235235
    236236# Output 3.0.1: naive error diffusion
     
    292292#     [  2./200,  9./200, 12./200,  9./200,  2./200]]
    293293
    294 def test3xx(src, mat, serpentine, name):
     294def test3xx(src, mat, serpentine):
    295295    (w, h) = src.size()
    296296    dest = Image((w, h))
     
    327327            ey[dy] = ey[dy + 1]
    328328        ey[lines - 1] = [0.] * (w + rows - 1)
    329     dest.writePng(name)
    330 
    331 test3xx(lenna256bw, ERROR_NAIVE, False, "out3-0-1.png")
    332 test3xx(gradient256bw, ERROR_NAIVE, False, "grad3-0-1.png")
    333 
    334 test3xx(lenna256bw, ERROR_FSTEIN, False, "out3-1-1.png")
    335 test3xx(gradient256bw, ERROR_FSTEIN, False, "grad3-1-1.png")
    336 test3xx(lenna256bw, ERROR_FSTEIN, True, "out3-1-2.png")
    337 test3xx(gradient256bw, ERROR_FSTEIN, True, "grad3-1-2.png")
    338 
    339 test3xx(lenna256bw, ERROR_FAN, False, "out3-2-1.png")
    340 test3xx(gradient256bw, ERROR_FAN, False, "grad3-2-1.png")
    341 
    342 test3xx(lenna256bw, ERROR_JAJUNI, False, "out3-2-2.png")
    343 test3xx(gradient256bw, ERROR_JAJUNI, False, "grad3-2-2.png")
    344 
    345 test3xx(lenna256bw, ERROR_STUCKI, False, "out3-2-3.png")
    346 test3xx(gradient256bw, ERROR_STUCKI, False, "grad3-2-3.png")
    347 
    348 test3xx(lenna256bw, ERROR_BURKES, False, "out3-2-4.png")
    349 test3xx(gradient256bw, ERROR_BURKES, False, "grad3-2-4.png")
    350 
    351 test3xx(lenna256bw, ERROR_SIERRA, False, "out3-2-5.png")
    352 test3xx(gradient256bw, ERROR_SIERRA, False, "grad3-2-5.png")
    353 
    354 test3xx(lenna256bw, ERROR_SIERRA2, False, "out3-2-6.png")
    355 test3xx(gradient256bw, ERROR_SIERRA2, False, "grad3-2-6.png")
    356 
    357 test3xx(lenna256bw, ERROR_FILTERLITE, False, "out3-2-7.png")
    358 test3xx(gradient256bw, ERROR_FILTERLITE, False, "grad3-2-7.png")
    359 
    360 test3xx(lenna256bw, ERROR_ATKINSON, False, "out3-2-8.png")
    361 test3xx(gradient256bw, ERROR_ATKINSON, False, "grad3-2-8.png")
    362 
    363 #test3xx(lenna256bw, ERROR_STAR, False, "out3-2-9.png")
    364 #test3xx(gradient256bw, ERROR_STAR, False, "grad3-2-9.png")
    365 
    366 #test3xx(lenna256bw, ERROR_STAR, False, "out3-2-9.png")
    367 #test3xx(gradient256bw, ERROR_STAR, False, "grad3-2-9.png")
     329    return dest
     330
     331test3xx(lenna256bw, ERROR_NAIVE, False).writePng("out3-0-1.png")
     332test3xx(gradient256bw, ERROR_NAIVE, False).writePng("grad3-0-1.png")
     333
     334test3xx(lenna256bw, ERROR_FSTEIN, False).writePng("out3-1-1.png")
     335test3xx(gradient256bw, ERROR_FSTEIN, False).writePng("grad3-1-1.png")
     336test3xx(lenna256bw, ERROR_FSTEIN, True).writePng("out3-1-2.png")
     337test3xx(gradient256bw, ERROR_FSTEIN, True).writePng("grad3-1-2.png")
     338
     339test3xx(lenna256bw, ERROR_FAN, False).writePng("out3-2-1.png")
     340test3xx(gradient256bw, ERROR_FAN, False).writePng("grad3-2-1.png")
     341
     342test3xx(lenna256bw, ERROR_JAJUNI, False).writePng("out3-2-2.png")
     343test3xx(gradient256bw, ERROR_JAJUNI, False).writePng("grad3-2-2.png")
     344
     345test3xx(lenna256bw, ERROR_STUCKI, False).writePng("out3-2-3.png")
     346test3xx(gradient256bw, ERROR_STUCKI, False).writePng("grad3-2-3.png")
     347
     348test3xx(lenna256bw, ERROR_BURKES, False).writePng("out3-2-4.png")
     349test3xx(gradient256bw, ERROR_BURKES, False).writePng("grad3-2-4.png")
     350
     351test3xx(lenna256bw, ERROR_SIERRA, False).writePng("out3-2-5.png")
     352test3xx(gradient256bw, ERROR_SIERRA, False).writePng("grad3-2-5.png")
     353
     354test3xx(lenna256bw, ERROR_SIERRA2, False).writePng("out3-2-6.png")
     355test3xx(gradient256bw, ERROR_SIERRA2, False).writePng("grad3-2-6.png")
     356
     357test3xx(lenna256bw, ERROR_FILTERLITE, False).writePng("out3-2-7.png")
     358test3xx(gradient256bw, ERROR_FILTERLITE, False).writePng("grad3-2-7.png")
     359
     360test3xx(lenna256bw, ERROR_ATKINSON, False).writePng("out3-2-8.png")
     361test3xx(gradient256bw, ERROR_ATKINSON, False).writePng("grad3-2-8.png")
     362
     363#test3xx(lenna256bw, ERROR_STAR, False).writePng("out3-2-9.png")
     364#test3xx(gradient256bw, ERROR_STAR, False).writePng("grad3-2-9.png")
     365
     366#test3xx(lenna256bw, ERROR_STAR, False).writePng("out3-2-9.png")
     367#test3xx(gradient256bw, ERROR_STAR, False).writePng("grad3-2-9.png")
    368368
    369369# Output 4.0.1: 4x4 Bayer dithering, 3 colours
    370 def test401(src, mat, name):
     370def test401(src, mat):
    371371    (w, h) = src.size()
    372372    dest = Image((w, h))
     
    382382                c = 0.5 + 0.5 * (c > 0.5 + threshold / 2)
    383383            dest.setGray(x, y, c)
    384     dest.writePng(name)
    385 
    386 test401(lenna256bw, DITHER_BAYER44, "out4-0-1.png")
    387 test401(gradient256bw, DITHER_BAYER44, "grad4-0-1.png")
     384    return dest
     385
     386test401(lenna256bw, DITHER_BAYER44).writePng("out4-0-1.png")
     387test401(gradient256bw, DITHER_BAYER44).writePng("grad4-0-1.png")
    388388
    389389# Output 4.0.2: standard Floyd-Steinberg, 3 colours
    390 def test402(src, mat, serpentine, name):
     390def test402(src, mat, serpentine):
    391391    (w, h) = src.size()
    392392    dest = Image((w, h))
     
    423423            ey[dy] = ey[dy + 1]
    424424        ey[lines - 1] = [0.] * (w + rows - 1)
    425     dest.writePng(name)
    426 
    427 test402(lenna256bw, ERROR_FSTEIN, False, "out4-0-2.png")
    428 test402(gradient256bw, ERROR_FSTEIN, False, "grad4-0-2.png")
     425    return dest
     426
     427test402(lenna256bw, ERROR_FSTEIN, False).writePng("out4-0-2.png")
     428test402(gradient256bw, ERROR_FSTEIN, False).writePng("grad4-0-2.png")
    429429
    430430# Pattern 4.1.1: gamma-corrected 50% gray, black-white halftone, 50% gray
     
    442442# Output 4.2.1: gamma-corrected 2-colour Floyd-Steinberg
    443443# Output 4.2.2: gamma-corrected 3-colour Floyd-Steinberg
    444 def test42x(src, mat, threshold, name):
     444def test42x(src, mat, threshold):
    445445    (w, h) = src.size()
    446446    dest = Image((w, h))
     
    468468            ey[dy] = ey[dy + 1]
    469469        ey[lines - 1] = [0.] * (w + rows - 1)
    470     dest.writePng(name)
     470    return dest
    471471
    472472def threshold_2(x):
     
    491491    return 1.
    492492
    493 test42x(lenna256bw, ERROR_FSTEIN, threshold_2, "out4-2-1.png")
    494 test42x(gradient256bw, ERROR_FSTEIN, threshold_2, "grad4-2-1.png")
    495 test42x(lenna256bw, ERROR_FSTEIN, threshold_3, "out4-2-2.png")
    496 test42x(gradient256bw, ERROR_FSTEIN, threshold_3, "grad4-2-2.png")
     493test42x(lenna256bw, ERROR_FSTEIN, threshold_2).writePng("out4-2-1.png")
     494test42x(gradient256bw, ERROR_FSTEIN, threshold_2).writePng("grad4-2-1.png")
     495test42x(lenna256bw, ERROR_FSTEIN, threshold_3).writePng("out4-2-2.png")
     496test42x(gradient256bw, ERROR_FSTEIN, threshold_3).writePng("grad4-2-2.png")
    497497
    498498##############################################################################
Note: See TracChangeset for help on using the changeset viewer.