skarugu commited on
Commit
ebeb67c
Β·
verified Β·
1 Parent(s): e2a4bdf

Updated the streamlit app

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +84 -14
src/streamlit_app.py CHANGED
@@ -1385,9 +1385,42 @@ with st.sidebar:
1385
  image_size = st.select_slider("Model input size",
1386
  options=[256, 384, 512, 640, 768, 1024], value=512)
1387
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1388
  st.header("Thresholds")
1389
- thr_nuc = st.slider("Nuclei threshold", 0.05, 0.95, 0.45, 0.01)
1390
- thr_myo = st.slider("Myotube threshold", 0.05, 0.95, 0.40, 0.01)
 
 
 
 
 
 
1391
 
1392
  st.header("Fusion Index method")
1393
  fi_method = st.radio(
@@ -1418,10 +1451,21 @@ with st.sidebar:
1418
  )
1419
 
1420
  st.header("Postprocessing")
1421
- min_nuc_area = st.number_input("Min nucleus area (px)", 0, 10000, 20, 1)
1422
- min_myo_area = st.number_input("Min myotube area (px)", 0, 200000, 500, 10)
1423
- nuc_close_radius = st.number_input("Nuclei close radius", 0, 50, 2, 1)
1424
- myo_open_radius = st.number_input("Myotube open radius", 0, 50, 2, 1,
 
 
 
 
 
 
 
 
 
 
 
1425
  help="Opening removes small noise without merging separate myotubes. "
1426
  "Replaces the old closing radius which was merging adjacent myotubes.")
1427
 
@@ -1431,7 +1475,8 @@ with st.sidebar:
1431
  "otherwise be counted as a single object."
1432
  )
1433
  myo_erode_radius = st.number_input(
1434
- "Myotube erode radius (px)", 0, 15, 2, 1,
 
1435
  help=(
1436
  "Erode + re-dilate breaks thin pixel bridges between adjacent "
1437
  "myotubes while preserving their overall size. "
@@ -1440,7 +1485,8 @@ with st.sidebar:
1440
  )
1441
  )
1442
  min_myo_aspect_ratio = st.number_input(
1443
- "Min myotube aspect ratio", 0.0, 10.0, 0.0, 0.1,
 
1444
  help=(
1445
  "Rejects round blobs (debris/artifacts) that are not real myotubes. "
1446
  "Myotubes are elongated (aspect ratio > 3). Round objects have ~1. "
@@ -1449,7 +1495,8 @@ with st.sidebar:
1449
  )
1450
  )
1451
  myo_max_area_px = st.number_input(
1452
- "Max myotube area before split (pxΒ²)", 0, 500000, 20000, 500,
 
1453
  help=(
1454
  "Any connected myotube region larger than this is split using "
1455
  "nucleus-seeded watershed. Set to 0 to disable. "
@@ -1457,7 +1504,8 @@ with st.sidebar:
1457
  )
1458
  )
1459
  myo_split_min_seeds = st.number_input(
1460
- "Min nuclei seeds to split", 2, 20, 2, 1,
 
1461
  help=(
1462
  "Minimum nucleus centroids required before splitting a large region. "
1463
  "Set to 2 to split merged pairs; increase if single large myotubes "
@@ -1999,6 +2047,9 @@ if not private_mode and names:
1999
  # ─────────────────────────────────────────────────────────────────────────────
2000
  if enable_al and not private_mode:
2001
  st.subheader("🧠 Submit corrected labels (Active Learning)")
 
 
 
2002
  st.caption(
2003
  "Download predicted masks, correct them in ImageJ/FIJI, napari, or any "
2004
  "image editor (white = foreground, black = background), then upload "
@@ -2006,6 +2057,8 @@ if enable_al and not private_mode:
2006
  )
2007
 
2008
  al_pick = st.selectbox("Correct masks for image", names, key="al_pick")
 
 
2009
 
2010
  # Download buttons for current masks β€” lets users edit and re-upload
2011
  if al_pick in st.session_state.artifacts:
@@ -2048,13 +2101,27 @@ if enable_al and not private_mode:
2048
  key="dl_myo_mask",
2049
  )
2050
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2051
  acol1, acol2 = st.columns(2)
2052
  with acol1:
2053
  corr_nuc = st.file_uploader(
2054
  "Upload corrected NUCLEI mask(s)",
2055
  type=["png", "tif", "tiff"],
2056
  accept_multiple_files=True,
2057
- key="nuc_corr",
2058
  help="Upload one nuclei mask for the selected image, or select many nuclei masks for batch correction.",
2059
  )
2060
  with acol2:
@@ -2062,7 +2129,7 @@ if enable_al and not private_mode:
2062
  "Upload corrected MYOTUBE mask(s)",
2063
  type=["png", "tif", "tiff"],
2064
  accept_multiple_files=True,
2065
- key="myo_corr",
2066
  help="Upload the matching myotube mask(s). Batch files are paired by filename stem.",
2067
  )
