GithubHelp home page GithubHelp logo

insightsoftwareconsortium / itkminimalpathextraction Goto Github PK

View Code? Open in Web Editor NEW
28.0 14.0 23.0 2.98 MB

Vessel and tube centerline extraction

Home Page: http://www.insight-journal.org/browse/publication/213

License: Apache License 2.0

C++ 84.90% CMake 8.70% Shell 0.94% Python 4.38% Dockerfile 0.96% Clojure 0.13%
itk-module

itkminimalpathextraction's People

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

Watchers

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

itkminimalpathextraction's Issues

Make instantiation of cost function internal

Why is the (special) cost function (SingleImageCostFunction) not instantiated internally? From the publication it seems that

PathFilterType :: CostFunctionType :: Pointer cost =  
   PathFilterType :: CostFunctionType :: New ();

PathFilterType :: Pointer pathFilter = PathFilterType :: New ();
pathFilter -> SetCostFunction ( cost );

is expected when employing SpeedFunctionToPathFilter.
What cases could there be where the cost function here would not be the predefined SingleImageCostFunction?
If there are no other, the instantiation of cost function could be done internally, so that it is not necessary when using SpeedFunctionToPathFilter.

Interpolator for gradient calculation is linear, i.e. not using the interpolator set for the cost function

Trying to solve #61 I found that the interpolator that is used to calculate the gradient is always linear

using InterpolateImageFunctionType = LinearInterpolateImageFunction<TInputImage, TCoordRep>;

and not using the interpolator that is (possibly) set for the cost function
/** Get/set the Interpolator. */
itkSetObjectMacro( Interpolator, InterpolatorType );
itkGetConstObjectMacro( Interpolator, InterpolatorType );

It seems the cost function interpolator is used in case iterateNeighborhoodOptimizer (which uses GetValue) is employed
return static_cast<MeasureType>( m_Interpolator->Evaluate(point) );

but not when the gradient is computed (which uses GetDerivative)
output = m_GradientImageFunction->Evaluate(point);

This however does not seem to be the issue of #61 (where a linear interpolator was used anyway), so posting as an issue on its own.

Key Error for SpeedFunctionPathInformation

Hi,
Your module seems really cool and is also perfect for my use. Thanks for the great work in advance!

I tried running the example code "DigitalSubtractionAngiographyVesselPath". Unfortunately, I receive an error message at the following point:

SpeedFunctionPathInformation_KeyError

Would you by any chance know, why this happens? Should I do anything differently?

Cheers,
heinermh

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).

Slow instantiation of SpeedFunctionPathInformation

Hi,
I tested the python example code on my laptop and found the instantiation of SpeedFunctionPathInformation is very slow.

It takes about 7s to run the following line with Core i7-10510U and 8GB RAM.
PathInformationType = itk.SpeedFunctionPathInformation[PointType]

Is there some time-consuming operation during the instantiation? Is there any way to speed it up in python?

Thx.

Extraction of an incorrect path

Hello!
Thanks for this project contributing to ITK!

I try to use this module for paths extraction from angiographic images. But the algorithm works incorrectly sometimes.

For example:
1

2

Also this error occurs even at the test data. For example, Noise-01-Speed.mhd

My test speed image and start/end points:
test_image.zip

I use python wrappings and GradientDescentOptimizer:

import itk

def mpe(speed_image, start_point, end_point, way_points=None):
    # ITK Types
    Point = itk.Point.F2
    CostFunction = itk.SingleImageCostFunction.IF2
    Interpolator = itk.LinearInterpolateImageFunction.IF2D
    PathInformation = itk.SpeedFunctionPathInformation.PD2
    MinimalPathExtractor = itk.SpeedFunctionToPathFilter.IF2PPP2

    interpolator = Interpolator.New()

    cost_function = CostFunction.New()
    cost_function.SetInterpolator(interpolator)

    optimizer = itk.GradientDescentOptimizer.New()
    optimizer.SetNumberOfIterations(1000)

    path_info = PathInformation.New()
    path_info.SetStartPoint(Point(start_point))
    path_info.SetEndPoint(Point(end_point))

    if way_points:
        for p in way_points:
            path_info.AddWayPoint(Point(p))

    path_extractor = MinimalPathExtractor.New()
    path_extractor.SetInput(speed_image)
    path_extractor.SetCostFunction(cost_function)
    path_extractor.SetOptimizer(optimizer)
    path_extractor.SetTerminationValue(1.0)
    path_extractor.AddPathInformation(path_info)

    path_extractor.Update()

    path = path_extractor.GetOutput(0)
    vertices_list = path.GetVertexList()

    if vertices_list.Size() == 0:
        raise ValueError('Path has not been found')

    px = []
    py = []

    for i in range(vertices_list.Size()):
        vertex = vertices_list.ElementAt(i)
        px.append(vertex[0])
        py.append(vertex[1])

    return px, py

