回答編集履歴

1

プログラムを追記

2021/07/05 12:31

投稿

Bull
Bull

スコア986

test CHANGED
@@ -27,3 +27,61 @@
27
27
  ```
28
28
 
29
29
  としてみてはどうでしょうか?
30
+
31
+
32
+
33
+ ---
34
+
35
+ 以下追記
36
+
37
+
38
+
39
+ 当方の環境 (Windows10/Python 3.8.10) で数カ所の修正で正常動作を確認しました。
40
+
41
+ ```Python
42
+
43
+ import cv2
44
+
45
+ import numpy as np
46
+
47
+ from matplotlib import pyplot as plt
48
+
49
+
50
+
51
+ def main():
52
+
53
+ img = cv2.imread(r"C:\2020-03\IMG_2052.JPG")
54
+
55
+
56
+
57
+ gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
58
+
59
+
60
+
61
+ hist, bins = np.histogram(gray.ravel(),256,[0,256])
62
+
63
+
64
+
65
+ print(hist)
66
+
67
+
68
+
69
+ plt.xlim(0,255)
70
+
71
+ plt.plot(hist)
72
+
73
+ plt.xlabel("pixel value", fontsize=20)
74
+
75
+ plt.ylabel("Number of pixels", fontsize=20)
76
+
77
+ plt.grid()
78
+
79
+ plt.show()
80
+
81
+
82
+
83
+ if __name__ == "__main__":
84
+
85
+ main()
86
+
87
+ ```