I have written a thing in python that takes an image as an input, and writes the output as a triangle tessellated version of the input image. For example this image of a kitten:
gets transformed into this:
But when I try to save the image, somehow I get a white border around it which I can't seem to get rid of.
The code that takes care of saving the image is as follows:
my_dpi=100
figSize = imageWidth / float(my_dpi), imageHeight / float(my_dpi)
fig = plt.figure(figsize=figSize)
ax = fig.add_axes([0, 0, 1, 1])
ax.invert_yaxis()
for triangle, eColor, fColor in zip(tris.simplices, triColors, triColors):
p = Polygon([tris.points[i] for i in triangle], closed=True, facecolor=fColor, edgecolor=eColor)
ax.add_patch(p)
ax.axis('tight')
ax.set_axis_off()
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
outfile_name = "%s-%s-%s.png" % (sys.argv[1].split('.')[0], str(tris.simplices.shape[0]), str(i))
fig.savefig(outfile_name, bbox_inches='tight', pad_inches=0, dpi=my_dpi)
tris
is just a triangulation object that comes from scipy's delaunay triangulation module. I use that to calculate the color of each triangle and add a polygon patch for each triangle in the for loop. The final set of patches gets written to an image when the figure is saved onto the file. Because of the white background of this website, you might not be able to see the white border, but if you open the output image link, the white border is clearly visible there. I've tried everything that I could think of but can't seem to get rid of this white border. Is there a special way to get rid of it if I'm saving the figure using polygon patches?