Changeset 1930 for www/study/study.py
- Timestamp:
- 11/11/07 13:27:40 (6 years ago)
- File:
-
- 1 edited
-
www/study/study.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
www/study/study.py
r1927 r1930 47 47 for y in range(256): 48 48 gradient256bw.setGray(x, 255 - y, y / 255.) 49 gradient256bw.writePng("gradient256bw.png") 49 50 50 51 # Output 1: 50% threshold … … 143 144 dest.setGray(x, y, c) 144 145 dest.writePng("pat003.png") 146 147 # Pattern 4: two different 25% patterns 148 dest = Image((320, 80)) 149 for y in range(80): 150 for x in range(80): 151 c = (x / 2 & 1) and (y / 2 & 1) 152 dest.setGray(x, y, c) 153 for x in range(80, 160): 154 c = (x & 1) and (y & 1) 155 dest.setGray(x, y, c) 156 for x in range(160, 240): 157 c = (x & 1) and ((y + x / 2) & 1) 158 dest.setGray(x, y, c) 159 for x in range(240, 320): 160 c = (x / 2 & 1) and ((y / 2 + x / 4) & 1) 161 dest.setGray(x, y, c) 162 dest.writePng("pat004.png") 163 164 # Output 7: 4x4 Bayer dithering 165 def test4(src, mat, name): 166 (w, h) = src.size() 167 dest = Image((w, h)) 168 dx = len(mat[0]) 169 dy = len(mat) 170 for y in range(h): 171 for x in range(w): 172 c = src.getGray(x, y) 173 threshold = (1. + mat[y % dy][x % dx]) / (dx * dy + 1) 174 c = c > threshold 175 dest.setGray(x, y, c) 176 dest.writePng(name) 177 178 mat = [[ 0, 8, 3, 11], 179 [ 15, 4, 12, 7], 180 [ 2, 10, 1, 9], 181 [ 13, 6, 14, 5]] 182 test4(lenna256bw, mat, "out007.png") 183 test4(gradient256bw, mat, "grad007.png") 184 185 mat = [[ 12, 5, 6, 13], 186 [ 4, 0, 1, 7], 187 [ 11, 3, 2, 8], 188 [ 15, 10, 9, 14]] 189 test4(lenna256bw, mat, "out008.png") 190 test4(gradient256bw, mat, "grad008.png") 191 192 mat = [[ 13, 7, 0, 4, 10], 193 [ 9, 3, 1, 8, 14], 194 [ 11, 5, 2, 6, 12],] 195 test4(lenna256bw, mat, "out009.png") 196 test4(gradient256bw, mat, "grad009.png") 197 198 ############################################################################## 199 # Only temporary cruft below this 200 import sys 201 sys.exit(0) 202 203 204 145 205 146 206 # Pattern 4: gamma-corrected 50% gray, black-white halftone, 50% gray … … 213 273 214 274 215 ##############################################################################216 # Only temporary cruft below this217 218 275 src = lenna256bw 219 276 src = gradient256bw … … 224 281 [ 2, 10, 1, 9], 225 282 [ 13, 6, 14, 5]] 226 mat = [[ 6, 7, 8, 9], 227 [ 5, 0, 1, 10], 228 [ 4, 3, 2, 11], 229 [ 15, 14, 13, 12]] 230 mat = [[ 12, 5, 9, 13], 231 [ 8, 0, 1, 6], 232 [ 4, 3, 2, 10], 233 [ 15, 11, 7, 14]] 234 mat = [[ 35, 24, 13, 14, 25, 32], 235 [ 31, 12, 5, 6, 15, 26], 236 [ 23, 4, 0, 1, 7, 16], 237 [ 22, 11, 3, 2, 8, 17], 238 [ 30, 21, 10, 9, 18, 27], 239 [ 34, 29, 20, 19, 28, 33]] 240 mat = [[ 0, 20, 30, 3, 23, 29], 241 [ 12, 32, 18, 15, 35, 17], 242 [ 27, 8, 4, 24, 11, 7], 243 [ 2, 22, 28, 1, 21, 31], 244 [ 14, 34, 16, 13, 33, 19], 245 [ 25, 10, 6, 26, 9, 5]] 283 #mat = [[ 6, 7, 8, 9], 284 # [ 5, 0, 1, 10], 285 # [ 4, 3, 2, 11], 286 # [ 15, 14, 13, 12]] 287 #mat = [[ 12, 5, 9, 13], 288 # [ 8, 0, 1, 6], 289 # [ 4, 3, 2, 10], 290 # [ 15, 11, 7, 14]] 291 size = 4 292 #mat = [[ 35, 24, 13, 14, 25, 32], 293 # [ 31, 12, 5, 6, 15, 26], 294 # [ 23, 4, 0, 1, 7, 16], 295 # [ 22, 11, 3, 2, 8, 17], 296 # [ 30, 21, 10, 9, 18, 27], 297 # [ 34, 29, 20, 19, 28, 33]] 298 #mat = [[ 0, 20, 30, 3, 23, 29], 299 # [ 12, 32, 18, 15, 35, 17], 300 # [ 27, 8, 4, 24, 11, 7], 301 # [ 2, 22, 28, 1, 21, 31], 302 # [ 14, 34, 16, 13, 33, 19], 303 # [ 25, 10, 6, 26, 9, 5]] 304 #size = 6 246 305 dest = Image((w, h)) 247 306 for y in range(h): … … 249 308 c = src.getGray(x, y) 250 309 i = Gamma.CtoI(c) 251 threshold = mat[x % 6][y % 6] 252 c = math.floor(i * 35.999) > threshold 310 threshold = mat[x % size][y % size] 311 d = math.floor(i * (size * size + .9999)) > threshold 312 if c > 0.95: 313 print c, i, i * (size * size + .9999) 314 c = d 253 315 dest.setGray(x, y, c) 254 316 dest.writePng("out008.png") 255 256 import sys257 sys.exit(0)258 317 259 318 # Create a dot-matrix pattern
Note: See TracChangeset
for help on using the changeset viewer.
