Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 3D_UNet
  • 3d_watershed
  • conv_zarr_tiff_folders
  • convert_tiff_folders
  • layered_surface_segmentation
  • main
  • memmap_txrm
  • notebook_update
  • notebooks
  • notebooksv1
  • optimize_scaleZYXdask
  • save_files_function
  • scaleZYX_mean
  • test
  • threshold-exploration
  • tr_val_te_splits
  • v0.2.0
  • v0.3.0
  • v0.3.1
  • v0.3.2
  • v0.3.3
  • v0.3.9
  • v0.4.0
  • v0.4.1
24 results

Target

Select target project
  • QIM/tools/qim3d
1 result
Select Git revision
  • 3D_UNet
  • 3d_watershed
  • conv_zarr_tiff_folders
  • convert_tiff_folders
  • layered_surface_segmentation
  • main
  • memmap_txrm
  • notebook_update
  • notebooks
  • notebooksv1
  • optimize_scaleZYXdask
  • save_files_function
  • scaleZYX_mean
  • test
  • threshold-exploration
  • tr_val_te_splits
  • v0.2.0
  • v0.3.0
  • v0.3.1
  • v0.3.2
  • v0.3.3
  • v0.3.9
  • v0.4.0
  • v0.4.1
24 results
Show changes
"""Visualization tools"""
import matplotlib.figure
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
from matplotlib import colormaps
from qim3d.utils._logger import log
import torch
import matplotlib
def plot_metrics(
*metrics,
linestyle="-",
batch_linestyle="dotted",
labels: list = None,
*metrics: tuple[dict[str, float]],
linestyle: str = "-",
batch_linestyle: str = "dotted",
labels: list|None = None,
figsize: tuple = (16, 6),
show=False
show: bool = False
):
"""
Plots the metrics over epochs and batches.
......@@ -79,8 +81,13 @@ def plot_metrics(
def grid_overview(
data, num_images=7, cmap_im="gray", cmap_segm="viridis", alpha=0.5, show=False
):
data: list|torch.utils.data.Dataset,
num_images: int = 7,
cmap_im: str = "gray",
cmap_segm: str = "viridis",
alpha: float = 0.5,
show: bool = False
)-> matplotlib.figure.Figure:
"""Displays an overview grid of images, labels, and masks (if they exist).
Labels are the annotated target segmentations
......@@ -174,13 +181,13 @@ def grid_overview(
def grid_pred(
in_targ_preds,
num_images=7,
cmap_im="gray",
cmap_segm="viridis",
alpha=0.5,
show=False,
):
in_targ_preds: tuple[np.ndarray, np.ndarray, np.ndarray],
num_images: int = 7,
cmap_im: str = "gray",
cmap_segm: str = "viridis",
alpha: float = 0.5,
show: bool = False,
)-> matplotlib.figure.Figure:
"""Displays a grid of input images, predicted segmentations, ground truth segmentations, and their comparison.
Displays a grid of subplots representing different aspects of the input images and segmentations.
......@@ -282,7 +289,7 @@ def grid_pred(
return fig
def vol_masked(vol, vol_mask, viz_delta=128):
def vol_masked(vol: np.ndarray, vol_mask: np.ndarray, viz_delta: int=128) -> np.ndarray:
"""
Applies masking to a volume based on a binary volume mask.
......
......@@ -19,9 +19,9 @@ def vectors(
vec: np.ndarray,
axis: int = 0,
volume_cmap:str = 'grey',
vmin:float = None,
vmax:float = None,
slice_idx: Optional[Union[int, float]] = None,
vmin: float|None = None,
vmax: float|None = None,
slice_idx: Union[int, float]|None = None,
grid_size: int = 10,
interactive: bool = True,
figsize: Tuple[int, int] = (10, 5),
......
from .installation import Installer
from .run import itk_vtk
from .helpers import NotInstalledError
\ No newline at end of file
import subprocess
import platform
from pathlib import Path
import os
import webbrowser
import threading
import time
import qim3d.utils
from qim3d.utils._logger import log
# from .helpers import get_qim_dir, get_nvm_dir, get_viewer_binaries, get_viewer_dir, get_node_binaries_dir, NotInstalledError, SOURCE_FNM
from .helpers import *
import webbrowser
import threading
import time
from .installation import Installer
# Start viewer
......@@ -73,7 +74,7 @@ def run_within_qim_dir(port=3000):
)
def itk_vtk(
def try_opening_itk_vtk(
filename: str = None,
open_browser: bool = True,
file_server_port: int = 8042,
......@@ -120,8 +121,8 @@ def itk_vtk(
1.85GB [00:17, 111MB/s]
Loading Okinawa_Foram_1.tif
Loading: 100%
1.85GB/1.85GB [00:02<00:00, 762MB/s]
Loading: 100%
1.85GB/1.85GB [00:02<00:00, 762MB/s]
Loaded shape: (995, 1014, 984)
Using virtual stack
Exporting data to OME-Zarr format at Okinawa_Foram_1.zarr
......@@ -207,3 +208,34 @@ def itk_vtk(
# If we still get an error, it is not installed in location we expect it to be installed and have to raise an error
# which will be caught in the command line and it will ask for installation
raise NotInstalledError
def itk_vtk(
filename: str = None,
open_browser: bool = True,
file_server_port: int = 8042,
viewer_port: int = 3000
):
"""
Command to run in cli/__init__.py. Tries to run the vizualization,
if that fails, asks the user to install it. This function is needed
here so we don't have to import NotInstalledError and Installer,
which exposes these to user.
"""
try:
try_opening_itk_vtk(filename,
open_browser=open_browser,
file_server_port = file_server_port,
viewer_port = viewer_port)
except NotInstalledError:
message = "Itk-vtk-viewer is not installed or qim3d can not find it.\nYou can either:\n\to Use 'qim3d viz SOURCE -m k3d' to display data using different method\n\to Install itk-vtk-viewer yourself following https://kitware.github.io/itk-vtk-viewer/docs/cli.html#Installation\n\to Let qim3D install itk-vtk-viewer now (it will also install node.js in qim3d library)\nDo you want qim3D to install itk-vtk-viewer now?"
print(message)
answer = input("[Y/n]:")
if answer in "Yy":
Installer().install()
try_opening_itk_vtk(filename,
open_browser=open_browser,
file_server_port = file_server_port,
viewer_port = viewer_port)
\ No newline at end of file