-
Notifications
You must be signed in to change notification settings - Fork 0
/
auxiliary.py
48 lines (41 loc) · 1.22 KB
/
auxiliary.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
40
41
42
43
44
45
46
47
import matplotlib.pyplot as plt
import numpy as np
def plot_hists(img, plt):
"""
Plota o histograma de cada um dos canais RGB
img - imagem RGB
plt - objeto matplotlib
"""
plt.figure(figsize=(20,10));
img_h = img[:,:,0]
img_s = img[:,:,1]
img_v = img[:,:,2]
histo_plot(img_h, "r","R", plt);
histo_plot(img_s, "g","G", plt);
histo_plot(img_v, "b","B", plt);
def make_hist(img_255, c, label, plt):
""" img_255 - uma imagem com 3 canais de 0 até 255
c a cor do plot
label - o label do gráfico
plt - matplotlib.pyplot
"""
hist,bins = np.histogram(img_255.flatten(),256,[0,256])
cdf = hist.cumsum()
cdf_normalized = cdf * hist.max()/ cdf.max()
# plt.plot(cdf_normalized, color = c)
plt.hist(img_255.flatten(),256,[0,256], color = c)
plt.xlim([0,256])
plt.legend(label, loc = 'upper left')
plt.plot()
def histo_plot(img, cor, label, plt):
"""
img - imagem
cor - cor
plt - matplotlib.pyplot object
"""
plt.figure(figsize=(10,5))
make_hist(img, cor, label, plt)
plt.show()
plt.figure(figsize=(10,5))
plt.imshow(img, cmap="Greys_r")#, vmin=0, vmax=255)
plt.title(label)