-
Notifications
You must be signed in to change notification settings - Fork 0
/
histograms
34 lines (22 loc) · 925 Bytes
/
histograms
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
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.image as mpimg
"""Takes binary images as inputs. Calculates the frequency histograms (both horizontal and vertical)
Should be used after cutting away the major areas of noise (use on smaller images)"""
image = "Binary.png" # your input image should be white text on black background
binary = mpimg.imread(image) # collection of lists
fig = plt.figure()
a = fig.add_subplot(1, 2, 1)
print binary
print binary.shape # y, x (in dims)
# want to compute the sum along the y-dim
sum1 = np.sum(binary, axis=1)
plt.title("Horizontal Frequencies")
plt.plot(sum1) # this gives the histogram for horizontal direction (->), with y varying
a = fig.add_subplot(1, 2, 2)
plt.title("Vertical Frequencies")
sum2 = np.sum(binary, axis=0) # get the histogram for ^ dim, vertical, with x varying
plt.plot(sum2)
plt.show()