|
17 | 17 | parser.add_argument('-f', '--file', |
18 | 18 | help='Path to video file (if not using camera)') |
19 | 19 | parser.add_argument('-c', '--color', type=str, default='gray', |
20 | | - help='Color space: "gray" (default) or "rgb"') |
| 20 | + help='Color space: "gray" (default), "rgb", or "lab"') |
21 | 21 | parser.add_argument('-b', '--bins', type=int, default=16, |
22 | 22 | help='Number of bins per channel (default 16)') |
23 | 23 | parser.add_argument('-w', '--width', type=int, default=0, |
|
38 | 38 | fig, ax = plt.subplots() |
39 | 39 | if color == 'rgb': |
40 | 40 | ax.set_title('Histogram (RGB)') |
| 41 | +elif color == 'lab': |
| 42 | + ax.set_title('Histogram (L*a*b*)') |
41 | 43 | else: |
42 | 44 | ax.set_title('Histogram (grayscale)') |
43 | 45 | ax.set_xlabel('Bin') |
|
47 | 49 | lw = 3 |
48 | 50 | alpha = 0.5 |
49 | 51 | if color == 'rgb': |
50 | | - lineR, = ax.plot(np.arange(bins), np.zeros((bins,)), c='r', lw=lw, alpha=alpha) |
51 | | - lineG, = ax.plot(np.arange(bins), np.zeros((bins,)), c='g', lw=lw, alpha=alpha) |
52 | | - lineB, = ax.plot(np.arange(bins), np.zeros((bins,)), c='b', lw=lw, alpha=alpha) |
| 52 | + lineR, = ax.plot(np.arange(bins), np.zeros((bins,)), c='r', lw=lw, alpha=alpha, label='Red') |
| 53 | + lineG, = ax.plot(np.arange(bins), np.zeros((bins,)), c='g', lw=lw, alpha=alpha, label='Green') |
| 54 | + lineB, = ax.plot(np.arange(bins), np.zeros((bins,)), c='b', lw=lw, alpha=alpha, label='Blue') |
| 55 | +elif color == 'lab': |
| 56 | + lineL, = ax.plot(np.arange(bins), np.zeros((bins,)), c='k', lw=lw, alpha=alpha, label='L*') |
| 57 | + lineA, = ax.plot(np.arange(bins), np.zeros((bins,)), c='b', lw=lw, alpha=alpha, label='a*') |
| 58 | + lineB, = ax.plot(np.arange(bins), np.zeros((bins,)), c='y', lw=lw, alpha=alpha, label='b*') |
53 | 59 | else: |
54 | | - lineGray, = ax.plot(np.arange(bins), np.zeros((bins,1)), c='k', lw=lw) |
| 60 | + lineGray, = ax.plot(np.arange(bins), np.zeros((bins,1)), c='k', lw=lw, label='intensity') |
55 | 61 | ax.set_xlim(0, bins-1) |
56 | 62 | ax.set_ylim(0, 1) |
| 63 | +ax.legend() |
57 | 64 | plt.ion() |
58 | 65 | plt.show() |
59 | 66 |
|
|
82 | 89 | lineR.set_ydata(histogramR) |
83 | 90 | lineG.set_ydata(histogramG) |
84 | 91 | lineB.set_ydata(histogramB) |
| 92 | + elif color == 'lab': |
| 93 | + cv2.imshow('L*a*b*', frame) |
| 94 | + lab = cv2.cvtColor(frame, cv2.COLOR_BGR2LAB) |
| 95 | + (l, a, b) = cv2.split(lab) |
| 96 | + histogramL = cv2.calcHist([l], [0], None, [bins], [0, 255]) / numPixels |
| 97 | + histogramA = cv2.calcHist([a], [0], None, [bins], [0, 255]) / numPixels |
| 98 | + histogramB = cv2.calcHist([b], [0], None, [bins], [0, 255]) / numPixels |
| 99 | + lineL.set_ydata(histogramL) |
| 100 | + lineA.set_ydata(histogramA) |
| 101 | + lineB.set_ydata(histogramB) |
85 | 102 | else: |
86 | 103 | gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) |
87 | 104 | cv2.imshow('Grayscale', gray) |
|
0 commit comments