Gradient sometimes zero (which prevents a gradient decent optimizer from decenting)

I have experienced many cases where I can extract a path with the IterateNeighborhoodOptimizer but where the GradientDescentOptimizer does not start to decent even though the speed function is continuous (based on a binary segmentation), apparently because the initial local gradient is calculated to be zero (even though start- and end-point, speed function etc are kept the same).
I have a vague feeling that this thresholding:

// NOTE: The cost function may undefined / unreachable areas
// (indicated by very large values) which may skew the gradient.
// To avoid this skewing effect, we reset gradient values larger
// than a given threshold.
if ( itk::Math::abs (derivative[i]) > DerivativeThreshold )
{
derivative[i] = 0.0;
}

to a hard coded value of 15.0:
constexpr typename DerivativeType::ValueType DerivativeThreshold = 15.0;

could be the culprit.

Another possible reason I could imagine is that the floating point precision might not suffice under some circumstances to calculate a non-zero gradient even if there is no extrema in the cost function at the current optimizer position.

I use this CLI for the testing:
https://github.com/romangrothausmann/ITK-CLIs/blob/bfb1312142d505cacd6770e4d5acc23475290c8f/min-path_seg.cxx

Python wrapping itk - SpeedFunctionToPathFilter returns zero points of centerline

Hi everyone,
first of all I would like to thank you for this module, it seems to work great for given example:
https://github.com/InsightSoftwareConsortium/ITKMinimalPathExtraction/blob/master/examples/DigitalSubtractionAngiographyVesselPath.ipynb

Unfortunately when I tried it on my data which are: .png file of vessels and .mdh and .zraw files generated from a DICOM the program from the example returns 0 points as an extracted centerline without any error.
GetVertexList() returns 0 instead of ie. 2200.
I changed nothing in it except of files and Points on a path.
My utils are:

  • Python 3.6.9
  • ITK 5.1.0

I'm wondering if problem could be in my speed image (.mdh, .zraw) or because my image file is itkImageRGBUC2 instead of itkImageUC2 from the example.

I will be thankful for some advices about it.

Regards
Franek

documentation/comment missing in itkIterateNeighborhoodOptimizer

Going through the code, I am wondering why i goes up to 2 here (not FullyConnected):


in contrast to just 1 here (FullyConnected):

If that is correct, it might be worth a comment in the code, since a reason for that irregularity is non-obvious.

kernel of DigitalSubtractionAngiographyVesselPath.ipynb dies for different path points

Hello,
I was playing around with the DigitalSubtractionAngiographyVesselPath.ipynb example and noticed that if I change the path file to other points, a lot of times the kernel dies at the last view function (view(dsa, geometries=path, ui_collapsed=True)).
When I use my own image, which is smaller, I am completely unable to find a combination of points that works.
I moved the code to VS Code in hope that I would get an error message but the script just stops executing in the view function after the viewer is initialized.

Here are some examples of paths that failed for me:
Path: [394.00, 203.00] [0.00, 0.00]
Path: [394.00, 203.00] [1.00, 20.00]
Path: [394.00, 203.00] [001.00, 020.00]
Path: [94.00, 203.00] [60.00, 230.00] [250.00, 190.00]
Path: [204.00, 23.00] [120.00, 80.00] [273.00, 19.00] [94.00, 173.00] [394.00, 121.00] [403.00, 237.00]

Apparently the view function is not the problem but the value for path.GetVertexList().Size() is 0 for the paths.

The original path in the example works fine, so I don't think that it is a setup problem.
Can I debug this somehow, are there restrictions for possible points or is this a bug?

Cheers :)

PyCapsule_Import "_ITKCommonPython._C_API" is not valid

My environment:

cat /etc/os-release:

NAME="Ubuntu"
VERSION="16.04.7 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.7 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

Environment:

Miniconda3
Python=3.9.7
itk=5.3.0

Calling the following python code:

PointType = itk.Point[itk.D,3]
PathInformationType = itk.SpeedFunctionPathInformation[PointType]

I get the error:
**AttributeError: PyCapsule_Import "_ITKCommonPython._C_API" is not valid**

the path coordinate result is out of image range

Hello,

Thanks for this project.I want find 3d vessel minimalpath,i try the sample of Synthetic-04-Speed.mhd,and the path result is right,but when i change to my data,the path result is out of image range.i debug the program,and find the data of Synthetic-04-Speed.mhd,that spacing is (1,1,1),origin is (0,0,0),the spacing and origin of my data is (0.65,0.65,3),(127.4,-32.4,56.7).and i make another test,resample my data with spacing(1,1,1),and set origin to (0,0,0),the result is right.
so i want to know how to set the program without change image spacing and origin message?

another demand,there have c++ examples,can share some python examples?

thanks!

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.