-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
108 lines (78 loc) · 2.55 KB
/
plot.py
File metadata and controls
108 lines (78 loc) · 2.55 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import matplotlib.pyplot as plt
import numpy as np
import cv2
from .morphology import*
def imshow(imgIn):
plt.imshow(cv2.cvtColor(imgIn, cv2.COLOR_BGR2RGB))
plt.show()
def imshowCVFig(figNum, imgIn):
plt.figure(figNum)
plt.imshow(cv2.cvtColor(imgIn, cv2.COLOR_BGR2RGB))
plt.show()
def plotshow_cvt(img):
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
def sumPixelAndPlot(imgToSum,maxIntense,rowOrCol):
# sumRow = np.sum(myMet_grey_inv,axis=1)
matImgOne = imgToSum.copy()
# matImgOne[matImgOne > 0] = 1
sumRow = np.sum(matImgOne,axis=1)
# print(sumRow.shape)
# sumCol = np.sum(myMet_grey_inv,axis=0)
sumCol = np.sum(matImgOne,axis=0)
# print(sumCol.shape)
# imshowCV(imgToSum)
# plt.plot(np.arange(len(sumRow))+1,sumRow,'b-',np.arange(len(sumCol))+1,sumCol,'r-')
if rowOrCol == 'row':
plt.plot(np.arange(len(sumRow))+1,sumRow,'b-')
plt.legend(['sumRow'])
elif rowOrCol == 'col':
plt.plot(np.arange(len(sumCol))+1,sumCol,'b-')
plt.legend(['sumCol'])
return sumRow, sumCol
def sumRowCol(imgToSum, norm = False, plot = True):
'''
imgToSum = binary image
'''
matImgOne = imgToSum.copy()
if norm:
matImgOne[matImgOne > 0] = 1
imgShape = imgToSum.shape
nrow = imgShape[0]
ncol = imgShape[1]
sumRow = np.sum(matImgOne,axis=1) / ncol
sumCol = np.sum(matImgOne,axis=0) / nrow
else:
sumRow = np.sum(matImgOne,axis=1)
sumCol = np.sum(matImgOne,axis=0)
if plot:
plt.figure()
plt.plot(np.arange(len(sumRow))+1,sumRow,'b-')
plt.legend(['sumRow'])
# elif rowOrCol == 'col':
plt.figure()
plt.plot(np.arange(len(sumCol))+1,sumCol,'r-')
plt.legend(['sumCol'])
return sumRow, sumCol
def plotArrayDiff(arr, arrTH = 0):
arrDiff = np.diff(arr)
plt.plot(arrDiff)
plt.show()
return arrDiff
def plotThresholdAndDiff(arr, arrTH):
arrDiff, arrThresholded = thresholdAndDiff(arr, arrTH)
plt.figure()
plt.plot(arrThresholded)
plt.figure()
plt.plot(arrDiff)
def plotHist(img,nbins,densityType):
mn=img.shape[0]*img.shape[1]
arrIntense = img.reshape((1,mn))
histShade = np.histogram(arrIntense, bins=nbins, range=None, normed=None, weights=None,density=densityType)
plt.plot(histShade[1][0:nbins],histShade[0])
plt.show()
def plotDiffSq(arrIn):
arrDiff = np.diff(arrIn)
arrSq = np.power(arrDiff,2)
plt.plot(arrSq)
plt.show()
return arrSq