Giter Club home page Giter Club logo

itkcontourinterpolation's Introduction

ITKMorphologicalContourInterpolation

Build, test, package

PyPI

License

Overview

An ITK-based implementation of morphological contour interpolation based off the paper:

Albu AB1, Beugeling T, Laurendeau D. "A morphology-based approach for interslice interpolation of anatomical slices from volumetric images." IEEE Trans Biomed Eng. 2008 Aug;55(8):2022-38. doi: 10.1109/TBME.2008.921158.

๐Ÿ‘จโ€๐Ÿ’ป Live API Demo โœจ

Documentation can be found in the Insight Journal article:

Zukiฤ‡ D., Vicory J., McCormick M., Wisse L., Gerig G., Yushkevich P., Aylward S. "ND Morphological Contour Interpolation", The Insight Journal. January-December, 2016. https://hdl.handle.net/10380/3563 https://insight-journal.org/browse/publication/977

Installation

Python

To install the wasm Python packages:

pip install itkwasm-morphological-contour-interpolation

To install the native Python packages:

python -m pip install --upgrade pip
python -m pip install itk-morphologicalcontourinterpolation

JavaScript

Install the JavaScript/TypeScript package:

npm install @itk-wasm/morphological-contour-interpolation

C++

Since ITK 4.11.0, this module is available in the ITK source tree as a remote module. To enable it, set:

Module_MorphologicalContourInterpolation:BOOL=ON

in ITK's CMake build configuration.

License

This software is distributed under the Apache 2.0 license. Please see the LICENSE file for details.

Acknowledgements

This work is supported by NIH grant R01 EB014346, "Continued development and maintenance of the ITK-SNAP 3D image segmentation software."

itkcontourinterpolation's People

Contributors

aylward avatar boucaud avatar dependabot[bot] avatar dzenanz avatar hjmjohnson avatar jhlegarreta avatar mseng10 avatar tbirdso avatar thewtex avatar vicory avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

itkcontourinterpolation's Issues

Segmentation fault

Hi!

I have been trying to make the interpolation work, but no matter what I try, it still returns segmentation fault, even for the official python example script with the provided sample data (SevenLabels.nrrd).

Package versions:

itk                                   5.3.0
itk-core                              5.3.0
itk-filtering                         5.3.0
itk-io                                5.3.0
itk-morphologicalcontourinterpolation 1.1.0
itk-numerics                          5.3.0
itk-registration                      5.3.0
itk-segmentation                      5.3.0

Script for reproducing error:

import itk
import sys

image = itk.imread('SevenLabels.nrrd', itk.UC)
filled = itk.morphological_contour_interpolator(image)
itk.imwrite(filled, 'Output.nrrd', compression=True)

Attached you can find the file just in case.
SevenLabels.zip

EDIT: Upon debugging I found that this line is failing: https://github.com/InsightSoftwareConsortium/ITK/blob/835dc01388d22c4b4c9a46b01dbdfe394ec23511/Wrapping/Generators/Python/PyBase/pyBase.i#L389

Thank you for your help in advance!

Python 3 Errors

Hi, I get segfaults if I use python3 to run this. Does this only work with python 2 currently?

module has no attribute 'swig'

The following code works when I use it in python 2.7 environment, but with python 3.6 I am getting this error:
AttributeError: module 'itk.MorphologicalContourInterpolationPython' has no attribute 'swig'

import itk

input_filename = 'annotation.nrrd'
output_filename = 'contoured.nrrd'

reader = itk.ImageFileReader.New(FileName=input_filename)

contoured = itk.MorphologicalContourInterpolator(Input=reader.GetOutput())

itk.imwrite(contoured, output_filename)

Finish TODOs

There are many TODOs dispersed in code. Either finish them or abandon them.

axis/label passing

Test passing (propagation to all relevant methods) of axis and label parameters

Windows support

Windows support for those that use Windows at the workplace.

Is there any ways to make the contour interpolation faster?

