Skip to content

Instantly share code, notes, and snippets.

@Karts27

Karts27/plot.py Secret

Created September 26, 2021 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Karts27/5dbff0e569629f4a767e99076d95e3ae to your computer and use it in GitHub Desktop.
Save Karts27/5dbff0e569629f4a767e99076d95e3ae to your computer and use it in GitHub Desktop.
# Get image as numpy array
def load_image(name, path):
img_path = os.path.join(path, name)
img = cv2.imread(img_path)
# img = load_img(img_path, target_size = (256, 256))
return img
# Plot numpy array
def plot_image(img, name, title):
plt.imshow(img)
plt.suptitle(title)
#plt.title(name)
# Plot a grid of examples
def plot_grid(img_names, img_root, title ,rows=2, cols=3):
fig = plt.figure(figsize=(8,8))
for i,name in enumerate(img_names):
#print(os.path.join(img_root, name))
fig.add_subplot(rows,cols,i+1)
img = load_image(name, img_root)
plt.axis("off")
plot_image(img, name, title)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment