Beispiel #1
0
def doit(fn):
	p = ppm.ppm(fn)
	print(p)
	if p.x < 700:
		p2 = ppm.ppm(fn + "_.ppm", "w", p.x * 2, p.y * 2)
		print("Doubling", p, p2)
		for y in range(p2.y):
			for x in range(p2.x):
				i = p.rdpx(x / 2, y / 2)
				p2.wrpx(x, y, i[0], i[1], i[2])
		p = p2

	if False:
		o = p.clone("_.ppm")
	else:
		o = None

	# Segment
	if p.x > 1400:
		sl = list()
		sl.append(ppm.rect(p, 0, 0, p.x, p.y))
	else:
		sl = segment(p, o)
	if len(sl) == 0:
		sl.append(ppm.rect(p, 0, 0, p.x, p.y))


	# Trim
	w = trim(p, o, sl)
	print("W", w)
	g = True
	if w > dwid:
		g = False

	for rx in sl:
		if o != None:
			rx.outline(o, 0, 0, 255)
		add_chunk(rx, o)
	return g
Beispiel #2
0
def doit(fn):
    p = ppm.ppm(fn)
    print(p)
    if p.x < 700:
        p2 = ppm.ppm(fn + "_.ppm", "w", p.x * 2, p.y * 2)
        print("Doubling", p, p2)
        for y in range(p2.y):
            for x in range(p2.x):
                i = p.rdpx(x / 2, y / 2)
                p2.wrpx(x, y, i[0], i[1], i[2])
        p = p2

    if False:
        o = p.clone("_.ppm")
    else:
        o = None

    # Segment
    if p.x > 1400:
        sl = list()
        sl.append(ppm.rect(p, 0, 0, p.x, p.y))
    else:
        sl = segment(p, o)
    if len(sl) == 0:
        sl.append(ppm.rect(p, 0, 0, p.x, p.y))

    # Trim
    w = trim(p, o, sl)
    print("W", w)
    g = True
    if w > dwid:
        g = False

    for rx in sl:
        if o != None:
            rx.outline(o, 0, 0, 255)
        add_chunk(rx, o)
    return g
Beispiel #3
0
def emit_chunk():
    global nchunk
    global lchunk
    global hchunk
    fn = "_.%04d.ppm" % nchunk
    sys.stderr.write(".... " + fn + "\n")

    wchunk = 0
    xlo = 99999
    xhi = 0
    for r in lchunk:
        wchunk = max(wchunk, r.xhi - r.xlo)
        xlo = min(xlo, r.xlo)
        xhi = max(xhi, r.xhi)

    print("# WC", fn, wchunk, hchunk, xlo, xhi, xhi - xlo)
    if xhi - xlo < dwid:
        xhi = xlo + dwid
        wchunk = dwid

    d = ppm.ppm(fn, "w", 20 + wchunk, max(hchunk, dht))
    y = 0
    for r in lchunk:
        if xhi - xlo == wchunk:
            r.xlo = xlo
            r.xhi = min(xhi, r.p.x)
        d.put_rect(0, y, r)
        y += (r.yhi - r.ylo)
        for x in range(20):
            d.wrpx(x, y, 0, 0, 0)
            d.wrpx(d.x - (1 + x), y, 0, 0, 0)
        y += chunk_space

    lchunk = list()
    wchunk = 0
    hchunk = 0

    del d
    sub_cmd(
        "convert -type grayscale -colors 64 %s -compress lzw _.%04d.tiff ; rm -f %s"
        % (fn, nchunk, fn))
    nchunk += 1
Beispiel #4
0
def emit_chunk():
	global nchunk
	global lchunk
	global hchunk
	fn = "_.%04d.ppm" % nchunk
	sys.stderr.write(".... " + fn + "\n")

	wchunk = 0
	xlo = 99999
	xhi = 0
	for r in lchunk:
		wchunk = max(wchunk, r.xhi - r.xlo)
		xlo = min(xlo, r.xlo)
		xhi = max(xhi, r.xhi)

	print("# WC", fn, wchunk, hchunk, xlo, xhi, xhi - xlo)
	if xhi - xlo < dwid:
		xhi = xlo + dwid
		wchunk = dwid

	d = ppm.ppm(fn, "w", 20 + wchunk, max(hchunk,dht))
	y = 0
	for r in lchunk:
		if xhi - xlo == wchunk:
			r.xlo = xlo
			r.xhi = min(xhi, r.p.x)
		d.put_rect(0, y, r)
		y += (r.yhi - r.ylo)
		for x in range(20):
			d.wrpx(x, y, 0, 0, 0)
			d.wrpx(d.x - (1+x), y, 0, 0, 0)
		y += chunk_space

	lchunk = list()
	wchunk = 0
	hchunk = 0

	del d
	sub_cmd("convert -type grayscale -colors 64 %s -compress lzw _.%04d.tiff ; rm -f %s" % (fn, nchunk, fn))
	nchunk += 1
Beispiel #5
0
import ppm;
import os;
a=ppm.ppm('1.ppm');
print(a.Create(1024,1024,255,[12,24,48]));
print(a.Draw(200,200,[1,1,1]));
os.remove('1.ppm');
Beispiel #6
0
center_threshold = 220
prob_threshold = 100

if len(sys.argv) < 2:
	print 'YOU FAIL: NO INPUT FILE'
	sys.exit(0)

infile = sys.argv[1]
outfile = infile[:-4] + '_centers.pgm'
probfile = infile[:-4] + '_probs.pgm'
circlefile = infile[:-4] + '_circles.pgm'

img = pgm()
img.read(infile)
out_img = ppm()
out_img.read(infile)
centers = pgm()
centers.read(infile)
edges = pgm()
edges.read(infile)

radii={}

for r in range(centers.height):
	radii[r] = {}
	for c in range(centers.width):
		radii[r][c] = []
		centers.set_pixel(r,c,255)

probs = copy.deepcopy(centers)