Skip to content

Commit 41c31f9

Browse files
committed
[Feat] Add HSI support #10
1 parent 4b3c81e commit 41c31f9

File tree

3 files changed

+66
-33
lines changed

3 files changed

+66
-33
lines changed

deep-learning-datasets-maker/split_rs_data.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ def run(self):
278278
vlayers = QgsProject.instance().mapLayersByName(currentvectorlay)
279279
fn_vec = vlayers[0]
280280
SplittingSize = int(self.dlg.comboBoxImgSize.currentText())
281+
standard_output = self.dlg.checkBoxStandard.isChecked()
281282

282283
# Log for files
283284
ras_path = str(fn_ras.dataProvider().dataSourceUri())
@@ -324,22 +325,22 @@ def mkdir_p(path):
324325
splitting(
325326
fn_ras_path,
326327
image_Paddle_path,
327-
"jpg",
328-
"JPEG",
329328
"",
330329
SplittingSize,
331330
SplittingSize,
332331
currentrasterlay,
332+
"IMG",
333+
standard_output
333334
)
334335
splitting(
335336
output,
336337
label_Paddle_path,
337-
"png",
338-
"PNG",
339338
"",
340339
SplittingSize,
341340
SplittingSize,
342341
currentrasterlay,
342+
"LAB",
343+
standard_output
343344
) # should be the same name of image. vector name if needed-> currentvectorlay
344345

345346
# ** Ins Seg with OPENCV **
@@ -377,12 +378,12 @@ def mkdir_p(path):
377378
splitting(
378379
InsSegGDALout,
379380
InSeg_Paddle_path,
380-
"png",
381-
"PNG",
382381
"",
383382
SplittingSize,
384383
SplittingSize,
385384
currentrasterlay,
385+
"LAB",
386+
standard_output
386387
)
387388
iface.addRasterLayer(
388389
InsSegGDALout, "deepbands-datasets-InsSeg")

deep-learning-datasets-maker/split_rs_data_dialog_base.ui

+30-17
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>440</width>
9+
<width>460</width>
1010
<height>410</height>
1111
</rect>
1212
</property>
@@ -18,13 +18,13 @@
1818
</property>
1919
<property name="minimumSize">
2020
<size>
21-
<width>440</width>
21+
<width>460</width>
2222
<height>410</height>
2323
</size>
2424
</property>
2525
<property name="maximumSize">
2626
<size>
27-
<width>440</width>
27+
<width>460</width>
2828
<height>410</height>
2929
</size>
3030
</property>
@@ -38,7 +38,7 @@
3838
<widget class="QLabel" name="label">
3939
<property name="minimumSize">
4040
<size>
41-
<width>176</width>
41+
<width>190</width>
4242
<height>0</height>
4343
</size>
4444
</property>
@@ -63,13 +63,13 @@
6363
</property>
6464
<property name="minimumSize">
6565
<size>
66-
<width>230</width>
66+
<width>239</width>
6767
<height>27</height>
6868
</size>
6969
</property>
7070
<property name="maximumSize">
7171
<size>
72-
<width>230</width>
72+
<width>239</width>
7373
<height>16777215</height>
7474
</size>
7575
</property>
@@ -83,7 +83,7 @@
8383
<widget class="QLabel" name="label_2">
8484
<property name="minimumSize">
8585
<size>
86-
<width>176</width>
86+
<width>190</width>
8787
<height>0</height>
8888
</size>
8989
</property>
@@ -108,13 +108,13 @@
108108
</property>
109109
<property name="minimumSize">
110110
<size>
111-
<width>230</width>
111+
<width>239</width>
112112
<height>27</height>
113113
</size>
114114
</property>
115115
<property name="maximumSize">
116116
<size>
117-
<width>230</width>
117+
<width>239</width>
118118
<height>16777215</height>
119119
</size>
120120
</property>
@@ -128,7 +128,7 @@
128128
<widget class="QLabel" name="label_3">
129129
<property name="minimumSize">
130130
<size>
131-
<width>176</width>
131+
<width>190</width>
132132
<height>16</height>
133133
</size>
134134
</property>
@@ -189,7 +189,7 @@
189189
<widget class="QLabel" name="label_5">
190190
<property name="minimumSize">
191191
<size>
192-
<width>176</width>
192+
<width>190</width>
193193
<height>0</height>
194194
</size>
195195
</property>
@@ -230,6 +230,19 @@
230230
</property>
231231
</widget>
232232
</item>
233+
<item>
234+
<widget class="QCheckBox" name="checkBoxStandard">
235+
<property name="enabled">
236+
<bool>true</bool>
237+
</property>
238+
<property name="text">
239+
<string>Save as U8C3/1</string>
240+
</property>
241+
<property name="checked">
242+
<bool>true</bool>
243+
</property>
244+
</widget>
245+
</item>
233246
<item>
234247
<widget class="QCheckBox" name="checkBoxPaddle">
235248
<property name="enabled">
@@ -249,13 +262,13 @@
249262
</property>
250263
<property name="minimumSize">
251264
<size>
252-
<width>176</width>
265+
<width>90</width>
253266
<height>0</height>
254267
</size>
255268
</property>
256269
<property name="maximumSize">
257270
<size>
258-
<width>176</width>
271+
<width>90</width>
259272
<height>16777215</height>
260273
</size>
261274
</property>
@@ -282,13 +295,13 @@
282295
<widget class="QLabel" name="label_9">
283296
<property name="minimumSize">
284297
<size>
285-
<width>176</width>
298+
<width>90</width>
286299
<height>0</height>
287300
</size>
288301
</property>
289302
<property name="maximumSize">
290303
<size>
291-
<width>176</width>
304+
<width>90</width>
292305
<height>16777215</height>
293306
</size>
294307
</property>
@@ -312,13 +325,13 @@
312325
<widget class="QLabel" name="label_10">
313326
<property name="minimumSize">
314327
<size>
315-
<width>176</width>
328+
<width>90</width>
316329
<height>0</height>
317330
</size>
318331
</property>
319332
<property name="maximumSize">
320333
<size>
321-
<width>176</width>
334+
<width>90</width>
322335
<height>16777215</height>
323336
</size>
324337
</property>

