Giter Site home page Giter Site logo

joostjm / slicercaseiterator Goto Github PK

View Code? Open in Web Editor NEW
13.0 6.0 10.0 263 KB

Simple Scripted Module to batch process patients in 3D Slicer

License: BSD 3-Clause "New" or "Revised" License

Python 96.87% CMake 3.13%
3d-slicer 3d-slicer-extension

slicercaseiterator's Introduction

SlicerCaseIterator

SlicerCaseIterator is a scripted module extension for 3D slicer. It's purpose is to streamline the segmentation of image datasets by handling loading and saving.

Usage

Input Data

The input for SlicerCaseIterator is a csv-file containing the file locations of the images and/or labelmaps that have to be segmented. The first row should be a header row, with each subsequent row representing one case.

By providing column names in the module interface, columns containing (absolute or relative) paths to the images/labelmaps. The main image is loaded last and set as background image.

Additional images/labelmaps can be loaded by specifying the respective column names as a comma separated list in the Additional images Column and Additional masks Column, with the last image specified here loaded as the foreground image (in all 3 slice viewers).

If you already processed some part of the batch or need to start at a specific case, you can do so by specifying the number at the Start postion parameter (with 1 representing the first case).

When input data is valid, press Start Batch and start segmenting!

Case Navigation

When a batch is loaded, the users can navigate between cases using the Previous Case and Next Case buttons that are then visible on the module interface.

In addition to the buttons, navigation also be controlled using 2 keyboard shortcuts:

  • Ctrl + N: Go to next case
  • Ctrl + P: Go to previous case (in case the first case is active, nothing happens)

When the last case is selected and the user moves to the next case, the current case is closed and a message indicating the batch is done is shown (navigation is then disabled).

Exiting the navigation prior to reaching is possible using the Reset button, which exits the navigation (the case is not saved and not closed).

Console Output

On the python console SlicerCaseIterator prints information about the current case. Output can contain the following:

  • The case number that is loaded. If the table contains a column patient or ID, the value of this cell for the current row is added to this message, e.g. Loading next patient (3/5): breast1...
  • An info messages when the case is closed.
  • For each new file that is saved, the full path location of the new file is printed.
  • Errors and warnings about invalid or missing input.

Invalid input

When the input is invalid (e.g. unknown column, incorrect path), error messages detailing the error are shown.

Output Customization

The following customization is available when processing a batch of cases:

  • Reader name: Any string specified here gets appended to filenames used to save labelmaps (both new labelmaps and labelmaps that were specified in the input file). This can help to prevent inadvertently overwriting files and to keep track of who made the labelmaps.
  • Go to Editor: Check this to automatically switch to the editor module whenever a new case is loaded.
  • Save loaded masks: Check this to enable resaving of any labelmaps that were specified in the input file and loaded (with the optional change in filename).
  • Save new masks: Check this to enable saving of any newly added labelmaps and/or labelmaps that were not loaded by SlicerCaseIterator. Again, with to optional suffix specified in Reader name.

When both Save loaded masks and Save new masks are unchecked, nothing is saved, and SlicerCaseIterator will only show you the cases. N.B. any newly added labelmaps and changes are discarded when the user switches to a different case!

Example

The format of the csv file is pretty simple but needs to be customized for the layout of your data. Here's a simple example to generate a csv file for a typical layout, such as /data/Examples/pat1/pat1.nii.gz and /data/Examples/pat1/pat1-label.nii.gz.

pathFormat = '/data/Examples/pat%d'
imageFormat = 'pat%d.nii.gz'
maskFormat = 'pat%d-label.nii.gz'

with open('/tmp/chd.csv', 'w') as fp:
    # write header row
    fp.write("path,image,mask\n")
    # write a line for each study
    for patIndex in range(19):
        fp.write("%s,%s,%s\n" % (pathFormat % patIndex, imageFormat % patIndex, maskFormat % patIndex))

slicercaseiterator's People

Contributors

che85 avatar cpinter avatar jcfr avatar joostjm avatar lassoan avatar pieper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

slicercaseiterator's Issues

About the table

Dear, Professor JoostJM.
I installed SlicerCaseIterator and still have some problems. The .csv table should be created including the dir of all volume and segment before loading? Can I save/write a loaded volume and mask segmentation in slicer by this module? I tried to do that but nothing happen after clicking the batch buttom.

Extension fails in slicer 4.10

SlicerCaseIterator fails in latest release of 3dSlicer.

~/tools/Slicer-4.10.0-linux-amd64/Slicer
  Error(s):
    CLI executable: /home/sansomk/.config/NA-MIC/Extensions-27501/SlicerCaseIterator/lib/Slicer-4.10/qt-scripted-modules/SlicerCaseIterator.py
    The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.
Fail to instantiate module  "SlicerCaseIterator"

I also made the script executable and got the following error:

  Error(s):
    CLI executable: /home/sansomk/.config/NA-MIC/Extensions-27501/SlicerCaseIterator/lib/Slicer-4.10/qt-scripted-modules/SlicerCaseIterator.py
    Traceback (most recent call last):
  File "/home/sansomk/.config/NA-MIC/Extensions-27501/SlicerCaseIterator/lib/Slicer-4.10/qt-scripted-modules/SlicerCaseIterator.py", line 21, in <module>
    import vtk, qt, ctk, slicer
  File "/home/sansomk/tools/Slicer-4.10.0-linux-amd64/lib/Slicer-4.10/python2.7/site-packages/vtk.py", line 12, in <module>
    all_m = importlib.import_module('vtkmodules.all')
  File "/home/sansomk/tools/Slicer-4.10.0-linux-amd64/lib/Python/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/sansomk/tools/Slicer-4.10.0-linux-amd64/lib/Slicer-4.10/python2.7/site-packages/vtkmodules/all.py", line 7, in <module>
    from .vtkCommonKit import *
  File "/home/sansomk/tools/Slicer-4.10.0-linux-amd64/lib/Slicer-4.10/python2.7/site-packages/vtkmodules/vtkCommonKit.py", line 9, in <module>
    from vtkCommonKitPython import *
ImportError: No module named vtkCommonKitPython

    CLI executable: /home/sansomk/.config/NA-MIC/Extensions-27501/SlicerCaseIterator/lib/Slicer-4.10/qt-scripted-modules/SlicerCaseIterator.py
    Failed to retrieve Xml Description
Fail to instantiate module  "SlicerCaseIterator"

Slicer (Self)tests and screenshots

It would be nice to have some self-tests for this module in Slicer as well as screenshots in the Slicer Extension manager.

That way the user would also get a better idea of how the module would look like in action...

Change Icon

Develop an icon that better suits this extension than the current, default extension icon.

ModuleNotFoundError

Hello,

I got this error on startup:

Python 3.6.7 (default, Mar 24 2020, 03:05:54) 
[GCC 5.3.1 20160406 (Red Hat 5.3.1-6)] on linux2
>>> 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/fernando/opt/Slicer/Nightly/lib/Python/lib/python3.6/imp.py", line 170, in load_source
    module = _exec(spec, sys.modules[name])
  File "<frozen importlib._bootstrap>", line 618, in _exec
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/fernando/.config/NA-MIC/Extensions-28875/SlicerCaseIterator/lib/Slicer-4.11/qt-scripted-modules/SlicerCaseIterator.py", line 19, in <module>
    from SlicerDevelopmentToolboxUtils.buttons import *
ModuleNotFoundError: No module named 'SlicerDevelopmentToolboxUtils'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.