Exemple #1
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
Exemple #2
0
#!/usr/bin/env python

import argparse
from imageprocessing import read_rgb_image, write_rgb_image, gray_as_rgb, sobel_scipy, rgb_as_gray, sobel

p = argparse.ArgumentParser()
p.add_argument('-i', required = True)
p.add_argument('-o', required = True)
p.add_argument('-f', required = True)
args = p.parse_args()

i = read_rgb_image(args.i)
o = None

if args.f == 'sobel':
	o = gray_as_rgb(sobel(i))
elif args.f == 'gray':
	o = gray_as_rgb(rgb_as_gray(i))
else:
	raise Exception('unknown filter')

write_rgb_image(args.o, o)
Exemple #3
0
        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