回答編集履歴
4
Browの比較を追記
answer
CHANGED
|
File without changes
|
3
Browの比較を追記
answer
CHANGED
|
@@ -1,3 +1,56 @@
|
|
|
1
|
+
追記)
|
|
2
|
+
|
|
3
|
+
**1. 以下の写真を"img_green_masked.jpeg"と名前を付けて保存してください。**
|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
**2. 画像と同じフォルダに以下のファイルを(適当な名前).pyと名前を付けて保存して走らせてください。**
|
|
7
|
+
```Python3
|
|
8
|
+
import cv2
|
|
9
|
+
import numpy as np
|
|
10
|
+
|
|
11
|
+
from scipy import stats
|
|
12
|
+
|
|
13
|
+
def calc_Bmode(img):
|
|
14
|
+
if len(img.shape)==3:
|
|
15
|
+
print(img.shape,"--> ",end="")
|
|
16
|
+
BGR = cv2.split(img_col)
|
|
17
|
+
img = BGR[0]
|
|
18
|
+
print(img.shape)
|
|
19
|
+
else:
|
|
20
|
+
print(img.shape)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
Brow = np.array(img).flatten()
|
|
24
|
+
Bmode = stats.mode(Brow[Brow>0])[0][0]
|
|
25
|
+
print("Bmode", Bmode)
|
|
26
|
+
img_col =cv2.imread("./img_green_masked.jpeg")
|
|
27
|
+
|
|
28
|
+
BGR = cv2.split(img_col)
|
|
29
|
+
Blue = BGR[0]
|
|
30
|
+
|
|
31
|
+
print("---一旦保存法---")
|
|
32
|
+
cv2.imwrite("./blue.jpeg",Blue)
|
|
33
|
+
img_blue_loaded = cv2.imread("./blue.jpeg")
|
|
34
|
+
calc_Bmode(img_blue_loaded)
|
|
35
|
+
cv2.imshow("img_blue_loaded",cv2.resize(img_blue_loaded,None,fx=0.25,fy=0.25))
|
|
36
|
+
cv2.waitKey(0)
|
|
37
|
+
|
|
38
|
+
print("---色の分解法---")
|
|
39
|
+
calc_Bmode(Blue)
|
|
40
|
+
|
|
41
|
+
cv2.imshow("Blue",cv2.resize(Blue,None,fx=0.25,fy=0.25))
|
|
42
|
+
|
|
43
|
+
cv2.waitKey(0)
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**3. 表示される画像に「識別文字」は見えますね?**
|
|
48
|
+
** =(別のファイルを間違えて開いている可能性は排除できますね?**
|
|
49
|
+
|
|
50
|
+
**4. どちらの方法でも同じBmodeになっていますか?**
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
1
54
|
~~元のファイルと少し違うようで値が違いますができました。~~
|
|
2
55
|
1以上の~を修正しました。
|
|
3
56
|
22となるのはNumpyだとかScipyのせいではなさそうな気がします。
|
2
1以上の件
answer
CHANGED
|
@@ -1,15 +1,33 @@
|
|
|
1
|
-
元のファイルと少し違うようで値が違いますができました。
|
|
1
|
+
~~元のファイルと少し違うようで値が違いますができました。~~
|
|
2
|
+
1以上の~を修正しました。
|
|
3
|
+
22となるのはNumpyだとかScipyのせいではなさそうな気がします。
|
|
4
|
+
(イメージの指定違い?)
|
|
5
|
+
|
|
6
|
+
---
|
|
2
7
|
```Python3
|
|
3
8
|
import cv2
|
|
4
9
|
import numpy as np
|
|
5
10
|
|
|
11
|
+
from scipy import stats
|
|
12
|
+
|
|
6
13
|
img = cv2.cvtColor(cv2.imread("./img.png"),cv2.COLOR_BGR2GRAY)
|
|
14
|
+
|
|
15
|
+
print("1以上の条件なし Numpy")
|
|
7
16
|
arr, count = np.unique(img, return_counts=True)
|
|
8
17
|
idx = np.argmax(count)
|
|
9
|
-
print("Maximum index:",arr[idx])
|
|
18
|
+
print("Maximum index[RAW]:",arr[idx])
|
|
10
|
-
print("Count:
|
|
19
|
+
print("Count: [RAW] ",count[idx])
|
|
20
|
+
# print(count)
|
|
21
|
+
|
|
22
|
+
print("1以上の条件あり Numpy")
|
|
23
|
+
arr, count = arr[1:], count[1:]
|
|
24
|
+
idx = np.argmax(count)
|
|
25
|
+
print("Maximum index: ",arr[idx])
|
|
26
|
+
print("Count: ",count[idx])
|
|
27
|
+
|
|
28
|
+
print("1以上の条件あり Scipy")
|
|
29
|
+
Bmode = stats.mode(img[img>0])[0][0]
|
|
30
|
+
print(Bmode)
|
|
31
|
+
|
|
11
32
|
```
|
|
12
|
-

|
|
33
|
+

|
|
13
|
-
|
|
14
|
-
---
|
|
15
|
-
`Bmode = stats.mode(img)[0][0] `という風にやると、171x231ピクセルの画像の171側に対して集計してしまうのでおかしなことになるようです。もし`stats.mode`をするのであれば、`Bmode = stats.mode(img.flatten())`のように一列につらつらとピクセルが並ぶようにしてください。
|
1
stats追加
answer
CHANGED
|
@@ -9,4 +9,7 @@
|
|
|
9
9
|
print("Maximum index:",arr[idx])
|
|
10
10
|
print("Count: ",count[idx])
|
|
11
11
|
```
|
|
12
|
-

|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
`Bmode = stats.mode(img)[0][0] `という風にやると、171x231ピクセルの画像の171側に対して集計してしまうのでおかしなことになるようです。もし`stats.mode`をするのであれば、`Bmode = stats.mode(img.flatten())`のように一列につらつらとピクセルが並ぶようにしてください。
|