回答編集履歴
2
d
answer
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
以下のステップで float 型の (H, W) の numpy 配列を uint16 型に変換してから保存してください。
|
4
4
|
|
5
|
-
1. [src.min(), src.max()] -> [0,
|
5
|
+
1. [src.min(), src.max()] -> [0, 2000] にスケールする。
|
6
6
|
2. uint16 にキャストする。
|
7
7
|
3. cv2.imwrite で保存する。
|
8
8
|
|
@@ -14,7 +14,7 @@
|
|
14
14
|
src = np.random.uniform(0, 1, (100, 100))
|
15
15
|
print(src.dtype, src.shape) # float64 (100, 100)
|
16
16
|
|
17
|
-
# [src.min(), src.max()] -> [0,
|
17
|
+
# [src.min(), src.max()] -> [0, 2000] にスケールする。
|
18
18
|
dst = np.interp(src, (src.min(), src.max()), (0, 2000))
|
19
19
|
dst = dst.astype(np.uint16) # float -> uint16
|
20
20
|
|
1
d
answer
CHANGED
@@ -15,9 +15,7 @@
|
|
15
15
|
print(src.dtype, src.shape) # float64 (100, 100)
|
16
16
|
|
17
17
|
# [src.min(), src.max()] -> [0, 65535] にスケールする。
|
18
|
-
dst = np.interp(
|
19
|
-
|
18
|
+
dst = np.interp(src, (src.min(), src.max()), (0, 2000))
|
20
|
-
)
|
21
19
|
dst = dst.astype(np.uint16) # float -> uint16
|
22
20
|
|
23
21
|
# 保存する。
|
@@ -26,4 +24,6 @@
|
|
26
24
|
# 読み込む。
|
27
25
|
src = cv2.imread("result.png", cv2.IMREAD_ANYDEPTH | cv2.IMREAD_ANYCOLOR)
|
28
26
|
print(src.dtype, src.shape) # uint16 (100, 100)
|
27
|
+
|
28
|
+
print(dst.min(), dst.max())
|
29
29
|
```
|