質問編集履歴
2
参考として出力画像例を追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -214,4 +214,6 @@
|
|
214
214
|
|
215
215
|
Python3.8.5
|
216
216
|
|
217
|
-
|
217
|
+
出力画像のイメージです。(テスト的に6ファイルのみ表示。色がない画像も正常な結果です。)
|
218
|
+
|
219
|
+
![イメージ説明](4b561ed884204ec83cca1db3a3f6cf96.jpeg)
|
1
プログラムコードの記述先を修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,200 +14,192 @@
|
|
14
14
|
|
15
15
|
```
|
16
16
|
|
17
|
-
|
17
|
+
●下記は本件とは関係ないと思われますが、表示されるメッセージです。
|
18
|
+
|
19
|
+
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-twatanabe'
|
20
|
+
|
21
|
+
libGL error: No matching fbConfigs or visuals found
|
22
|
+
|
23
|
+
libGL error: failed to load driver: swrast
|
18
24
|
|
19
25
|
```
|
20
26
|
|
21
27
|
|
22
28
|
|
23
|
-
|
29
|
+
|
24
|
-
|
25
|
-
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-twatanabe'
|
26
|
-
|
27
|
-
libGL error: No matching fbConfigs or visuals found
|
28
|
-
|
29
|
-
libGL error: failed to load driver: swrast
|
30
30
|
|
31
31
|
|
32
32
|
|
33
33
|
### 該当のソースコード
|
34
34
|
|
35
|
-
```ここに言語
|
35
|
+
```ここに言語を入力
|
36
|
+
|
36
|
-
|
37
|
+
#取得した画像を表示して出力する(jpg等で保存する)。"
|
38
|
+
|
39
|
+
import gc
|
40
|
+
|
41
|
+
import math
|
42
|
+
|
43
|
+
import os
|
44
|
+
|
45
|
+
import numpy as np
|
46
|
+
|
47
|
+
import matplotlib as mpl
|
48
|
+
|
49
|
+
import matplotlib.pyplot as plt
|
50
|
+
|
51
|
+
import rasterio
|
52
|
+
|
53
|
+
from rasterio.enums import Resampling
|
54
|
+
|
55
|
+
from rasterio import plot
|
56
|
+
|
57
|
+
import glob
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
#ディレクトリ名やファイル名等の設定"
|
62
|
+
|
63
|
+
area_name = 'area'
|
64
|
+
|
65
|
+
direct_name = '/home/user/'
|
66
|
+
|
67
|
+
filename = "outoput_image"
|
68
|
+
|
69
|
+
output = direct_name+area_name+'/OUTPUT/'
|
70
|
+
|
71
|
+
data_path = input+'/DATA/'
|
72
|
+
|
73
|
+
ndpath = output+'IMAGE/NDVI/'
|
74
|
+
|
75
|
+
outpath = output+'RESULT/'
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
# フォルダが存在しない場合に作成する。"
|
80
|
+
|
81
|
+
def makepath(path):
|
82
|
+
|
83
|
+
if not os.path.exists(path):
|
84
|
+
|
85
|
+
os.makedirs(path)
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
# データ入力 (NDVIデータをまとめて読込む) (オリジナル画像:384×148 のGeoTiff画像が複数枚)"
|
90
|
+
|
91
|
+
data_files = glob.glob(ndpath+'*.tif')
|
92
|
+
|
93
|
+
data_files.sort()
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
# 画像サイズやリサンプリングを設定"
|
98
|
+
|
99
|
+
len_num = len(data_files)
|
100
|
+
|
101
|
+
col = 4
|
102
|
+
|
103
|
+
raw =math.ceil(len_num/col)
|
104
|
+
|
105
|
+
my_dpi = 96
|
106
|
+
|
107
|
+
im_col = 148 * (col*2)
|
108
|
+
|
109
|
+
im_raw = 384 *(col*3)
|
110
|
+
|
111
|
+
dwscale_factor = 1/2 #縮小サイズ)
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
# 出力キャンバスの設定"
|
116
|
+
|
117
|
+
fig = plt.figure(figsize=(int(im_raw/my_dpi),int(im_col/my_dpi)), dpi = my_dpi)
|
118
|
+
|
119
|
+
fig.clf()
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
# 画像の読込とリサンプリング"
|
124
|
+
|
125
|
+
for i in range(len_num):
|
126
|
+
|
127
|
+
with rasterio.open(data_files[i]) as src:
|
128
|
+
|
129
|
+
# resample data to target shape
|
130
|
+
|
131
|
+
data = src.read(
|
132
|
+
|
133
|
+
out_shape=(
|
134
|
+
|
135
|
+
src.count,
|
136
|
+
|
137
|
+
int(src.height * dwscale_factor),
|
138
|
+
|
139
|
+
int(src.width * dwscale_factor)
|
140
|
+
|
141
|
+
),
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
resampling=Resampling.bilinear #内挿方法
|
146
|
+
|
147
|
+
)
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
# scale image transform
|
152
|
+
|
153
|
+
transform = src.transform * src.transform.scale(
|
154
|
+
|
155
|
+
(src.width / data.shape[-1]),
|
156
|
+
|
157
|
+
(src.height / data.shape[-2])
|
158
|
+
|
159
|
+
)
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
# 画像のプロット位置をシフトさせ配置
|
164
|
+
|
165
|
+
plt.subplot(raw, col, i+1)
|
166
|
+
|
167
|
+
plt.imshow(data[0], clim=(-1, 1), cmap=cm.jet, interpolation='nearest')
|
168
|
+
|
169
|
+
plt.colorbar()
|
170
|
+
|
171
|
+
plt.title(data_files[i][-17:-4], fontsize=25)# ファイル名から日付を取得
|
172
|
+
|
173
|
+
plt.tight_layout()
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
# 画像の保尊
|
178
|
+
|
179
|
+
plt.savefig(outpath+filename+"_time_series_img.jpg", dpi=my_dpi)
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
# 画像表示
|
184
|
+
|
37
|
-
|
185
|
+
plt.show()
|
38
|
-
|
186
|
+
|
187
|
+
|
188
|
+
|
39
|
-
|
189
|
+
# メモリ開放
|
190
|
+
|
191
|
+
plt.cla()
|
192
|
+
|
193
|
+
fig.clf()
|
194
|
+
|
195
|
+
plt.close('all')
|
196
|
+
|
197
|
+
plt.close(fig)
|
198
|
+
|
199
|
+
gc.collect()
|
40
200
|
|
41
201
|
```
|
42
202
|
|
43
|
-
"#取得した画像を表示して出力する(jpg等で保存する)。"
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
import gc
|
48
|
-
|
49
|
-
import math
|
50
|
-
|
51
|
-
import os
|
52
|
-
|
53
|
-
import numpy as np
|
54
|
-
|
55
|
-
import matplotlib as mpl
|
56
|
-
|
57
|
-
import matplotlib.pyplot as plt
|
58
|
-
|
59
|
-
import rasterio
|
60
|
-
|
61
|
-
from rasterio.enums import Resampling
|
62
|
-
|
63
|
-
from rasterio import plot
|
64
|
-
|
65
|
-
import glob
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
"#ディレクトリ名やファイル名等の設定"
|
70
|
-
|
71
|
-
area_name = 'area'
|
72
|
-
|
73
|
-
direct_name = '/home/user/'
|
74
|
-
|
75
|
-
filename = "outoput_image"
|
76
|
-
|
77
|
-
output = direct_name+area_name+'/OUTPUT/'
|
78
|
-
|
79
|
-
data_path = input+'/DATA/'
|
80
|
-
|
81
|
-
ndpath = output+'IMAGE/NDVI/'
|
82
|
-
|
83
|
-
outpath = output+'RESULT/'
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
"# フォルダが存在しない場合に作成する。"
|
88
|
-
|
89
|
-
def makepath(path):
|
90
|
-
|
91
|
-
if not os.path.exists(path):
|
92
|
-
|
93
|
-
os.makedirs(path)
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
"# データ入力 (NDVIデータをまとめて読込む) (オリジナル画像:384×148 のGeoTiff画像が複数枚)"
|
98
|
-
|
99
|
-
data_files = glob.glob(ndpath+'*.tif')
|
100
|
-
|
101
|
-
data_files.sort()
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
"# 画像サイズやリサンプリングを設定"
|
106
|
-
|
107
|
-
len_num = len(data_files)
|
108
|
-
|
109
|
-
col = 4
|
110
|
-
|
111
|
-
raw =math.ceil(len_num/col)
|
112
|
-
|
113
|
-
my_dpi = 96
|
114
|
-
|
115
|
-
im_col = 148 * (col*2)
|
116
|
-
|
117
|
-
im_raw = 384 *(col*3)
|
118
|
-
|
119
|
-
dwscale_factor = 1/2 #縮小サイズ)
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
"# 出力キャンバスの設定"
|
124
|
-
|
125
|
-
fig = plt.figure(figsize=(int(im_raw/my_dpi),int(im_col/my_dpi)), dpi = my_dpi)
|
126
|
-
|
127
|
-
fig.clf()
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
"# 画像の読込とリサンプリング"
|
132
|
-
|
133
|
-
for i in range(len_num):
|
134
|
-
|
135
|
-
with rasterio.open(data_files[i]) as src:
|
136
|
-
|
137
|
-
”# resample data to target shape
|
138
|
-
|
139
|
-
data = src.read(
|
140
|
-
|
141
|
-
out_shape=(
|
142
|
-
|
143
|
-
src.count,
|
144
|
-
|
145
|
-
int(src.height * dwscale_factor),
|
146
|
-
|
147
|
-
int(src.width * dwscale_factor)
|
148
|
-
|
149
|
-
),
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
resampling=Resampling.bilinear #内挿方法
|
154
|
-
|
155
|
-
)
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
"# scale image transform
|
160
|
-
|
161
|
-
transform = src.transform * src.transform.scale(
|
162
|
-
|
163
|
-
(src.width / data.shape[-1]),
|
164
|
-
|
165
|
-
(src.height / data.shape[-2])
|
166
|
-
|
167
|
-
)
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
"# 画像のプロット位置をシフトさせ配置
|
172
|
-
|
173
|
-
plt.subplot(raw, col, i+1)
|
174
|
-
|
175
|
-
plt.imshow(data[0], clim=(-1, 1), cmap=cm.jet, interpolation='nearest')
|
176
|
-
|
177
|
-
plt.colorbar()
|
178
|
-
|
179
|
-
plt.title(data_files[i][-17:-4], fontsize=25)# ファイル名から日付を取得
|
180
|
-
|
181
|
-
plt.tight_layout()
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
"# 画像の保尊
|
186
|
-
|
187
|
-
plt.savefig(outpath+filename+"_time_series_img.jpg", dpi=my_dpi)
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
"# 画像表示
|
192
|
-
|
193
|
-
plt.show()
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
"# メモリ開放
|
198
|
-
|
199
|
-
plt.cla()
|
200
|
-
|
201
|
-
fig.clf()
|
202
|
-
|
203
|
-
plt.close('all')
|
204
|
-
|
205
|
-
plt.close(fig)
|
206
|
-
|
207
|
-
gc.collect()
|
208
|
-
|
209
|
-
|
210
|
-
|
211
203
|
|
212
204
|
|
213
205
|
### 試したこと
|