def computeIoU(predicted, expected):
	"""
		Computes the Intersection over Union metric for two binary masks.
	"""
	intersection = predicted * expected
	union = predicted + expected
	
	# Re-adjust union back to [0, 1] scale and return the result.
	union[union == 2] = 1
	return float(sum(intersection.flat)) / (sum(union.flat) or 1)