Saturday, October 6, 2012

Which image looks more messy?



Created with this dumb python script:

#!/usr/bin/python

import random
import sys

def write_pgm(filename, width, height, buf):
    header = "P2\n#%s\n%d %d\n255" % (filename, width, height)

    f = open(filename,"wt")
    f.write(header)

    bufsize = len(buf)
    for i in range(bufsize):
        if i % width == 0:
            f.write("\n")
        f.write( "%03d " % (buf[i]) )

    f.close()


if __name__ == "__main__":

    random.seed()

    w=320
    h=240

    stains=32

    # uniform mess
    buf=w*h*[0]
    for i in range(stains):
        n = random.randrange(w*h)
        buf[n] = 255

    write_pgm('uniform.pgm',w,h,buf)

    # concentrated mess (only the upper part)
    buf=w*h*[0]
    for i in range(stains):
        n = random.randrange(w*h/10)
        buf[n] = 255

    write_pgm('concentrated.pgm',w,h,buf)

No comments: