Created
July 4, 2009 13:52
-
-
Save bayerj/140584 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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