Save matplotlib figure image

https://stackoverflow.com/questions/8218608/scipy-savefig-without-frames-axes-only-content


 import matplotlib.pyplot as plt

import cv2
from skimage import measure

image = cv2.imread("/data/temp/image.png")
mask = cv2.imread("/data/temp/mask.png", -1) * 255
contours = measure.find_contours(mask, 200)

fig = plt.figure(frameon=False)
# fig.set_size_inches(w, h)

ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)

ax.imshow(image, aspect="auto")
for contour in contours:
ax.plot(contour[:, 1], contour[:, 0], linewidth=1, label="class 1", color=)
ax.legend()

fig.savefig("/data/temp/temp.png", format="png")

댓글

이 블로그의 인기 게시물

sklearn tsne + matplotlib scatter

Implementation of Focal Loss using Pytorch