def imResize(image):
	import cv2
	height = image.shape[0]
	width = image.shape[1]
	maxW = 1000.0
	maxH = 600.0
	dim = (width, height)
	if height > maxH or width > maxW:
		if height > width:
			r = maxH/height
			dim = (int(width * r), int(maxH))
		else:
			r = maxW/width
			dim = (int(maxW), int(height * r))
	newimage = cv2.resize(image,dim)
	return newimage

def sort_contours(cnts, method="left-to-right"):
	import cv2
	# initialize the reverse flag and sort index
	reverse = False
	i = 0

	# handle if we need to sort in reverse
	if method == "right-to-left" or method == "bottom-to-top":
		reverse = True

	# handle if we are sorting against the y-coordinate rather than
	# the x-coordinate of the bounding box
	if method == "top-to-bottom" or method == "bottom-to-top":
		i = 1

	# construct the list of bounding boxes and sort them from top to
	# bottom
	boundingBoxes = [cv2.boundingRect(c) for c in cnts]
	(cnts, boundingBoxes) = zip(*sorted(zip(cnts, boundingBoxes),
		key=lambda b:b[1][i], reverse=reverse))

	# return the list of sorted contours and bounding boxes
	return (cnts, boundingBoxes)
