Changeset 1978
- Timestamp:
- Nov 16, 2007, 4:11:12 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
www/study/study.py
r1973 r1978 54 54 # Output 1.1.2: 40% threshold 55 55 # Output 1.1.3: 60% threshold 56 def test11x(src, threshold , name):56 def test11x(src, threshold): 57 57 (w, h) = src.size() 58 58 dest = Image((w, h)) … … 61 61 c = src.getGray(x, y) > threshold 62 62 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 65 test11x(lenna256bw, 0.5).writePng("out1-1-1.png") 66 test11x(lenna256bw, 0.4).writePng("out1-1-2.png") 67 test11x(lenna256bw, 0.6).writePng("out1-1-3.png") 68 test11x(gradient256bw, 0.5).writePng("grad1-1-1.png") 69 test11x(gradient256bw, 0.4).writePng("grad1-1-2.png") 70 test11x(gradient256bw, 0.6).writePng("grad1-1-3.png") 71 71 72 72 # Output 1.2.1: 3-colour threshold 73 73 # Output 1.2.2: 5-colour threshold 74 def test12x(src, colors , name):74 def test12x(src, colors): 75 75 (w, h) = src.size() 76 76 dest = Image((w, h)) … … 82 82 c = math.floor(c * p) / q 83 83 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 86 test12x(lenna256bw, 3).writePng("out1-2-1.png") 87 test12x(lenna256bw, 5).writePng("out1-2-2.png") 88 test12x(gradient256bw, 3).writePng("grad1-2-1.png") 89 test12x(gradient256bw, 5).writePng("grad1-2-2.png") 90 90 91 91 # Pattern 2.1.1: a 50% halftone pattern with various block sizes … … 111 111 112 112 # Output 2.1.1: 20/40/60/80% threshold with 25/50/75% patterns inbetween: 113 def test211(src , name):113 def test211(src): 114 114 (w, h) = src.size() 115 115 dest = Image((w, h)) … … 128 128 c = 1. 129 129 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 132 test211(lenna256bw).writePng("out2-1-1.png") 133 test211(gradient256bw).writePng("grad2-1-1.png") 134 134 135 135 # Pattern 2.2.1: vertical, mixed and horizontal black-white halftones … … 182 182 [ 11, 5, 2, 6, 12],] 183 183 184 def test23x(src, mat , name):184 def test23x(src, mat): 185 185 (w, h) = src.size() 186 186 dest = Image((w, h)) … … 193 193 c = c > threshold 194 194 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 197 test23x(lenna256bw, DITHER_BAYER44).writePng("out2-3-1.png") 198 test23x(gradient256bw, DITHER_BAYER44).writePng("grad2-3-1.png") 199 200 test23x(lenna256bw, DITHER_CLUSTER44).writePng("out2-3-2.png") 201 test23x(gradient256bw, DITHER_CLUSTER44).writePng("grad2-3-2.png") 202 203 test23x(lenna256bw, DITHER_LINE53).writePng("out2-3-3.png") 204 test23x(gradient256bw, DITHER_LINE53).writePng("grad2-3-3.png") 205 205 206 206 # Output 2.4.1: uniform random dithering 207 def test241(src , name):207 def test241(src): 208 208 random.seed(0) 209 209 (w, h) = src.size() … … 214 214 d = c > random.random() 215 215 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 218 test241(lenna256bw).writePng("out2-4-1.png") 219 test241(gradient256bw).writePng("grad2-4-1.png") 220 220 221 221 # Output 2.4.2: random dithering 222 def test242(src , name):222 def test242(src): 223 223 random.seed(0) 224 224 (w, h) = src.size() … … 229 229 d = c > random.gauss(0.5, 0.15) 230 230 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 233 test242(lenna256bw).writePng("out2-4-2.png") 234 test242(gradient256bw).writePng("grad2-4-2.png") 235 235 236 236 # Output 3.0.1: naive error diffusion … … 292 292 # [ 2./200, 9./200, 12./200, 9./200, 2./200]] 293 293 294 def test3xx(src, mat, serpentine , name):294 def test3xx(src, mat, serpentine): 295 295 (w, h) = src.size() 296 296 dest = Image((w, h)) … … 327 327 ey[dy] = ey[dy + 1] 328 328 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 331 test3xx(lenna256bw, ERROR_NAIVE, False).writePng("out3-0-1.png") 332 test3xx(gradient256bw, ERROR_NAIVE, False).writePng("grad3-0-1.png") 333 334 test3xx(lenna256bw, ERROR_FSTEIN, False).writePng("out3-1-1.png") 335 test3xx(gradient256bw, ERROR_FSTEIN, False).writePng("grad3-1-1.png") 336 test3xx(lenna256bw, ERROR_FSTEIN, True).writePng("out3-1-2.png") 337 test3xx(gradient256bw, ERROR_FSTEIN, True).writePng("grad3-1-2.png") 338 339 test3xx(lenna256bw, ERROR_FAN, False).writePng("out3-2-1.png") 340 test3xx(gradient256bw, ERROR_FAN, False).writePng("grad3-2-1.png") 341 342 test3xx(lenna256bw, ERROR_JAJUNI, False).writePng("out3-2-2.png") 343 test3xx(gradient256bw, ERROR_JAJUNI, False).writePng("grad3-2-2.png") 344 345 test3xx(lenna256bw, ERROR_STUCKI, False).writePng("out3-2-3.png") 346 test3xx(gradient256bw, ERROR_STUCKI, False).writePng("grad3-2-3.png") 347 348 test3xx(lenna256bw, ERROR_BURKES, False).writePng("out3-2-4.png") 349 test3xx(gradient256bw, ERROR_BURKES, False).writePng("grad3-2-4.png") 350 351 test3xx(lenna256bw, ERROR_SIERRA, False).writePng("out3-2-5.png") 352 test3xx(gradient256bw, ERROR_SIERRA, False).writePng("grad3-2-5.png") 353 354 test3xx(lenna256bw, ERROR_SIERRA2, False).writePng("out3-2-6.png") 355 test3xx(gradient256bw, ERROR_SIERRA2, False).writePng("grad3-2-6.png") 356 357 test3xx(lenna256bw, ERROR_FILTERLITE, False).writePng("out3-2-7.png") 358 test3xx(gradient256bw, ERROR_FILTERLITE, False).writePng("grad3-2-7.png") 359 360 test3xx(lenna256bw, ERROR_ATKINSON, False).writePng("out3-2-8.png") 361 test3xx(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") 368 368 369 369 # Output 4.0.1: 4x4 Bayer dithering, 3 colours 370 def test401(src, mat , name):370 def test401(src, mat): 371 371 (w, h) = src.size() 372 372 dest = Image((w, h)) … … 382 382 c = 0.5 + 0.5 * (c > 0.5 + threshold / 2) 383 383 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 386 test401(lenna256bw, DITHER_BAYER44).writePng("out4-0-1.png") 387 test401(gradient256bw, DITHER_BAYER44).writePng("grad4-0-1.png") 388 388 389 389 # Output 4.0.2: standard Floyd-Steinberg, 3 colours 390 def test402(src, mat, serpentine , name):390 def test402(src, mat, serpentine): 391 391 (w, h) = src.size() 392 392 dest = Image((w, h)) … … 423 423 ey[dy] = ey[dy + 1] 424 424 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 427 test402(lenna256bw, ERROR_FSTEIN, False).writePng("out4-0-2.png") 428 test402(gradient256bw, ERROR_FSTEIN, False).writePng("grad4-0-2.png") 429 429 430 430 # Pattern 4.1.1: gamma-corrected 50% gray, black-white halftone, 50% gray … … 442 442 # Output 4.2.1: gamma-corrected 2-colour Floyd-Steinberg 443 443 # Output 4.2.2: gamma-corrected 3-colour Floyd-Steinberg 444 def test42x(src, mat, threshold , name):444 def test42x(src, mat, threshold): 445 445 (w, h) = src.size() 446 446 dest = Image((w, h)) … … 468 468 ey[dy] = ey[dy + 1] 469 469 ey[lines - 1] = [0.] * (w + rows - 1) 470 dest.writePng(name)470 return dest 471 471 472 472 def threshold_2(x): … … 491 491 return 1. 492 492 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")493 test42x(lenna256bw, ERROR_FSTEIN, threshold_2).writePng("out4-2-1.png") 494 test42x(gradient256bw, ERROR_FSTEIN, threshold_2).writePng("grad4-2-1.png") 495 test42x(lenna256bw, ERROR_FSTEIN, threshold_3).writePng("out4-2-2.png") 496 test42x(gradient256bw, ERROR_FSTEIN, threshold_3).writePng("grad4-2-2.png") 497 497 498 498 ##############################################################################
Note: See TracChangeset
for help on using the changeset viewer.