marcomusy/vedo

Optimize Loading and Visualization of Multiple .nii.gz Segments in Vedo

Closed this issue · 1 comments

Description:

I am loading and visualizing several segmented body parts from a segmentation job. The segmentation resulted in approximately 120 .nii.gz files, each representing a different segment of the body. I need to visualize all these segments simultaneously in their respective locations in 3D space.

Current Issue:

When I load all the segments using Vedo, the application becomes slow and laggy. The lag significantly affects the interactivity and usability of the visualization tool. I need a way to optimize the loading and rendering process without merging the segments into a single file. Maintaining the ability to toggle the visibility of individual segments is crucial for my analysis and visualization tasks.

Code Example:

Below is the current code I am using to load and visualize the segments:

from pathlib import Path
import random
from vedo.applications import *
from vedo import *

subject = "s0024"
SEGMENTATION_PATH = "/segmentations"
directory = Path(SEGMENTATION_PATH)

file_paths_with_sizes = [(path, path.stat().st_size) for path in directory.rglob('*') if path.is_file()]

# Sort the files by size in descending order
file_paths_with_sizes.sort(key=lambda x: x[1], reverse=True)

sorted_file_paths = [str(path) for path, size in file_paths_with_sizes]

def _generate_colors(count):
    """Generate random colormap names."""
    available_colormaps = ['Accent', 'Blues', 'BrBG', 'BuGn', 'BuPu', 'CMRmap', 'Dark2', 'GnBu', 'Greens',
                            'Greys', 'OrRd', 'Oranges', 'PRGn', 'Paired', 'Pastel1', 'Pastel2', 'PiYG', 'PuBu',
                            'PuBuGn', 'PuOr', 'PuRd', 'Purples', 'RdBu', 'RdGy', 'RdPu', 'RdYlBu', 'RdYlGn', 
                            'Reds', 'Set1', 'Set2', 'Set3', 'Spectral', 'Wistia', 'YlGn', 'YlGnBu', 'YlOrBr',
                            'YlOrRd', 'afmhot', 'autumn', 'binary', 'bone', 'brg', 'bwr', 'cividis', 'cool',
                            'coolwarm', 'copper', 'cubehelix', 'flag', 'gist_earth', 'gist_gray', 'gist_heat',
                            'gist_ncar', 'gist_rainbow', 'gist_stern', 'gist_yarg', 'gnuplot', 'gnuplot2', 
                            'gray', 'hot', 'hsv', 'inferno', 'jet', 'magma', 'nipy_spectral', 'ocean', 
                            'pink', 'plasma', 'prism', 'rainbow', 'seismic', 'spring', 'summer', 'tab10', 
                            'tab20', 'tab20b', 'tab20c', 'terrain', 'turbo', 'twilight', 'twilight_shifted', 
                            'viridis', 'winter']
    
    return random.sample(available_colormaps, count)

# Load segmented volumes
volumes = []
SEGMENTS = 70
for path, color in zip(sorted_file_paths[:SEGMENTS], _generate_colors(SEGMENTS)):
    vol = Volume(path).cmap(color)
    volumes.append(vol)

show(*volumes, axes=1, bg='white', viewup='z', interactive=True)

Requirements:

  • Optimize Loading: Improve the loading time and performance when visualizing multiple segments without merging them into a single file.
  • Maintain Interactivity: Ensure that the application remains responsive and interactive even with a large number of segments loaded.
  • Toggle Visibility: Retain the ability to toggle the visibility of individual segments independently.

Request:

  • Performance Tips: Any suggestions on how to optimize the loading and rendering process in Vedo for handling multiple .nii.gz files efficiently.
  • Code Improvements: Recommendations for modifications to the current code to enhance performance while maintaining the ability to treat each segment as a separate object.
  • Best Practices: Any best practices for working with large datasets in Vedo or alternative visualization tools that could better handle this use case.

Thank you for your assistance!

was this already answered elsewhere (?)
Reopen if not.