Skip to content

This package is being developed by INVent Lab team in the Dept of Biomedical Engineering at Case Western Reserve University, under the supervision of Dr. Satish Viswanath.πŸπŸš€πŸŽ‰πŸ¦•

License

Notifications You must be signed in to change notification settings

mohsenhariri/medviz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

88 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MedViz

Optional normalization

Usage

Install the package using pip:

    pip install medviz

Or install from the source:

    pip install git+https://github.com/mohsenhariri/medviz

Import the package and use the layered_plot function

    import medviz

    medviz.layered_plot(image_path="dataset/1-1.nii", mask_paths=["dataset/small_bowel.nii", "dataset/1-1-label.nii"], mask_colors=["red", "yellow"], title="Layered Plot")

Development

Setup

  • make env
  • source env_platform_ver/bin/activate
  • make
  • make check
  • make pireq

Required packages

  • Numpy
  • Matplotlib
  • Pandas
  • Nibabel
  • Pydicom
  • Tabulate

Matplotlib Backend

If your OS doesn't have a backend GUI to render Matplotlib, you need to install pyqt5 (via PIP), then set QT_QPA_PLATFORM=wayland in your environment variables.

    make piu pyqt5
    export QT_QPA_PLATFORM=wayland

Utility Helpers

  • path_in: Converts a given path to an absolute path, optionally using the ROOT_IN environment variable as a base.

  • save_path_dir: Validates and ensures the existence of a directory path, creating it if necessary. It can also use the ROOT_OUT environment variable as a base.

  • save_path_file: Generates a unique save path for a file, appends a timestamp if the file already exists, and ensures its parent directory exists.

Slider- To do

  • Max
  • Min
  • Midian
  1. Plot layered images and masks
  2. Generate Gif

Plotting

3D plots

  1. Basic Usage: Plot a single image without any mask:
    viz.plot3d('path/to/image.nii')
  1. Plotting Multiple Images: If you have multiple images to plot:
    images = ['path/to/image1.nii', 'path/to/image2.nii']
    viz.plot3d(images)
  1. Displaying Images with Masks: To visualize images along with their corresponding masks:
    images = ['path/to/image1.nii', 'path/to/image2.nii']
    masks = ['path/to/mask1.nii', 'path/to/mask2.nii']
    viz.plot3d(images, masks=masks)
  1. Using Custom Colors: To specify custom colors for the masks:
    images = ['path/to/image1.nii', 'path/to/image2.nii']
    masks = ['path/to/mask1.nii', 'path/to/mask2.nii']
    colors = ['red', 'green']
    viz.plot3d(images, masks=masks, colors=colors)
  1. Displaying Titles: For adding titles to the plotted images:
    images = ['path/to/image1.nii', 'path/to/image2.nii']
    masks = ['path/to/mask1.nii', 'path/to/mask2.nii']
    colors = ['red', 'green']
    titles = ['Image 1', 'Image 2']
    viz.plot3d(images, masks=masks, colors=colors, titles=titles)
  1. Specifying Display Plane: You can visualize the images in different planes:
    viz.plot3d('path/to/image.nii', plane="sagittal")
  1. Saving the Plot: To save the plot to a specified location:
    viz.plot3d('path/to/image.nii', save_path='path/to/save_directory/')
  1. Specifying Rows and Columns: To organize multiple images into a specific number of rows and columns:

Specify Rows:

    images = ['path/to/image1.nii', 'path/to/image2.nii', 'path/to/image3.nii']
    viz.plot3d(images, rows=2)

This will generate a 2x2 grid, with the third image in the first cell of the second row.

Specify Columns:

    images = ['path/to/image1.nii', 'path/to/image2.nii', 'path/to/image3.nii']
    viz.plot3d(images, columns=2)

This will also generate a 2x2 grid similar to the previous example.

Specifying Both Rows and Columns: For more control, you can specify both rows and columns:

    images = ['path/to/image1.nii', 'path/to/image2.nii', 'path/to/image3.nii', 'path/to/image4.nii']
    viz.plot3d(images, rows=2, columns=2)