We are using this library to build a contouring applications. However it looks like the interpolation routine takes tremendous amount of time (like more than 20 seconds ..). Is there any ways (or configure settings somewhere) that could make such process faster? Preferably, with 1-2 seconds, which is basically similar to commercially available contouring software (e.g., Eclipse).

The code we are testing on is borrowed from the example code:

image = itk.imread(sys.argv[1], itk.UC)
filled = itk.morphological_contour_interpolator(image)
itk.imwrite(filled, sys.argv[2], compression=True)

Comprehensive testing

Test with requested region smaller than largest (automatically for all test images).
Test setting custom slice positions.
Have Jessica (per Alexis' recommendation) test the final GUI-integrated version.

Interpolation of 2 areas far away is failing

In Slicer, if I paint 2 areas in axial within a few slices of differences and the regions are not overlapping, the interpolation is producing odd result.

It would be good to:

  • detect that the regions do not overlap
  • if so, give expose an option to decide of the behavior: interpolate (but correctly) vs do not interpolate

Create validation tests

Based on the nice segmentation data that Paul sent, create validation tests where a subset of the slices are used for interpolation and the remaining segmentations are used for validation.

Improve tests.

The existing tests should be improved:

  • ITK testing conventions on the naming of the test files should be applied.
  • The ITK testing macros should be used (e.g. TRY_EXPECT_NO_EXCEPTION, EXERCISE_BASIC_OBJECT_METHODS, etc.) to avoid boilerplate code.
  • The tests should run as long as possible and return the status code at the end (i.e. use a testStatus in and change its value as tests fail: requires changing the test design).
  • The coding style should conform to the ITK coding style (Appendix Three).

how to use this module in python?

Hi, i have installed the python package, and i can find it in itk.MorphologicalContourInterpolator, but i don't know how to use it? Can you give me a demo in python? best with numpy.ndarray as input...

Thanks.

MtoN symetrically

Right now, we turn each M-to-N case into m 1-to-N cases. This creates quick (unsmooth) morphing near one end-slice. Switching to n M-to-1 cases just reverses the end-slice near which the transition is unsmooth. Both end-slices should be broken down into MxN small chunks which would then be interpolated using the 1-to-1 procedure. Optimization: dilation images created for calculation of "belongs" image could be used to create the dilation sequence.

Fix CI

Refactoring in 6fb73c0 broke the CI:

CMake Error at /home/runner/work/ITKContourInterpolation/ITK/CMake/ITKModuleAPI.cmake:88 (message):
  No such module: "RLEImage"
Call Stack (most recent call first):
  /home/runner/work/ITKContourInterpolation/ITK/CMake/ITKModuleAPI.cmake:7 (itk_module_load)
  /home/runner/work/ITKContourInterpolation/ITK/CMake/ITKModuleAPI.cmake:173 (_itk_module_use_recurse)
  /home/runner/work/ITKContourInterpolation/ITK/CMake/ITKModuleMacros.cmake:335 (itk_module_use)
  test/CMakeLists.txt:5 (itk_module_test)

is an error message from e.g. https://open.cdash.org/builds/9697918/configure

We need to request RLEImage module when building ITK in the CI.

cannot import name 'itkHelpers' from 'itk.support' (unknown location)

I installed with pip. Whenever I try to use the module, I get an ImportError. This seems to be a problem with ITK 5.2.0, and not this package.

Moreover, I can't downgrade because of incompatibility of this package with 5.1.0 (supposed to be the current solution). How did you get it to work?

Terminal output:

Traceback (most recent call last):
  File "/home/can/PycharmProjects/mask_to_mesh/examples/scripts/single-object_mitochondria/generate_mesh.py", line 18, in <module>
    single_object_category_map(
  File "/home/can/PycharmProjects/mask_to_mesh/mask_to_mesh/workflow.py", line 84, in single_object_category_map
    object_metadata_set, image_metadata_set = isolate_objects(
  File "/home/can/PycharmProjects/mask_to_mesh/mask_to_mesh/isolate_objects/main_new_way.py", line 113, in isolate_objects
    interpolated = itk.morphological_contour_interpolator(binary_stack_itk)
  File "/home/can/.cache/pypoetry/virtualenvs/mask-to-mesh-j662lBGy-py3.8/lib/python3.8/site-packages/itk/support/lazy.py", line 132, in __getattribute__
    base.itk_load_swig_module(module, namespace)
  File "/home/can/.cache/pypoetry/virtualenvs/mask-to-mesh-j662lBGy-py3.8/lib/python3.8/site-packages/itk/support/base.py", line 110, in itk_load_swig_module
    l_module = loader.load(swig_module_name)
  File "/home/can/.cache/pypoetry/virtualenvs/mask-to-mesh-j662lBGy-py3.8/lib/python3.8/site-packages/itk/support/base.py", line 259, in load
    l_spec.loader.exec_module(l_module)  # pytype: disable=attribute-error
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/can/.cache/pypoetry/virtualenvs/mask-to-mesh-j662lBGy-py3.8/lib/python3.8/site-packages/itk/support/../MorphologicalContourInterpolationPython.py", line 72, in <module>
    from itk.itkMorphologicalContourInterpolatorPython import *
  File "/home/can/.cache/pypoetry/virtualenvs/mask-to-mesh-j662lBGy-py3.8/lib/python3.8/site-packages/itk/itkMorphologicalContourInterpolatorPython.py", line 305, in <module>
    from itk.support import itkHelpers
ImportError: cannot import name 'itkHelpers' from 'itk.support' (unknown location)

How to use ITKMorphologicalContourInterpolation with two slices

@dzenanz ๏ผŒ
I am sorry to bother you, may I seek expertise on this matter?
Now I have some segmented slices, the type of them is vtkSmartPointer< vtkImageData >
such as:
I40_2
For example, I have two slices in this type, named image1 and image2.Now I want to make image1 as the first slices and image2 as the last slices, put them into ITKMorphologicalContourInterpolation. But the MCI filter requires the type of "itk::Image< unsigned char, 3 >".
How can I transform these two "vtkSmartPointer" images to "itk::Image< unsigned char, 3 >", what functions or class can I use?
Thanks for your Suggestions two months before, I had posted this question on the forum,but I haven't heard back yet. If its not too much trouble, would you mind sharing your thoughts on this issue?
On behalf of my teachers and schoolmates, I sincerely appreciate your help.

Dose it support 4d interpolation?

I have a series of the ground truth of the segmentation of 3d images on different time step, I would like to make the interpolation. But I didn't succeed. This is what I got:


ExitTrap Traceback (most recent call last)
Cell In[43], line 2
1 WASMTIME_BACKTRACE_DETAILS=1
----> 2 filled = morphological_contour_interpolation(itkwasm_image)

File \lib\site-packages\itkwasm_morphological_contour_interpolation_wasi\morphological_contour_interpolation.py:130, in morphological_contour_interpolation(input_image, label, axis, no_heuristic_alignment, no_use_distance_transform, use_custom_slice_positions, no_use_extrapolation, use_ball_structuring_element, labeled_slice_indices_axis, labeled_slice_indices_label, labeled_slice_indices)
126 for value in labeled_slice_indices:
127 args.append(str(value))
--> 130 outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs)
132 result = outputs[0].data
133 return result

File \lib\site-packages\itkwasm\pipeline.py:465, in Pipeline.run(self, args, outputs, inputs)
461 raise ValueError(f'Unexpected/not yet supported output.type {output.type}')
463 populated_outputs.append(output_data)
--> 465 ri.delayed_exit(return_code)
467 # Should we be returning the return_code?
468 return tuple(populated_outputs)

File \lib\site-packages\itkwasm\pipeline.py:131, in RunInstance.delayed_exit(self, return_code)
129 def delayed_exit(self, return_code):
130 func = self._instance.exports(self._store)["itk_wasm_delayed_exit"]
--> 131 func(self._store, return_code)

File \lib\site-packages\wasmtime_func.py:101, in Func.call(self, store, *params)
92 error = ffi.wasmtime_func_call(
93 store._context(),
94 byref(self._func),
(...)
98 len(result_tys),
99 trap)
100 if error:
--> 101 raise WasmtimeError._from_ptr(error)
103 results = []
104 for i in range(0, len(result_tys)):

ExitTrap: error while executing at wasm backtrace:
0: 0x4ba6a - !<wasm function 964>
1: 0x204937 - !<wasm function 3517>
note: using the WASMTIME_BACKTRACE_DETAILS=1 environment variable may show more debugging information

Caused by:
Exited with i32 exit status 1

==========================================================

I sincerely appreciate your help!

Threading crash

Hunt down the occasional crash which probably occurs due to multithreading access

np.uint8 support

Most labeled images have fewer than 256 labels, which is why I think it is only natural to support the data type that takes the lowest amount of space natively, for such cases, in the prebuilt binaries.

Could you add support for this data type?

Thank you, the application is amazing!

Update the README.

include

  • link to IJ article
  • how to install the Python package
  • how to enable as a Remote Module in ITK

Threading label races

Currently, different labels within the same segment are interpolated in parallel. The one which finishes last potentially overwrites the others. Should a particular rule be used, such as keeping the label with the highest number (value)?

This would impact performance a bit, but would make sure tests pass (because the result would not depend on races between threads).

Python installation failed

Hi every one,
I used two commands that was suggested to install this module but I faced with this error:
ERROR: Could not find a version that satisfies the requirement itk-morphologicalcontourinterpolation (from versions: none)
ERROR: No matching distribution found for itk-morphologicalcontourinterpolation.

BUG: AttributeError: PyCapsule_Import "_ITKCommonPython._C_API" is not valid

Encountered this Attribute Error on the line that calls the morphological contour interpolation.
I am on version ITK 5.3.0 and Python 3.10.7 and assume that my itk version may be the source of the problem?

I have tried to downgrade to itk version v5.3rc03 via pip but that gives some compatibility issues with the itk-filtering version, so I am curious if there might be a simple solution to this?

Here is the code that I am running that causes the issue

scan_image_url =URL-TO-NIFTI-MR-SCAN-IMAGE
oar_url =URL-TO-NIFTI-CONTOUR-MASK

scan_image_itk = itk.imread(scan_image_url)
oar_itk = itk.imread(oar_url)

interpolated_contour = itk.morphological_contour_interpolator(oar_itk)

which gives the following traceback and error

AttributeError                            Traceback (most recent call last)
Cell In [4], line 15
     12 scan_image_itk = itk.imread(scan_image_url)
     13 oar_itk = itk.imread(oar_url)
---> 15 interpolated_contour = itk.morphological_contour_interpolator(scan_image_itk)

File c:\Users\UDA2UH\AppData\Local\Programs\Python\Python310\lib\site-packages\itk\support\lazy.py:138, in LazyITKModule.__getattribute__(self, attr)
    136 module = self.__belong_lazy_attributes[attr]
    137 namespace = {}
--> 138 base.itk_load_swig_module(module, namespace)
    139 self.loaded_lazy_modules.add(module)
    140 for k, v in namespace.items():

File c:\Users\UDA2UH\AppData\Local\Programs\Python\Python310\lib\site-packages\itk\support\base.py:132, in itk_load_swig_module(name, namespace)
    129 # SWIG-generated modules have 'Python' appended. Only load the SWIG module
    130 # if we haven't already.
    131 loader = LibraryLoader()
--> 132 l_module = loader.load(swig_module_name)
    134 # OK, now the modules on which this one depends are loaded and
    135 # template_feature-instantiated, and the SWIG module for this one is also loaded.
    136 # We're going to put the things we load and create in two places: the
   (...)
...
---> 13     from . import _MorphologicalContourInterpolationPython
     14 else:
     15     import _MorphologicalContourInterpolationPython

AttributeError: PyCapsule_Import "_ITKCommonPython._C_API" is not valid

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.