StrokeSegLab
Loading...
Searching...
No Matches
StrokeSegLab.entrypoints.gui.GUIMain Class Reference

Public Member Functions

None __init__ (self, str input_path, bool only_preprocessing, bool save_preprocessing, bool keep_MNI, bool save_pmap, bool skip_BET, float threshold, str model_name, str suffix, str viewer)
 
bool check_stop (self)
 
 update_status (self, s)
 

Public Attributes

 input_path = tk.StringVar(value="")
 
 suffix = tk.StringVar(value=self._config.get("default","suffix"))
 
 open_viewer = tk.BooleanVar(value=False)
 
 threshold_var = tk.DoubleVar(value=0.5)
 
 label_viewer_not_found = tk.Label(frame, text="No viewer found",fg="red")
 
 combo_viewers = ttk.Combobox(frame,values=self._viewers,state="readonly")
 
 model_to_import = tk.StringVar(value="")
 
 status_import_text = tk.StringVar(value="")
 
 label_import_model = tk.Label(import_model_window, textvariable=self.status_import_text)
 
bool success = False
 
str success = "green")
 
str _stop_requested = "red")
 

Protected Member Functions

 _restore_warning_window (self)
 
 _show_warning (self)
 
None _check_path_filled (self)
 
None _on_model_change (self, tk.Event event=None)
 
None _on_mode_change (self, tk.Event event=None)
 
None _show_threshold (self)
 
None _show_about (self)
 
None _show_help (self)
 
None _show_import_model (self)
 
None _select_model (self)
 
None _import_model (self)
 
None _select_input_folder (self)
 
None _select_input_file (self)
 
None _on_close (self)
 
None _stop (self)
 
None _run (self)
 
None _run_prediction (self)
 
None _predict (self)
 
None _run_bet (self)
 
None _bet (self)
 
None _update_result (self)
 
None _update_stringvar (self, tk.StringVar stringvar, str s)
 
str _check_device (self)
 

Protected Attributes

 _logger = logging.getLogger()
 
 _option = Option()
 
 _config = Config()
 
 _preprocessor = Preprocessor(gui=self)
 
 _postprocessor = Postprocessor(gui=self)
 
 _inference = Inference(gui=self)
 
bool _running = False
 
dict _nii_paths = {}
 
 _window = tk.Tk()
 
 _on_close
 
 _keep_MNI = tk.BooleanVar(value=keep_MNI)
 
 _save_pmap = tk.BooleanVar(value=save_pmap)
 
 _save_preproc = tk.BooleanVar(value=save_preprocessing)
 
 _skip_BET = tk.BooleanVar(value=skip_BET)
 
 _channel_text = tk.StringVar()
 
 _status_text = tk.StringVar()
 
 _working_on_text = tk.StringVar()
 
 _result_text = tk.StringVar()
 
 _subject_number_text = tk.StringVar()
 
 _option_menu = Menu(menubar,tearoff=0)
 
 _run_button = tk.Button(frame, text='run', command=self._run, state="disabled")
 
 _entry_input_path = tk.Entry(frame, textvariable=self.input_path, state='readonly', width=50)
 
 _label_suffix = tk.Label(frame, text="Suffix : ")
 
 _entry_suffix = tk.Entry(frame, textvariable=self.suffix, width=20)
 
 _label_model = tk.Label(frame, text="Model : ")
 
list _models = self._config.get("default","models").split(',')
 
 _label_channel = tk.Label(frame,textvariable=self._channel_text,fg="blue")
 
 _combo_models = ttk.Combobox(frame,values=self._models,state="readonly")
 
 _on_model_change
 
 _label_open_viewer = tk.Label(frame, text="Open viewer : ")
 
 _viewer_button = tk.Checkbutton(frame, text="ON/OFF", variable=self.open_viewer)
 
list _viewers = [v for v in v if self._config.get("ViewerPath", v)]
 
 _label_keep_MNI = tk.Label(frame,text=" Output in MNI space ")
 
 _keep_MNI_button = tk.Checkbutton(frame, text="YES/NO", variable=self._keep_MNI)
 
 _label_exec_mode = tk.Label(frame, text="Execution mode : ")
 
 _combo_modes = ttk.Combobox(frame,values=execution_modes,state="readonly")
 
 _on_mode_change
 
 _label_working_on = tk.Label(frame, textvariable=self._working_on_text, fg="blue")
 
 _label_subject_number_text = tk.Label(frame, textvariable=self._subject_number_text, fg="blue")
 
 _label_status = tk.Label(frame, textvariable=self._status_text)
 
 _label_result = tk.Label(frame, textvariable=self._result_text, font=("Arial", 14, "bold"))
 
bool _stop_requested = False
 
 _stop_button = tk.Button(frame, text="Stop", command=self._stop)
 
 _update_stringvar
 
 _update_result = False
 

Detailed Description

Graphical interface of the brain segmentation application
This class initialize the Tkinter window, manage user inputs, run preprocessing, inference, postprocessing and updates the GUI

Constructor & Destructor Documentation

◆ __init__()

None StrokeSegLab.entrypoints.gui.GUIMain.__init__ ( self,
str input_path,
bool only_preprocessing,
bool save_preprocessing,
bool keep_MNI,
bool save_pmap,
bool skip_BET,
float threshold,
str model_name,
str suffix,
str viewer )
Initialize the graphical interface with all the Tkinter widgets and run the main Tkinter loop (mainloop).

**Args:**
- `input_path` (str): The input path.
- `only_preprocessing` (bool): If True, the app performs brain extraction only.
- `save_preprocessing` (bool): If True, save all preprocessing steps.
- `keep_MNI` (bool): If True, save the input image and segmentation in MNI space.
- `save_pmap` (bool): If True, save the probability map in addition to the binary mask.
- `threshold` (float): Segmentation threshold (default: 0.5 if None).
- `skip_BET` (bool): If True, skip the brain extraction step.
- `model_name` (str): Name of the model located in the models folder to be used.
- `suffix` (str): Suffix for the output segmentation (use default if None).
- `viewer` (str): Name of the viewer used to open the first input image and its segmentation.

These parameters are used to pre-fill the corresponding fields in the graphical interface.

Member Function Documentation

◆ _bet()

None StrokeSegLab.entrypoints.gui.GUIMain._bet ( self)
protected
@public
Run the BET pipeline for all subjects.

It creates a temporary directory and then, for each subject : 
- Run preprocessing
- Checks periodically if a stop is requested
- Update the UI during the process using self._window.after because Tkinter isn't thread safe, we can't modify the UI from a secondary thread. So 'after' is scheduling an update in the main thread

◆ _check_device()

str StrokeSegLab.entrypoints.gui.GUIMain._check_device ( self)
protected
@public
Check Cuda if available

Returns:
    str: The selected execution provider ('CUDAExecutionProvider' or 'CPUExecutionProvider')

◆ _check_path_filled()

None StrokeSegLab.entrypoints.gui.GUIMain._check_path_filled ( self)
protected
@public
Enable the run button only if the input path is set and there is model available

◆ _import_model()

None StrokeSegLab.entrypoints.gui.GUIMain._import_model ( self)
protected
@public
Try to import a model, update the model list and the status message : 
- Call update_model to refresh the list of model available
- Call add_model to add the model to the models directory
- Update the list used by the combobox
- Handle the potential error and display a status message

◆ _on_close()

None StrokeSegLab.entrypoints.gui.GUIMain._on_close ( self)
protected
@public
Check if a prediction is running, and destroy the window if not

◆ _on_mode_change()

None StrokeSegLab.entrypoints.gui.GUIMain._on_mode_change ( self,
tk.Event event = None )
protected
@public
Update the app based on the selected mode:
- Brain extraction only : all the fields are deleted execpt input path, some option are disable
- Prediction : all the fields are displayed
Args:
    event (tk.Event, optional): The event triggered by the mode selection. Defaults to None.

◆ _on_model_change()

None StrokeSegLab.entrypoints.gui.GUIMain._on_model_change ( self,
tk.Event event = None )
protected
@public
Update the app based on the selected model
- Disbale the run button if there isn't a model available
- Display an appropriate message based on the model
Args:
    event (tk.Event, optional): The event triggered by the model selection. Defaults to None