2068
 
@@ -2074,13 +2141,16 @@ if enable_al and not private_mode:
2074
  corr_nuc, corr_myo, st.session_state.artifacts, al_pick
2075
  )
2076
  if n_submitted == 1:
2077
- st.success("Saved 1 corrected image pair to corrections/.")
2078
  elif n_submitted > 1:
2079
- st.success(f"Saved {n_submitted} corrected image pairs to corrections/.")
2080
  if correction_errors:
2081
  st.warning("Some files were skipped:\n" + "\n".join(f"- {e}" for e in correction_errors[:12]))
2082
  if not n_submitted and not correction_errors:
2083
  st.error("No matching correction pairs were found.")
 
 
 
2084
 
2085
  elif enable_al and private_mode:
2086
  st.info(
 
1385
  image_size = st.select_slider("Model input size",
1386
  options=[256, 384, 512, 640, 768, 1024], value=512)
1387
 
1388
+ st.header("Analysis preset")
1389
+ analysis_preset = st.radio(
1390
+ "Preset",
1391
+ ["Standard", "Dense culture rescue", "Sparse cleanup"],
1392
+ index=0,
1393
+ help=(
1394
+ "Dense culture rescue lowers the myotube threshold and uses more "
1395
+ "aggressive bridge-breaking/splitting to reduce myotube undercounting."
1396
+ ),
1397
+ )
1398
+ preset_defaults = {
1399
+ "Standard": {"thr_nuc": 0.45, "thr_myo": 0.40, "min_nuc_area": 20,
1400
+ "min_myo_area": 500, "nuc_close_radius": 2, "myo_open_radius": 2,
1401
+ "myo_erode_radius": 2, "min_myo_aspect_ratio": 0.0,
1402
+ "myo_max_area_px": 20000, "myo_split_min_seeds": 2},
1403
+ "Dense culture rescue": {"thr_nuc": 0.42, "thr_myo": 0.28, "min_nuc_area": 15,
1404
+ "min_myo_area": 250, "nuc_close_radius": 2, "myo_open_radius": 1,
1405
+ "myo_erode_radius": 4, "min_myo_aspect_ratio": 0.0,
1406
+ "myo_max_area_px": 6000, "myo_split_min_seeds": 2},
1407
+ "Sparse cleanup": {"thr_nuc": 0.45, "thr_myo": 0.45, "min_nuc_area": 20,
1408
+ "min_myo_area": 800, "nuc_close_radius": 2, "myo_open_radius": 2,
1409
+ "myo_erode_radius": 2, "min_myo_aspect_ratio": 1.5,
1410
+ "myo_max_area_px": 25000, "myo_split_min_seeds": 3},
1411
+ }
1412
+ defaults = preset_defaults[analysis_preset]
1413
+ preset_key = analysis_preset.lower().replace(" ", "_")
1414
+
1415
  st.header("Thresholds")
1416
+ thr_nuc = st.slider(
1417
+ "Nuclei threshold", 0.05, 0.95, defaults["thr_nuc"], 0.01,
1418
+ key=f"thr_nuc_{preset_key}"
1419
+ )
1420
+ thr_myo = st.slider(
1421
+ "Myotube threshold", 0.05, 0.95, defaults["thr_myo"], 0.01,
1422
+ key=f"thr_myo_{preset_key}"
1423
+ )
1424
 
1425
  st.header("Fusion Index method")
1426
  fi_method = st.radio(
 
1451
  )
1452
 
1453
  st.header("Postprocessing")
1454
+ min_nuc_area = st.number_input(
1455
+ "Min nucleus area (px)", 0, 10000, defaults["min_nuc_area"], 1,
1456
+ key=f"min_nuc_area_{preset_key}"
1457
+ )
1458
+ min_myo_area = st.number_input(
1459
+ "Min myotube area (px)", 0, 200000, defaults["min_myo_area"], 10,
1460
+ key=f"min_myo_area_{preset_key}"
1461
+ )
1462
+ nuc_close_radius = st.number_input(
1463
+ "Nuclei close radius", 0, 50, defaults["nuc_close_radius"], 1,
1464
+ key=f"nuc_close_radius_{preset_key}"
1465
+ )
1466
+ myo_open_radius = st.number_input(
1467
+ "Myotube open radius", 0, 50, defaults["myo_open_radius"], 1,
1468
+ key=f"myo_open_radius_{preset_key}",
1469
  help="Opening removes small noise without merging separate myotubes. "
1470
  "Replaces the old closing radius which was merging adjacent myotubes.")
1471
 
 
1475
  "otherwise be counted as a single object."
1476
  )
1477
  myo_erode_radius = st.number_input(
1478
+ "Myotube erode radius (px)", 0, 15, defaults["myo_erode_radius"], 1,
1479
+ key=f"myo_erode_radius_{preset_key}",
1480
  help=(
1481
  "Erode + re-dilate breaks thin pixel bridges between adjacent "
1482
  "myotubes while preserving their overall size. "
 
1485
  )
1486
  )
1487
  min_myo_aspect_ratio = st.number_input(
1488
+ "Min myotube aspect ratio", 0.0, 10.0, defaults["min_myo_aspect_ratio"], 0.1,
1489
+ key=f"min_myo_aspect_ratio_{preset_key}",
1490
  help=(
1491
  "Rejects round blobs (debris/artifacts) that are not real myotubes. "
1492
  "Myotubes are elongated (aspect ratio > 3). Round objects have ~1. "
 
1495
  )
1496
  )
1497
  myo_max_area_px = st.number_input(
1498
+ "Max myotube area before split (px)", 0, 500000, defaults["myo_max_area_px"], 500,
1499
+ key=f"myo_max_area_px_{preset_key}",
1500
  help=(
1501
  "Any connected myotube region larger than this is split using "
1502
  "nucleus-seeded watershed. Set to 0 to disable. "
 
1504
  )
1505
  )
1506
  myo_split_min_seeds = st.number_input(
1507
+ "Min nuclei seeds to split", 2, 20, defaults["myo_split_min_seeds"], 1,
1508
+ key=f"myo_split_min_seeds_{preset_key}",
1509
  help=(
1510
  "Minimum nucleus centroids required before splitting a large region. "
1511
  "Set to 2 to split merged pairs; increase if single large myotubes "
 
2047
  # ─────────────────────────────────────────────────────────────────────────────
2048
  if enable_al and not private_mode:
2049
  st.subheader("🧠 Submit corrected labels (Active Learning)")
2050
+ flash_msg = st.session_state.pop("correction_flash", None)
2051
+ if flash_msg:
2052
+ st.success(flash_msg)
2053
  st.caption(
2054
  "Download predicted masks, correct them in ImageJ/FIJI, napari, or any "
2055
  "image editor (white = foreground, black = background), then upload "
 
2057
  )
2058
 
2059
  al_pick = st.selectbox("Correct masks for image", names, key="al_pick")
2060
+ if "correction_upload_reset_id" not in st.session_state:
2061
+ st.session_state.correction_upload_reset_id = 0
2062
 
2063
  # Download buttons for current masks β€” lets users edit and re-upload
2064
  if al_pick in st.session_state.artifacts:
 
2101
  key="dl_myo_mask",
2102
  )
2103
 
2104
+ clear_col, _ = st.columns([1, 3])
2105
+ with clear_col:
2106
+ if st.button(
2107
+ "Remove uploaded masks",
2108
+ help=(
2109
+ "Clears masks currently sitting in the upload boxes. "
2110
+ "This does not delete corrections that were already submitted."
2111
+ ),
2112
+ key="clear_pending_correction_uploads",
2113
+ ):
2114
+ st.session_state.correction_upload_reset_id += 1
2115
+ st.rerun()
2116
+
2117
+ upload_key_suffix = f"{al_pick}_{st.session_state.correction_upload_reset_id}"
2118
  acol1, acol2 = st.columns(2)
2119
  with acol1:
2120
  corr_nuc = st.file_uploader(
2121
  "Upload corrected NUCLEI mask(s)",
2122
  type=["png", "tif", "tiff"],
2123
  accept_multiple_files=True,
2124
+ key=f"nuc_corr_{upload_key_suffix}",
2125
  help="Upload one nuclei mask for the selected image, or select many nuclei masks for batch correction.",
2126
  )
2127
  with acol2:
 
2129
  "Upload corrected MYOTUBE mask(s)",
2130
  type=["png", "tif", "tiff"],
2131
  accept_multiple_files=True,
2132
+ key=f"myo_corr_{upload_key_suffix}",
2133
  help="Upload the matching myotube mask(s). Batch files are paired by filename stem.",
2134
  )
2135
 
 
2141
  corr_nuc, corr_myo, st.session_state.artifacts, al_pick
2142
  )
2143
  if n_submitted == 1:
2144
+ st.session_state.correction_flash = "Saved 1 corrected image pair to corrections/."
2145
  elif n_submitted > 1:
2146
+ st.session_state.correction_flash = f"Saved {n_submitted} corrected image pairs to corrections/."
2147
  if correction_errors:
2148
  st.warning("Some files were skipped:\n" + "\n".join(f"- {e}" for e in correction_errors[:12]))
2149
  if not n_submitted and not correction_errors:
2150
  st.error("No matching correction pairs were found.")
2151
+ if n_submitted:
2152
+ st.session_state.correction_upload_reset_id += 1
2153
+ st.rerun()
2154
 
2155
  elif enable_al and private_mode:
2156
  st.info(