Skip to content

Instantly share code, notes, and snippets.

@bayerj
Created July 4, 2009 13:52
Show Gist options
  • Save bayerj/140584 to your computer and use it in GitHub Desktop.
Save bayerj/140584 to your computer and use it in GitHub Desktop.
def plot_prediction(result, sample, target, filename=None):
sample.shape = 512, 512
fig = pylab.figure()
plot = fig.add_subplot(111)
pylab.imshow(sample, cmap=pylab.cm.gray)
denormalize = lambda x, rng: (x + 1.) * rng / 2
def getcoords(normalized):
min0, max0, min1, max1 = normalized.tolist()
min0 = int(denormalize(min0, sample.shape[0]))
max0 = int(denormalize(max0, sample.shape[0]))
min1 = int(denormalize(min1, sample.shape[1]))
max1 = int(denormalize(max1, sample.shape[1]))
return min0, min1, max0 - min0, max1 - min1
x, y, width, height = getcoords(target)
rect = pylab.Rectangle((x, y), width, height, fill=True, alpha=.7,
facecolor='red')
plot.add_patch(rect)
x, y, width, height = getcoords(result)
rect = pylab.Rectangle((x, y), width, height, fill=True, alpha=.7,
facecolor='blue')
plot.add_patch(rect)
if filename is None:
pylab.show()
else:
pylab.savefig(filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment