Skip to content

Commit

Permalink
Edit detection of images for viewing - change rigid suffix req
Browse files Browse the repository at this point in the history
  • Loading branch information
gurayerus committed Dec 9, 2024
1 parent 295c979 commit 6a42dcf
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 60 deletions.
104 changes: 44 additions & 60 deletions src/viewer/pages/process_sMRI_DLMUSE.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def panel_int1() -> None:
- On the cloud platform, you can directly drag and drop your T1 image files or folder and they will be uploaded to the **"Nifti/T1"** folder within the **working directory**.
- On the cloud, **we strongly recommend** compressing your DICOM data into a single ZIP archive before uploading. The system will automatically extract the contents of the ZIP file into the **"Nifti/T1"** folder upon upload.
- On the cloud, **we strongly recommend** compressing your input images into a single ZIP archive before uploading. The system will automatically extract the contents of the ZIP file into the **"Nifti/T1"** folder upon upload.
"""
utilst.util_get_help(s_title, s_text)

Expand Down Expand Up @@ -257,80 +257,64 @@ def panel_view() -> None:
st.warning("Please select the MRID!")
return

st.session_state.paths["sel_img"] = os.path.join(
st.session_state.paths["T1"], sel_mrid + st.session_state.suff_t1img
st.session_state.paths["sel_img"] = utilio.get_image_path(
st.session_state.paths["T1"],
sel_mrid,
["nii.gz", ".nii"]
)
if sel_mrid is not None:
st.session_state.paths["sel_img"] = os.path.join(
# hardcoded fix for T1 suffix
st.session_state.paths["T1"],
re.sub(r"_T1$", "", sel_mrid) + st.session_state.suff_t1img,
)

st.session_state.paths["sel_seg"] = os.path.join(
st.session_state.paths["dlmuse"], re.sub(r"_T1$", "", sel_mrid) + st.session_state.suff_seg

st.session_state.paths["sel_seg"] = utilio.get_image_path(
st.session_state.paths["dlmuse"],
sel_mrid,
["nii.gz", ".nii"]
)

if not os.path.exists(st.session_state.paths["sel_img"]):
st.warning(
f'Could not locate underlay image: {st.session_state.paths["sel_img"]}'
'Could not locate underlay image!'
)
return

if not os.path.exists(st.session_state.paths["sel_seg"]):
st.warning(
f'Could not locate overlay image: {st.session_state.paths["sel_seg"]}'
'Could not locate overlay image!'
)
return

with st.spinner("Wait for it..."):
# Select images
# FIXME: at least on cloud, can get here with multiple _T1 appended (see marked lines)
if sel_mrid is not None:
st.session_state.paths["sel_img"] = os.path.join(
# hardcoded fix for T1 suffix
st.session_state.paths["T1"],
re.sub(r"_T1$", "", sel_mrid) + st.session_state.suff_t1img,
)
st.session_state.paths["sel_seg"] = os.path.join(
# hardcoded fix for T1 suffix
st.session_state.paths["dlmuse"],
re.sub(r"_T1$", "", sel_mrid) + st.session_state.suff_seg,
)

# Process image and mask to prepare final 3d matrix to display
img, mask, img_masked = utilni.prep_image_and_olay(
st.session_state.paths["sel_img"],
st.session_state.paths["sel_seg"],
list_rois,
crop_to_mask,
)
# Process image and mask to prepare final 3d matrix to display
img, mask, img_masked = utilni.prep_image_and_olay(
st.session_state.paths["sel_img"],
st.session_state.paths["sel_seg"],
list_rois,
crop_to_mask,
)

# Detect mask bounds and center in each view
mask_bounds = utilni.detect_mask_bounds(mask)

# Show images
blocks = st.columns(len(list_orient))
for i, tmp_orient in stqdm(
enumerate(list_orient),
desc="Showing images ...",
total=len(list_orient),
):
with blocks[i]:
ind_view = utilni.img_views.index(tmp_orient)
size_auto = True
if is_show_overlay is False:
utilst.show_img3D(
img, ind_view, mask_bounds[ind_view, :], tmp_orient, size_auto
)
else:
utilst.show_img3D(
img_masked,
ind_view,
mask_bounds[ind_view, :],
tmp_orient,
size_auto
)
# Detect mask bounds and center in each view
mask_bounds = utilni.detect_mask_bounds(mask)

# Show images
blocks = st.columns(len(list_orient))
for i, tmp_orient in stqdm(
enumerate(list_orient),
desc="Showing images ...",
total=len(list_orient),
):
with blocks[i]:
ind_view = utilni.img_views.index(tmp_orient)
size_auto = True
if is_show_overlay is False:
utilst.show_img3D(
img, ind_view, mask_bounds[ind_view, :], tmp_orient, size_auto
)
else:
utilst.show_img3D(
img_masked,
ind_view,
mask_bounds[ind_view, :],
tmp_orient,
size_auto
)


def panel_download() -> None:
Expand Down
14 changes: 14 additions & 0 deletions src/viewer/pages/process_sMRI_DLWMLS.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def panel_wdir() -> None:
)
st.session_state.flags["dir_out"] = True

utilst.util_workingdir_get_help()

def panel_infl() -> None:
"""
Expand Down Expand Up @@ -95,6 +96,19 @@ def panel_infl() -> None:
icon=":material/thumb_up:",
)

s_title="Input FL Scans"
s_text="""
- Upload or select input FL scans. DLWMLS can be directly applied to raw FL scans. Nested folders are not supported.
- The result file with total segmented WMLS volume includes an **"MRID"** column that uniquely identifies each scan. **MRID** is extracted from image file names by removing the common suffix to all images. Using consistent input image names is **strongly recommended**
- On the desktop app, a symbolic link named **"Nifti/FL"** will be created in the **working directory**, pointing to your input FL images folder.
- On the cloud platform, you can directly drag and drop your FL image files or folder and they will be uploaded to the **"Nifti/FL"** folder within the **working directory**.
- On the cloud, **we strongly recommend** compressing your input images into a single ZIP archive before uploading. The system will automatically extract the contents of the ZIP file into the **"Nifti/T1"** folder upon upload.
"""
utilst.util_get_help(s_title, s_text)

def panel_dlwmls() -> None:
"""
Expand Down
8 changes: 8 additions & 0 deletions src/viewer/utils/utils_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,11 @@ def get_file_list(folder_path: str, file_suff: str = "") -> List:
if f.endswith(file_suff):
list_nifti.append(f)
return list_nifti

def get_image_path(folder_path: str, file_pref: str = "", file_suff_list: list) -> str:
if not os.path.exists(folder_path):
return ""
for tmp_suff in file_suff_list:
for f in os.listdir(folder_path):
if f.startswith(file_pref) and f.endswith(tmp_suff):
return os.path.join(folder_path, f)

0 comments on commit 6a42dcf

Please sign in to comment.