예제 #1
0
파일: test.py 프로젝트: bhamrick/ai2
import sys
from pgm import pgm

infile = sys.argv[1]
outfile = sys.argv[2]

img = pgm()
img.read(infile)
for r in range(img.height):
	for c in range(img.width):
		img.set_pixel(r,c,img.get_pixel(r,c)/2)
img.write(outfile)
예제 #2
0
high_threshold = 400
low_threshold = 200

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)
예제 #3
0
파일: canny.py 프로젝트: bhamrick/ai2
import sys
import copy
from pgm import pgm
from ppm import ppm

high_threshold = 400
low_threshold = 200

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

infile = sys.argv[1]
outfile = infile[:-4] + '_canny.ppm'

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

def grad(img, r, c):
	if r <= 0 or c <= 0 or r >= img.height-1 or c >= img.width-1:
		return (0,0)
	gx = img.get_pixel(r-1,c+1) + 2*img.get_pixel(r,c+1) + img.get_pixel(r+1,c+1) - img.get_pixel(r-1,c-1) - 2*img.get_pixel(r,c-1) - img.get_pixel(r+1,c-1)
	gy = img.get_pixel(r+1,c-1) + 2*img.get_pixel(r+1,c) + img.get_pixel(r+1,c+1) - img.get_pixel(r-1,c-1) - 2*img.get_pixel(r-1,c) - img.get_pixel(r-1,c+1)
	return (gx,gy)

if len(sys.argv) >= 3:
	high_threshold = int(sys.argv[2])
예제 #4
0
	stdscr.move(0,0)
	stdscr.refresh()

update_bar(0,stdscr)

high_threshold = 400
low_threshold = 200

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

infile = sys.argv[1]
outfile = infile[:-4] + '_ellipses.pgm'

img = pgm()
img.read(infile)
edges = pgm()
edges.read(infile)
tmp_img = pgm()
tmp_img.read(infile)
tmpfile = infile[:-4] + '_space.pgm'
outimg = pgm()
outimg.read(infile)

for r in range(outimg.height):
	for c in range(outimg.width):
		outimg.set_pixel(r,c,255)

# Parameterize ellipses as <r,c> = <rc,cc> + <a*cos(theta+phi),b*sin(theta+phi)>
예제 #5
0
 def fromFile(cls, fileName):
     p = pgm(fileName)
     return cls(p.bytes, p.width, p.height)