This will arrange the images in a 2x2 grid with each cell having one image.

  1. Combining Multiple Options: You can also combine multiple options for a comprehensive view:
    images = ['path/to/image1.nii', 'path/to/image2.nii']
    masks = ['path/to/mask1.nii', 'path/to/mask2.nii']
    titles = ["First Image with Mask", "Second Image with Mask"]
    mask_colors = ["#FF0000", "#00FF00"]
    viz.plot3d(images, masks=masks, mask_colors=mask_colors, titles=titles, save_path='path/to/save_directory/')

GIFs

Method signature:

    def gif(
        image: Union[str, Path, np.ndarray],
        masks: Optional[Union[str, Path, np.ndarray, List[Union[str, Path, np.ndarray]]]] = None,
        mask_colors: Optional[List[str]] = None,
        start_slice: Optional[int] = 0,
        end_slice: Optional[int] = None,
        slices: Optional[List[int]] = None,
        cmap: str = "gray",
        plane: str = "axial",
        save_path: Union[str, Path] = "output.gif",
        duration: int = 100,
        segments_title: Optional[List[str]] = None
    ) -> None:

Usages

load image and mask(s) from file path:

   image = 'path/to/image.nii' or 'path/to/image.nii.gz' or 'path/to/image.mha' or 'path/to/image.dcm'
   mask = 'path/to/mask.nii' or 'path/to/mask.nii.gz' or 'path/to/mask.mha' or 'path/to/mask.dcm'
   masks = ['path/to/mask1.nii', 'path/to/mask2.nii']
  1. Basic Usage:

Generate a GIF from a 3D image without any masks:

    viz.gif(image)

This will save the GIF as output.gif in the current directory.

  1. Set save path:
    viz.gif(image, save_path='path/to/save_directory/')

This will save the GIF as output.gif in the specified directory.

  1. Overlaying Mask

To overlay mask on the image:

    viz.gif(image, mask=mask)
  1. Overlaying Multiple Masks

To overlay multiple masks on the image:

    viz.gif(image, masks=masks)

This will overlay the masks in the order they are specified in the list.

  1. Using Custom Colors

To specify custom colors for the masks:

    viz.gif(image, masks=masks, mask_colors=['red', 'green'])
  1. Displaying Titles

For adding titles to the plotted images:

    viz.gif(image, masks=masks, mask_colors=['red', 'green'], segments_title=['Segment 1', 'Segment 2'])
  1. Specifying Display Plane

You can visualize the images in different planes:

    viz.gif(image, plane="sagittal")
  1. Specifying Slices

To specify the slices to be included in the GIF:

    viz.gif(image, slices=[0, 10, 20, 30, 40])
  1. Define a range of slices

To specify a range of slices to be included in the GIF:

    viz.gif(image, start_slice=20, end_slice=40)
  1. Specifying Duration

To specify the duration of each frame in the GIF, the default is 100ms:

    viz.gif(image, duration=200)
  1. Combining Multiple Options

You can also combine multiple options for a comprehensive view:

    viz.gif(image, masks=masks, mask_colors=['red', 'green'], segments_title=['Segment 1', 'Segment 2'], slices=[0, 10, 20, 30, 40], save_path='path/to/save_directory/')

2D plots

  1. 2D images.

inpute: - an array of images

viz.plot2d_images_array()
viz.plot2d_images_path()
  1. 2D image and masks- layered plot

inpute: - an image - an array of masks

viz.plot2d_layered_path()
viz.plot2d_layered_array()

Interactive plots

  1. 3D images with slider

inpute: - an array of images

viz.plot3d.images()
  1. 3D images and masks- layered plot with slider

inpute: - an array of images - an array of masks

viz.plot3d.images_masks()

Feature Excraction

About

This package is being developed by INVent Lab team in the Dept of Biomedical Engineering at Case Western Reserve University, under the supervision of Dr. Satish Viswanath.πŸπŸš€πŸŽ‰πŸ¦•

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages