Skip to content

LMUK-RADONC-PHYS-RES/contouring-tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contouring tool

This software is a very early alpha / wip version of atool specifically designed for contouring 2D+t CineMRI data. While the drawing tools are functional, everything else is subject to change.

It is made public in the context of the trackrad challenge.

screenshot

Most of the icons and ui design in gernal are inspired or derived from excalidraw.

MIT License

Copyright (c) 2020 Excalidraw

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Instructions

These instructions were written for use on our own cluster/research server. The make use of singularity containers to mount a given patient folder under the /data/ path. You can adapt the program to your own needs by implementing a new adapter (see on the bottom), for your own data structure.

Prerequisites

  • You need to provide all .mha frames of a specific patient in a single folder on the the research server, e.g. /proect_data/path_to_patients/pat001, and the labels folder should also be (or will be created) inside that folder, e.g. /project_data/path_to_patients/pat001/labels.
  • Alternatively, a specific labels folder can be specified with the --labels-folder labels cli flag
  • The filename of images should end with '.mha'
  • The images should have dtype equal to float
  • The images must have dimension (1,x,y) or (x,y,1) or (x,1,y). Non-square images might result in errors, in this case contact us for bugfixes.
  • Labels are stored in the same format.
  • Select a random port number (above 5740). This instruction uses 5739 as an example, so replace this number in all commands. The tool require a unique port number and produces an error if the selected port is already in use. In this case please try again with a different port.

Workflow

  • 1.1 To contour from inside TurboVNC in Firefox go directly to point 2.

  • 1.2 To contour from the browser on your local PC, run the following in your local terminal: ssh your_username@str2cc46.radonc.med.uni-muenchen.de -L 5739:localhost:5739

    1. Enter app folder: cd /project_data_2/mridian/mridian_tracking/trackrad2025/code/contouring_apps/tom_labelling_tool/app
    1. To start the app, run the singularity containe while specifying the path to your patient of interest: singularity exec --nv --pwd /code/server --bind ./:/code/ --bind /project_data_2/path_to_your_patient_of_interest/:/data/ installation/container.sif python3 index.py --port 5739 --write true --rotate-image 180 --labels-folder labels
  • You can change --rotate-image to correctly rotate your image and --labels-folder to change the name of the labels folder Recommended: to avoid the app to cache images and always show the same, on the webpage click F12 and under Network, Disable Cache

    1. Open the adress that appears in the browser, something like http://localhost:5739/
    1. Draw contour with different tools: 'B' fills previous contour, 'I' removes small islands and press ',' (< on US keyboard) and '.' (> on US keyboard) to go back and forth between frames. Once you are done, you go to Options and click on Speichern als (or Ctrl+S) and the frames will be saved by default in the ./labels folder. Under Options, you can show or hide the contour from the previous frame, which is showed in green.
    1. Close patient by pressing Ctr+C in the terminal

Old readme

Roadmap

  • Implement loading custom adapters from paths
  • Implement keyboard control/shotcuts
  • Improve cli
  • Write docs
  • Improve design

Overview

The tool consists of 2 components:

  • core tool
  • server

The core tool is a static webpage, which needs to be build and which are hosted by the server, alongside an api serving the actual frames, labels and saving funcitonality.

For the server to host the correct files, an module called adapter is used. The default provider follows the LMU dataset and requires a folder mounted to /data with .mha files and the corresponding labels in a labels subfolder, following the same file names:

/data/
/data/frame_001.mha
/data/frame_002.mha
/data/labels/frame_001.mha
/data/labels/frame_002.mha

Custom adapters can be implemented and provided via the cli to adapt the server to other folder structures, or file types. (future update)

Getting started

To get started, you need to first build the webpage components and than run the sever. Note that the tool uses autosaving, which could aciventally result in file corruption. By default storing to disk is therefore disabled. To enable storing to disk pass a --save true flag.

Building webpages (optionally)

In a first step, the webpages for the core tool and the docs need to be build. This source code may be distpibuted, with this step already done.

Alternativly, run the build scipt, which creates a docker container, uses it to build the docs and the core tool, and deletes the docker image

cd installation
./build_web.sh

Singularity

The simplest way to run the tool is using Singularity. To do so bulild container run

cd installation
./build_singularity.sh

once the container is build, simply cd to the top level and run the following command, replacing /path/to_nii_gz_folder/ with your target path:

singularity exec --nv --pwd /code/server --bind ./:/code/ --bind /path/to_nii_gz_folder/:/data/ insttallation/container.sif python3 index.py --port 5739 --write true

Example:

singularity exec --nv --pwd /code/server --bind ./:/code/ --bind /project_data/mridian/mridian_tracking/tbloecker/data/testing/full_scans_fixed/abdomen_patient0017/raw_cine/20211202130059_converted_output_scan_5_2D_rad_FOV270_8FPS_th5_sag/:/data/ installation/container.sif python3 index.py --port 5739 --write true

Docker

TODO

Directly

TODO

Custom adapters

class BaseAdapter:
    def __init__(self, **kwargs):
        pass
    def index(self):
        pass
    def get_scan(self, scan_id):
        pass
    def get_scan_preview(self, scan_id):
        pass
    def get_frame(self, scan_id, frame_idx):
        pass
    def get_frame_label_contour(self, scan_id, frame_idx):
        pass
    def save_frame_label(self, scan_id, frame_idx):
        pass

License

This license only applies to the Software contained in this repository. All other materials made available in the context of the TrackRAD2025 competition may be licensed under different terms.

Copyright 2025 The TrackRAD2025 organizers

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors