Пример #1
0
tdb.arg_parser().add_argument("--std", required=True)
tdb.arg_parser().add_argument("--rows", type=int, default=20000)
tdb.arg_parser().add_argument("-o", required=True)
args = tdb.parse_args()

# read the mean for each dimension
mean = np.array(
    [float(i) for i in open(args.mean).readline().strip().split(" ")],
    np.float64)
assert (len(mean) == DIM)

# read the standard deviation for each dimension
std = np.array(
    [float(i) for i in open(args.std).readline().strip().split(" ")],
    np.float64)
assert (len(std) == DIM)


def compute(m):
    k = np.matrix([np.fromstring(i, np.uint8) for i in m]) - mean
    k = k / std
    return k.transpose() * k


jobs = process(tdb.groups(args.rows), compute)
m = reduce(lambda acc, x: acc + x, jobs, np.zeros((DIM, DIM), np.float64))

print >> sys.stderr, "processed rows:", tdb.count()

sio.savemat(args.o, {"c": m, "n": tdb.count()}, do_compression=True)
Пример #2
0
CHANNELS = 3
DIM = WIDTH * HEIGHT * CHANNELS

tdb = TinyDB(dimensions = DIM, parse_args = None)
tdb.arg_parser().add_argument("--mean", required = True)
tdb.arg_parser().add_argument("--std", required = True)
tdb.arg_parser().add_argument("--rows", type = int, default = 20000)
tdb.arg_parser().add_argument("-o", required = True)
args = tdb.parse_args()

# read the mean for each dimension
mean = np.array([float(i) for i in open(args.mean).readline().strip().split(" ")], np.float64)
assert(len(mean) == DIM)

# read the standard deviation for each dimension
std = np.array([float(i) for i in open(args.std).readline().strip().split(" ")], np.float64)
assert(len(std) == DIM)


def compute(m):
	k = np.matrix([np.fromstring(i, np.uint8) for i in m]) - mean
	k = k / std
	return k.transpose() * k

jobs = process(tdb.groups(args.rows), compute)
m = reduce(lambda acc, x: acc + x, jobs, np.zeros((DIM, DIM), np.float64))

print >> sys.stderr, "processed rows:", tdb.count()

sio.savemat(args.o, {"c": m, "n": tdb.count()}, do_compression = True)
Пример #3
0
	if filt == None:
		return arr
	elif filt == 'raw,sobel':
		i = ip.unflatten_rgb_image(arr, d, d)
		i = ip.sobel_scipy(i)
		i = ip.gray_as_rgb(i)
		return ip.flatten_rgb_image(i)
	raise Exception('unknown filter')

if args.filter == None:
	qi = np.int32(qi)
elif args.filter == 'raw,sobel':
	qi = np.int32(do_filter(qi, args.filter))
else:
	print >> sys.stderr, "unknown filter"
	sys.exit(1)

if args.filterout != None:
	ip.write_rgb_image(args.filterout, ip.unflatten_rgb_image(np.uint8(qi), d, d))

# -----------------------------

def compute_distance(datachunks):
	return [np.linalg.norm(qi - do_filter(np.fromstring(c, np.uint8), args.filter)) for c in datachunks]

c = 0
for result in process(db.groups(400), compute_distance):
	for k in result:
		print k, c
		c += 1
Пример #4
0
    raise Exception('unknown filter')


if args.filter == None:
    qi = np.int32(qi)
elif args.filter == 'raw,sobel':
    qi = np.int32(do_filter(qi, args.filter))
else:
    print >> sys.stderr, "unknown filter"
    sys.exit(1)

if args.filterout != None:
    ip.write_rgb_image(args.filterout,
                       ip.unflatten_rgb_image(np.uint8(qi), d, d))

# -----------------------------


def compute_distance(datachunks):
    return [
        np.linalg.norm(qi - do_filter(np.fromstring(c, np.uint8), args.filter))
        for c in datachunks
    ]


c = 0
for result in process(db.groups(400), compute_distance):
    for k in result:
        print k, c
        c += 1