teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

5

写真の追加

2021/12/20 00:59

投稿

Deep_passion
Deep_passion

スコア47

title CHANGED
File without changes
body CHANGED
@@ -86,4 +86,7 @@
86
86
  [こちらに複数のやりかたってかいてあるので、その通りにやっています。](https://note.nkmk.me/en/python-numpy-image-processing/)
87
87
 
88
88
 
89
- ![イメージ説明](02d7381ece0bf28cf7bd68a37f62a080.png)
89
+ ![イメージ説明](02d7381ece0bf28cf7bd68a37f62a080.png)
90
+
91
+ 4,melianさんへの返信
92
+ ![イメージ説明](ffcda7591c321cc97e9b5fb0677ef3b8.png)

4

コードの変更

2021/12/20 00:59

投稿

Deep_passion
Deep_passion

スコア47

title CHANGED
File without changes
body CHANGED
@@ -37,18 +37,16 @@
37
37
 
38
38
  ```ここに言語名を入力
39
39
 
40
- from glob import glob
41
40
 
42
- A=glob('/content/drive/MyDrive/神様/sartorius-inserted/train_masks_npz/*.npz')
43
-
44
-
45
-
46
41
  for idx, f in enumerate(A):
47
42
  from PIL import Image
43
+ # f = np.asarray(f)
44
+ # f = Image.fromarray(f.astype('uint8'))
45
+ f=np.load(f)
46
+
48
- im = Image.fromarray(f) #ここでエラーがでます。
47
+ f = Image.fromarray(f.astype(np.uint8))
49
-    im.save(f"/content/drive/MyDrive/神様/sartorius-inserted/train_sample_npy_to_pnp/{f[-16:-4]}.jpeg")
48
+ im.save(f"/content/drive/MyDrive/神様/sartorius-inserted/train_sample_npy_to_pnp/{f[-16:-4]}.jpeg")
50
49
 
51
-
52
50
  ```
53
51
 
54
52
  ### 補足情報(FW/ツールのバージョンなど)

3

文字追加

2021/12/20 00:54

投稿

Deep_passion
Deep_passion

スコア47

title CHANGED
@@ -1,1 +1,1 @@
1
- npzから、pngに直したい次第です。
1
+ npzから、pngに直したい次第です。(編集済み)
body CHANGED
@@ -80,4 +80,12 @@
80
80
 
81
81
  ```
82
82
  2,
83
- [rgbで変化なしです。](https://stackoverflow.com/questions/43229482/image-fromarray-cannot-be-used-with-array-array)
83
+ [rgbで変化なしです。](https://stackoverflow.com/questions/43229482/image-fromarray-cannot-be-used-with-array-array)
84
+
85
+
86
+ 3,
87
+
88
+ [こちらに複数のやりかたってかいてあるので、その通りにやっています。](https://note.nkmk.me/en/python-numpy-image-processing/)
89
+
90
+
91
+ ![イメージ説明](02d7381ece0bf28cf7bd68a37f62a080.png)

2

文字追加

2021/12/20 00:53

投稿

Deep_passion
Deep_passion

スコア47

title CHANGED
File without changes
body CHANGED
@@ -77,4 +77,7 @@
77
77
  2706 ndim = len(shape)
78
78
 
79
79
  AttributeError: 'NpzFile' object has no attribute '__array_interface__'
80
+
80
- ```
81
+ ```
82
+ 2,
83
+ [rgbで変化なしです。](https://stackoverflow.com/questions/43229482/image-fromarray-cannot-be-used-with-array-array)

1

文字追加

2021/12/20 00:38

投稿

Deep_passion
Deep_passion

スコア47

title CHANGED
File without changes
body CHANGED
@@ -56,4 +56,25 @@
56
56
  ここにより詳細な情報を記載してください。
57
57
 
58
58
  Python3 (3.7.4)
59
- macbookpro 16
59
+ macbookpro 16
60
+
61
+ 1,
62
+
63
+ ```np.loadを追加後
64
+ ---------------------------------------------------------------------------
65
+ AttributeError Traceback (most recent call last)
66
+ <ipython-input-37-df6ebf7b8628> in <module>()
67
+ 5 # f = Image.fromarray(f.astype('uint8'))
68
+ 6 f=np.load(f)
69
+ ----> 7 f = Image.fromarray(f)
70
+ 8 print(f)
71
+
72
+ /usr/local/lib/python3.7/dist-packages/PIL/Image.py in fromarray(obj, mode)
73
+ 2702 .. versionadded:: 1.1.6
74
+ 2703 """
75
+ -> 2704 arr = obj.__array_interface__
76
+ 2705 shape = arr["shape"]
77
+ 2706 ndim = len(shape)
78
+
79
+ AttributeError: 'NpzFile' object has no attribute '__array_interface__'
80
+ ```