deep-learning-datasets-maker/utils/splitting.py

+29-10
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,30 @@
77
import math
88

99
# Start Splitting
10-
def splitting(fn_ras, cdpath, frmt_ext, imgfrmat, scaleoptions, needed_out_x, needed_out_y, file_name):
10+
def splitting(fn_ras,
11+
cdpath,
12+
scaleoptions,
13+
needed_out_x,
14+
needed_out_y,
15+
file_name,
16+
mode="IMG",
17+
standard=True):
1118
ds = gdal.Open(fn_ras)
1219
gt = ds.GetGeoTransform()
1320

21+
options = { "outputType": gdal.GDT_Byte }
22+
frmt_ext = osp.splitext(osp.basename(fn_ras))[-1].replace(".", "")
23+
if mode == "IMG":
24+
if not standard:
25+
options["outputType"] = ds.GetRasterBand(1).DataType
26+
else:
27+
options["format"] = "JPEG"
28+
frmt_ext = "jpg"
29+
else:
30+
if standard:
31+
options["format"] = "PNG"
32+
frmt_ext = "png"
33+
1434
# get coordinates of upper left corner
1535
xmin = gt[0]
1636
ymax = gt[3]
@@ -48,15 +68,14 @@ def splitting(fn_ras, cdpath, frmt_ext, imgfrmat, scaleoptions, needed_out_x, ne
4868
# outputBounds = (xmin, ymin, xmax, ymax), dstNodata = -9999)
4969

5070
# or gdal translate to subset the input raster
51-
gdal.Translate(osp.join(cdpath, \
52-
(str(file_name) + "-" + str(j) + "-" + str(i) + "." + frmt_ext)),
53-
ds,
54-
projWin=(abs(xmin), abs(ymax), abs(xmax), abs(ymin)),
55-
xRes=resx,
56-
yRes=-resy,
57-
outputType=gdal.gdalconst.GDT_Byte,
58-
format=imgfrmat,
59-
scaleParams=[[scaleoptions]])
71+
gdal.Translate(
72+
osp.join(cdpath, (str(file_name) + "-" + str(j) + "-" + str(i) + "." + frmt_ext)),
73+
ds,
74+
projWin=(abs(xmin), abs(ymax), abs(xmax), abs(ymin)),
75+
xRes=resx,
76+
yRes=-resy,
77+
scaleParams=[[scaleoptions]],
78+
**options)
6079

6180
# close the open dataset!!!
6281
ds = None

0 commit comments

Comments
 (0)