From 29bf26e2a698cf0e8b1f45d3bf10e123e0d5cbfd Mon Sep 17 00:00:00 2001 From: htylab <10368378+htylab@users.noreply.github.com> Date: Sun, 16 Jun 2024 19:08:16 +0800 Subject: [PATCH] update --- tigerhx/guitool.py | 3 +- tigerhx/tigercinegui.py | 73 +++++++++++++++++++++++++++++++++-------- 2 files changed, 61 insertions(+), 15 deletions(-) diff --git a/tigerhx/guitool.py b/tigerhx/guitool.py index d4c7d86..6fb81c9 100644 --- a/tigerhx/guitool.py +++ b/tigerhx/guitool.py @@ -166,7 +166,8 @@ def init_app(application_path): default_models = ['cine4d_v0001_xyz_mms12.onnx', 'cine4d_v0002_xyz_mms12acdc.onnx', - 'cine4d_v0003_xy_mms12acdc.onnx'] + 'cine4d_v0003_xy_mms12acdc.onnx', + 'cine4d_v0004_xy_retrain.onnx'] for m0 in default_models: model_file = join(model_path, m0) diff --git a/tigerhx/tigercinegui.py b/tigerhx/tigercinegui.py index 9a2cc82..b05b8c5 100644 --- a/tigerhx/tigercinegui.py +++ b/tigerhx/tigercinegui.py @@ -28,6 +28,7 @@ root = None progress_bar = None display_type_combo = None +colormap_combo = None data = None # Ensure data is globally accessible fig, ax = None, None canvas = None @@ -90,17 +91,23 @@ def process_files_multithreaded(files, slice_select, model_ff): LVM = LVM.astype(int) Seg = emp.astype(int) - dict = {'input': img_ori, - 'LV': LV , 'LVM': LVM, 'RV': RV , - 'Seg': Seg, 'Seg_AHA': Seg_AHA, 'voxel_size': np.array(voxel_size)} + mask = np.max(Seg, axis=(2, 3)) + xx, yy = np.nonzero(mask) + x0, x1 = max(0, xx.min() - 10), min(mask.shape[0], xx.max() + 10) + y0, y1 = max(0, yy.min() - 10), min(mask.shape[1], yy.max() + 10) + + dict = {'input': img_ori, 'Seg': Seg, 'SegAHA': Seg_AHA, + 'input_crop': img_ori[x0:x1, y0:y1], 'Seg_crop': Seg[x0:x1, y0:y1], + 'SegAHA_crop': Seg_AHA[x0:x1, y0:y1], + 'LV': LV, 'LVM': LVM, 'RV': RV, + 'voxel_size': np.array(voxel_size)} dict['model'] = basename(model_ff) savemat(f'./output/{name}_pred_{onnx_version}.mat', dict, do_compression=True) log_message(log_box, f'{num + 1}/{len(files)}: {basename(file)} finished ......') root.after(0, update_mat_listbox) - - #root.after(0, lambda: progress_bar.pack_forget()) + # root.after(0, lambda: progress_bar.pack_forget()) log_message(log_box, f'All job finished.........') progress_bar['value'] = 0 root.update_idletasks() # Ensure the GUI updates @@ -128,7 +135,7 @@ def on_mat_select(event): log_message(log_box, f"'{selected_type}' not found in {selected_mat}") if 'model' in data: - model_name = data['model'][0] #from .mat file , the string stored into a cell array + model_name = data['model'][0] # from .mat file, the string stored into a cell array log_message(log_box, f"Predicted using {model_name}") except Exception as e: log_message(log_box, f"An error occurred: {e}") @@ -144,6 +151,11 @@ def on_display_type_change(event): update_time_slider(seg) # Adapt the range of the time points except: log_message(log_box, f"Select a result file....") + +def on_colormap_change(event): + if seg is not None: + show_montage(seg) # Redraw the figure with the selected colormap + def show_montage(emp, time_frame=0): global fig, ax, canvas, im plt.close('all') # Close all previous figures @@ -198,10 +210,17 @@ def show_montage(emp, time_frame=0): # Resize the mosaic to 400x600 mosaic_resized = resize(padded_mosaic, (600, 400), anti_aliasing=True) + colormap = colormap_combo.get() # Get the selected colormap + if colormap == 'gray': + cmap = 'gray' + elif colormap == 'vivid': + cmap = 'viridis' # Replace 'vivid' with an actual matplotlib colormap, like 'viridis' + if im is None: - im = ax.imshow(mosaic_resized) + im = ax.imshow(mosaic_resized, cmap=cmap) else: im.set_data(mosaic_resized) + im.set_cmap(cmap) im.set_clim(vmin=emp.min(), vmax=emp.max()) canvas = FigureCanvasTkAgg(fig, master=canvas_frame) @@ -304,20 +323,47 @@ def list_and_log_sample_files(sample_dir): display_type_label.pack(side=tk.LEFT) # Create a combo box for selecting display type -display_types = ['Seg', 'Seg_AHA', 'input', 'LV', 'LVM', 'RV'] -display_type_combo = ttk.Combobox(display_type_frame, values=display_types, width=10) +display_types = ['input', 'Seg', 'SegAHA', + 'input_crop', 'Seg_crop', 'SegAHA_crop', + 'LV', 'LVM', 'RV'] +display_type_combo = ttk.Combobox(display_type_frame, values=display_types, width=16) display_type_combo.pack(side=tk.LEFT, padx=5) display_type_combo.current(0) # Set default display type to 'Seg' display_type_combo.bind("<>", on_display_type_change) -refresh_button = tk.Button(display_type_frame, text="Refresh Preds", command=update_mat_listbox) -refresh_button.pack(side=tk.LEFT, padx=5) +# Create a label for the colormap combo box +colormap_label = tk.Label(display_type_frame, text="Colormap") +colormap_label.pack(side=tk.LEFT, padx=5) + +# Create a combo box for selecting colormap +colormap_combo = ttk.Combobox(display_type_frame, values=['gray', 'vivid'], width=10) +colormap_combo.pack(side=tk.LEFT, padx=5) +colormap_combo.current(0) # Set default colormap to 'gray' +colormap_combo.bind("<>", on_colormap_change) # Create a listbox for the .mat files -mat_listbox = tk.Listbox(listbox_frame, width=40, height=10) -mat_listbox.pack(side=tk.TOP, fill=tk.BOTH, expand=True) +#mat_listbox = tk.Listbox(listbox_frame, width=40, height=10) +#mat_listbox.pack(side=tk.TOP, fill=tk.BOTH, expand=True) +#mat_listbox.bind('<>', on_mat_select) + + + +# Create a frame for the listbox and display type combo box +listbox_frame = tk.Frame(frame) +listbox_frame.pack(padx=10, pady=10, fill=tk.BOTH, expand=True) + +# Create a scrollbar for the listbox +listbox_scrollbar = tk.Scrollbar(listbox_frame, orient=tk.VERTICAL) +listbox_scrollbar.pack(side=tk.RIGHT, fill=tk.Y) + +# Create a listbox for the .mat files +mat_listbox = tk.Listbox(listbox_frame, width=40, height=10, yscrollcommand=listbox_scrollbar.set) +mat_listbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=True) mat_listbox.bind('<>', on_mat_select) +# Configure the scrollbar to work with the listbox +listbox_scrollbar.config(command=mat_listbox.yview) + # Create a progress bar progress_bar = ttk.Progressbar(frame, mode='determinate') progress_bar.pack(side=tk.TOP, fill=tk.BOTH) @@ -346,4 +392,3 @@ def list_and_log_sample_files(sample_dir): # Run the application root.mainloop() -