◆ _predict()

None StrokeSegLab.entrypoints.gui.GUIMain._predict ( self)
protected
@public
Run the prediction pipeline for all subjects.

Depending on the model:
- 2 channels (FLAIR and T1), 't1' is the T1 image and 'flair' is the FLAIR image.
- 1 channel, 't1' contains either the T1 or the FLAIR image, and 'flair' is None.

It creates a temporary directory and then, for each subject : 
- Run preprocessing, inference and postprocessing
- Checks periodically if a stop is requested
- Update the UI during the process using self._window.after because Tkinter isn't thread safe, we can't modify the UI from a secondary thread. So 'after' is scheduling an update in the main thread

◆ _run()

None StrokeSegLab.entrypoints.gui.GUIMain._run ( self)
protected
@public
The entry point of the processing
Update the UI, set various variables used during the processing task, and call either _run_prediction or _run_bet depending on the selected mode.

◆ _run_bet()

None StrokeSegLab.entrypoints.gui.GUIMain._run_bet ( self)
protected
@public
Configure the BET settings and launch it in a separate thread in order to not freeze the UI

◆ _run_prediction()

None StrokeSegLab.entrypoints.gui.GUIMain._run_prediction ( self)
protected
@public
Configure the prediction settings and launch it in a separate thread in order to not freeze the UI :
- Retrieves and configures runtime option
- Call find_nii_files to construct a dictionary of NIFTI path and check T1/FLAIR consistency
- Display warning message if needed and other informations to the users
- Start the prediction in a thread

◆ _select_input_file()

None StrokeSegLab.entrypoints.gui.GUIMain._select_input_file ( self)
protected
@public
Handle the input file selection
Open a filedialog, set the input path and call for _check_path_filled

◆ _select_input_folder()

None StrokeSegLab.entrypoints.gui.GUIMain._select_input_folder ( self)
protected
@public
Handle the input folder selection
Open a filedialog, set the input path and call for _check_path_filled

◆ _select_model()

None StrokeSegLab.entrypoints.gui.GUIMain._select_model ( self)
protected
@public
Open a filedialog to select a model file.
If a file is selected, store the path and clear the import status message

◆ _show_about()

None StrokeSegLab.entrypoints.gui.GUIMain._show_about ( self)
protected
@public
Display the about window
A notebook is used to display 3 frame in different tabs : developpers, license and publications

◆ _show_help()

None StrokeSegLab.entrypoints.gui.GUIMain._show_help ( self)
protected
@public
Display the help window

◆ _show_import_model()

None StrokeSegLab.entrypoints.gui.GUIMain._show_import_model ( self)
protected
@public
Display the import model window with 3 button to select and import the model and close the window

◆ _show_threshold()

None StrokeSegLab.entrypoints.gui.GUIMain._show_threshold ( self)
protected
@public
Display the threshold window with a slider and an entry field linked to the threshold of the segmentation

◆ _stop()

None StrokeSegLab.entrypoints.gui.GUIMain._stop ( self)
protected
@public
Method used to stop a prediction (or BET)
- Since the prediction (or BET) runs in a separate thread and can take a long time, this method does not stop the process immediately. Instead, it sets a variable (self._stop_requested) that is checked periodically during the processing loop. When detected, the process will terminate.
- Update the UI to inform the user

◆ _update_result()

None StrokeSegLab.entrypoints.gui.GUIMain._update_result ( self)
protected
@public
Update the UI based on the result of the processing

◆ _update_stringvar()

None StrokeSegLab.entrypoints.gui.GUIMain._update_stringvar ( self,
tk.StringVar stringvar,
str s )
protected
@public
Update the value of a StringVar with the given string
Args:
    stringvar (tk.StringVar): The StringVar to update
    s (str): The new string value to set

◆ check_stop()

bool StrokeSegLab.entrypoints.gui.GUIMain.check_stop ( self)
@public
The method used during the process to check if a stop is requested by the user

Returns:
    bool: True if a stop was requested, otherwise False

The documentation for this class was generated from the following file: