emilyveenhuis commited on
Commit
19f7005
1 Parent(s): d9d2139

Modify layout

Browse files

Use VisDrone config

README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
  title: NRTK-Gradio
3
- emoji: 🕵️‍♂️
4
- colorFrom: purple
5
- colorTo: blue
6
  sdk: gradio
7
  sdk_version: 4.13.0
8
  app_file: app.py
 
1
  ---
2
  title: NRTK-Gradio
3
+ emoji: 📷
4
+ colorFrom: blue
5
+ colorTo: green
6
  sdk: gradio
7
  sdk_version: 4.13.0
8
  app_file: app.py
app.py CHANGED
@@ -10,38 +10,42 @@ from nrtk.impls.perturb_image.pybsm.perturber import PybsmPerturber
10
 
11
  import gradio as gr # type: ignore
12
 
 
 
 
 
13
  # Define default values for fields for initilization and button clicks
14
  #
15
- # Note, for this application we'll be focusing on the use case of satellite imagery, so we'll try to pick default
16
- # values that work with images similar to those in the xView dataset. Perturbing images from other datasets or other
17
  # operational tasks may not be successful without modification to these values; defining broad defaults is extremely
18
  # difficult, if not impossible due to the physics-based nature of these perturbations.
19
  default_values = {
20
- "gsd": 0.3,
21
  "scenario": {
22
- "aircraftSpeed": 100.,
23
- "altitude": 4000.,
24
  "backgroundReflectance": 0.07,
25
  "backgroundTemperature": 293.,
26
- "cn2at1m": 1.7e-14,
27
- "groundRange": 1000,
28
  "haWindspeed": 21.,
29
- "ihaze": 1,
30
  "name": "",
31
  "targetReflectance": 0.15,
32
  "targetTemperature": 295.,
33
  },
34
  "sensor": {
35
- "D": .029,
36
  "bitdepth": 11.9,
37
  "darkCurrent": 0.,
38
  "dax": 0.0001,
39
  "day": 0.0001,
40
  "eta": 0.4,
41
- "f": .27,
42
  "intTime": 0.03,
43
  "maxN": 96000,
44
- "maxWellFill": 0.6,
45
  "name": "",
46
  "optTransWavelengths": [3.8e-07, 7.0e-07],
47
  "opticsTransmission": [],
@@ -226,42 +230,43 @@ def submit(data):
226
  scenario = PybsmScenario(**scenario_config)
227
  perturber = PybsmPerturber(sensor=sensor, scenario=scenario)
228
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
  # Apply the perturbation and display
230
  return {
231
- output_col: gr.Column(visible=True),
232
- out_img: perturber(image=data[input_img], additional_params={"img_gsd": gsd})
233
  }
234
 
235
 
236
- def save(data):
237
- """
238
- Saves current configuration at given path
239
- """
240
- if not data[file_path]:
241
- raise gr.Error("A filename must be provided to save the configuration!")
242
- path = Path(data[file_path])
243
- path.parent.mkdir(parents=True, exist_ok=True)
244
- config = generate_config(data)
245
- with open(path, 'w') as yaml_file:
246
- yaml.dump(config, yaml_file)
247
- gr.Info(f"Saved config: {data[file_path]}")
248
-
249
-
250
  # Lastly, we define the layout of the application and register the button click listener functions:
251
- with gr.Blocks() as demo:
252
  gr.Markdown(
253
  """
254
  # Apply pyBSM Perturbations with NRTK
255
 
256
- Note: Default configuration options are tailored to satellite imagery (specifically xView).
257
  Perturbing other datasets or other operational tasks may not be successful without modification
258
  to some of these configuration options; defining broad defaults is extremely difficult, if not
259
  impossible due to the physics-based nature of these perturbations.
260
  """
261
  )
262
  with gr.Row():
263
- with gr.Column() as input_col:
264
- sample_img_path = "./assets/92_1920_2201_2432_2713.jpg"
265
  input_img = gr.Image(
266
  label="Input Image",
267
  value=sample_img_path
@@ -270,13 +275,17 @@ with gr.Blocks() as demo:
270
  gr.Examples(
271
  examples=[
272
  sample_img_path,
273
- "./assets/99_384_0_896_512.jpg",
274
- "./assets/125_1152_768_1664_1280.jpg",
275
- "./assets/126_1920_1920_2432_2432.jpg"
276
  ],
277
  inputs=input_img
278
  )
279
-
 
 
 
 
280
  with gr.Row():
281
  gen_config_btn = gr.Button("Generate New Configuration")
282
  with gr.Column():
@@ -420,14 +429,9 @@ with gr.Blocks() as demo:
420
 
421
  submit_btn = gr.Button("Perturb Image")
422
 
423
- with gr.Column(visible=False) as output_col:
424
- out_img = gr.Image(label="Perturbed Image")
425
- file_path = gr.Textbox(label="Config Filename")
426
- save_btn = gr.Button("Save Configuration")
427
-
428
  github_btn = gr.Button(
429
  "Check out NRTK on GitHub!",
430
- icon="./assets/github-badge.png",
431
  link="https://github.com/Kitware/nrtk"
432
  )
433
 
@@ -461,18 +465,8 @@ with gr.Blocks() as demo:
461
  D_m, f_m, px_m, optTransWavelengths_str, opticsTransmission_str, eta, int_time_s, dark_current, read_noise,
462
  max_N, bit_depth, max_well_fill, sx, sy, dax, day, qe_str, qewavelengths_str
463
  },
464
- outputs=[out_img, output_col],
465
- )
466
- save_btn.click(
467
- fn=save,
468
- inputs={
469
- input_img, img_gsd, scenario_name, ihaze, altitude_m, ground_range_m, aircraft_speed_m_Per_s, target_reflectance,
470
- target_temperature_K, bkgd_reflectance, bkgd_temperature_K, ha_windspeed_m_Per_s, cn2at1m, sensor_name,
471
- D_m, f_m, px_m, optTransWavelengths_str, opticsTransmission_str, eta, int_time_s, dark_current, read_noise,
472
- max_N, bit_depth, max_well_fill, sx, sy, dax, day, qe_str, qewavelengths_str, file_path
473
- },
474
- outputs=None,
475
  )
476
 
477
 
478
- demo.launch(show_error=True, share=True)
 
10
 
11
  import gradio as gr # type: ignore
12
 
13
+
14
+ asset_dir = Path("./assets")
15
+
16
+
17
  # Define default values for fields for initilization and button clicks
18
  #
19
+ # Note, for this application we'll be focusing on the use case of UAS imagery, so we'll try to pick default
20
+ # values that work with images similar to those in the VisDrone dataset. Perturbing images from other datasets or other
21
  # operational tasks may not be successful without modification to these values; defining broad defaults is extremely
22
  # difficult, if not impossible due to the physics-based nature of these perturbations.
23
  default_values = {
24
+ "gsd": 0.105,
25
  "scenario": {
26
+ "aircraftSpeed": 0,
27
+ "altitude": 75,
28
  "backgroundReflectance": 0.07,
29
  "backgroundTemperature": 293.,
30
+ "cn2at1m": 0,
31
+ "groundRange": 0,
32
  "haWindspeed": 21.,
33
+ "ihaze": 2,
34
  "name": "",
35
  "targetReflectance": 0.15,
36
  "targetTemperature": 295.,
37
  },
38
  "sensor": {
39
+ "D": 0.004,
40
  "bitdepth": 11.9,
41
  "darkCurrent": 0.,
42
  "dax": 0.0001,
43
  "day": 0.0001,
44
  "eta": 0.4,
45
+ "f": 0.01429,
46
  "intTime": 0.03,
47
  "maxN": 96000,
48
+ "maxWellFill": 0.005,
49
  "name": "",
50
  "optTransWavelengths": [3.8e-07, 7.0e-07],
51
  "opticsTransmission": [],
 
230
  scenario = PybsmScenario(**scenario_config)
231
  perturber = PybsmPerturber(sensor=sensor, scenario=scenario)
232
 
233
+ config = generate_config(data)
234
+ config_file = str(asset_dir / "generated_config.yml")
235
+ with open(config_file, "w") as f:
236
+ yaml.dump(config, f)
237
+
238
+ def stretch_contrast_convert_8bit(img, perc=[0.1, 99.9]):
239
+ img = img.astype(float)
240
+ img = img - np.percentile(img.ravel(), perc[0])
241
+ img = img / (np.percentile(img.ravel(), perc[1]) / 255)
242
+ img = np.clip(img, 0, 255)
243
+ return np.round(img).astype(np.uint8)
244
+
245
+ perturbed_img = perturber(image=data[input_img], additional_params={"img_gsd": gsd})
246
+ peturbed_img = stretch_contrast_convert_8bit(perturbed_img, [0.1, 90.9])
247
+
248
  # Apply the perturbation and display
249
  return {
250
+ out_img: perturbed_img,
251
+ out_config: config_file
252
  }
253
 
254
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
  # Lastly, we define the layout of the application and register the button click listener functions:
256
+ with gr.Blocks() as nrtk_demo:
257
  gr.Markdown(
258
  """
259
  # Apply pyBSM Perturbations with NRTK
260
 
261
+ Note: Default configuration options are tailored to UAS imagery (specifically VisDrone).
262
  Perturbing other datasets or other operational tasks may not be successful without modification
263
  to some of these configuration options; defining broad defaults is extremely difficult, if not
264
  impossible due to the physics-based nature of these perturbations.
265
  """
266
  )
267
  with gr.Row():
268
+ with gr.Column():
269
+ sample_img_path = str(asset_dir / "0000161_01584_d_0000158.jpg")
270
  input_img = gr.Image(
271
  label="Input Image",
272
  value=sample_img_path
 
275
  gr.Examples(
276
  examples=[
277
  sample_img_path,
278
+ str(asset_dir / "0000006_01111_d_0000003.jpg"),
279
+ str(asset_dir / "0000006_01659_d_0000004.jpg"),
280
+ str(asset_dir / "0000006_04309_d_0000011.jpg")
281
  ],
282
  inputs=input_img
283
  )
284
+ with gr.Column() as output_col:
285
+ out_img = gr.Image(label="Perturbed Image")
286
+ out_config = gr.File(label="Generated Configuration")
287
+ with gr.Row():
288
+ with gr.Column() as input_col:
289
  with gr.Row():
290
  gen_config_btn = gr.Button("Generate New Configuration")
291
  with gr.Column():
 
429
 
430
  submit_btn = gr.Button("Perturb Image")
431
 
 
 
 
 
 
432
  github_btn = gr.Button(
433
  "Check out NRTK on GitHub!",
434
+ icon=str(asset_dir / "github-badge.png"),
435
  link="https://github.com/Kitware/nrtk"
436
  )
437
 
 
465
  D_m, f_m, px_m, optTransWavelengths_str, opticsTransmission_str, eta, int_time_s, dark_current, read_noise,
466
  max_N, bit_depth, max_well_fill, sx, sy, dax, day, qe_str, qewavelengths_str
467
  },
468
+ outputs=[out_img, out_config],
 
 
 
 
 
 
 
 
 
 
469
  )
470
 
471
 
472
+ nrtk_demo.launch(show_error=True)
assets/0000006_01111_d_0000003.jpg ADDED
assets/0000006_01659_d_0000004.jpg ADDED
assets/0000006_04309_d_0000011.jpg ADDED
assets/0000161_01584_d_0000158.jpg ADDED
assets/125_1152_768_1664_1280.jpg DELETED
Binary file (70.1 kB)
 
assets/126_1920_1920_2432_2432.jpg DELETED
Binary file (49.8 kB)
 
assets/92_1920_2201_2432_2713.jpg DELETED
Binary file (38.5 kB)
 
assets/99_384_0_896_512.jpg DELETED
Binary file (108 kB)