-
Notifications
You must be signed in to change notification settings - Fork 0
/
matplotlib_imshow.py
39 lines (32 loc) · 1.52 KB
/
matplotlib_imshow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# -----------------------------------------------------------------------------------------------
### Imports ###
# -----------------------------------------------------------------------------------------------
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
# -----------------------------------------------------------------------------------------------
### Matplotlib Imshow ###
# -----------------------------------------------------------------------------------------------
# converting color mode to RGB and displaying the image as matplotlib figure
def matplotlib_imshow(
img_title="", img=None, scale=5, cv_colorspace_conversion_flag=cv.COLOR_BGR2RGB
):
"""
title: plot title (to be shown)
img: image to plot
scale = 5: the default scaling is 5
cv_colorspace_conversion_flag = cv.COLOR_BGR2RGB: colorspace conversion
"""
# tinkering with size
try:
img_height, img_width = img.shape[0], img.shape[1]
aspect_ratio = img_width / img_height
plt.figure(figsize=(scale, scale * aspect_ratio))
except AttributeError:
print(
"None Type image. Correct_syntax is, matplotlib_imshow(img_title, img, fig_h, cv_colorspace_conversion_flag)."
)
# actual code for displaying the image
plt.imshow(cv.cvtColor(img, cv_colorspace_conversion_flag))
plt.title(img_title)
plt.show()