Coder Social home page Coder Social logo

simpleitk-notebooks's Introduction

SimpleITK Notebooks

GitHub Actions Notebook Testing  CircleCI Notebook Testing   http://insightsoftwareconsortium.github.io/SimpleITK-Notebooks/   Code style: black

SimpleITK is an abstraction layer and wrapper around the Insight Segmentation and Registration Toolkit (ITK). It is available in the following programming languages: C++, Python, R, Java, C#, Lua, Tcl and Ruby.

This repository contains a collection of Jupyter Notebooks illustrating the use of SimpleITK for educational and research activities. The notebooks demonstrate the use of SimpleITK for interactive image analysis using the Python and R programming languages.

The repository and its contents can be used for:

  1. Learning SimpleITK.
  2. As a basis for your teaching activities.
  3. As a basis for your research activities.

For the latter two use cases you can take advantage of the the repository's infrastructure which supports remote data downloads and notebook testing. These readily facilitate collaborative research.

The animation below is a visualization of a rigid CT/MR registration process created with SimpleITK and Python (the script used to generate the frames for the animated gif is found in the repository's Utilities directory).

Getting Started

Note that currently SimpleITK with R is only available on Linux and Mac.

  1. Language specific details for installing the notebooks is given in the README files in the respective directories (Python, R). For general information about installing SimpleITK please see the SimpleITK read-the-docs pages.

  2. The SimpleITK API documentation is based on the C++ implementation which is readily mapped to your language of choice.

  3. Learn the general concepts underlying the implementations of segmentation and registration by reading the (ITK book). The relevant portion is "Book 2: Design and Functionality". The ITK API is significantly different from the SimpleITK one, but the general concepts are the same (e.g. combination of optimizer and similarity metric for registration).

  4. General notebook setup. By default the contents of the Jupyter notebooks do not occupy the full browser window width. To take advantage of the full window width you can either configure each notebook independently by adding the following into a code cell:

from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))

Or apply this configuration to all notebooks by adding the following to the custom.css jupyter configuration file:

.container { width:100% !important; }

On OSX/Linux this file is found in ~/.jupyter/custom/custom.css on windows it is found in C:\Users\[your_user_name]\.jupyter\custom\custom.css.

Kicking the Tires

Before you clone the repository to your computer you may want to try it out, kick the tires so to speak.

Thanks to the awesome people from the Binder Project you can try out the Python notebooks without installing a thing.

Some caveats:

  1. This is a free public service with limited resources, so may not always be available.
  2. Some of our notebooks require significant computational resources which may not be available.
  3. All cells that use the sitk.Show() command will generate an exception because they require a Fiji installation. Either ignore this or modify the code for the session.

After you launch binder, go to the Python directory and select the notebook of interest:

Binder

Contributions from the Community

We encourage contributions from the community!!!

  1. Ask questions on the ITK discourse.
  2. Report issues you encounter (compatibility/bugs) using the GitHub issue reporting system.
  3. Contribute code (instructions):
    1. bug fixes.
    2. improved versions of existing notebooks, both text and code.
    3. new notebooks.

How to Cite

If you find these notebooks or the notebook testing infrastructure useful in your research, support our efforts by citing it as:

Z. Yaniv, B. C. Lowekamp, H. J. Johnson, R. Beare, "SimpleITK Image-Analysis Notebooks: a Collaborative Environment for Education and Reproducible Research", J Digit Imaging., https://doi.org/10.1007/s10278-017-0037-8, 31(3): 290-303, 2018.

simpleitk-notebooks's People

Contributors

blowekamp avatar dave3d avatar dependabot[bot] avatar dstansby avatar ervaibhavkumar avatar hjmjohnson avatar jwj019 avatar kolibril13 avatar osy2 avatar philipmac avatar richardbeare avatar thewtex avatar zivy 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  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  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  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  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  avatar  avatar  avatar  avatar  avatar

simpleitk-notebooks's Issues

is it a error or bug in external view with 3d slicer?

when i run follow code:

sitk.Show(sitk.ReadImage(fetch_data("SimpleITK.jpg")), "SimpleITK Logo")

3DSlicer startup, load and display the SimpleITK.jpg, but this cell keep freezing, and “the debug information” in the terminal is:

where is the sitkShow.cxx, where is the "\dashboard\Miniconda3-32..."? I can't find them.

en....I delete "debugOn=True", this cell still keep freezing([IN(*)])....

is it a error or bug?

Deformable Registration doubts

Hi @zivy

There are different deformable registrations which SimpleITK supports. I don't know if any other is supported.

Lists are
DemonsRegistrationFilter, DiffeomorphicDemonsRegistrationFilter, FastSymmetricForcesDemonsRegistrationFilter, LevelSetMotionRegistrationFilter and SymmetricForcesDemonsRegistrationFilter

Can you please tell me some of my doubts

  1. What are the basic differences of these methods? I mean in which cases we should use Diffeomorphic rather than only demon? I will be grateful if you can give me some good reference to get overview about these methods.

  2. Whats the actual role of matching point ? As I increase the number it doesn't effect the result.

  3. How small RMS should be to declare it a good registration? Is there any limit we can put , then we can also bound number of iterations.

  4. Is there any function which can display displacement field vectors pictorially, at least for one 2D slice?

Thanks

gui.PointDataAquisition() in Region Growing

Hi,
I followed the instruction in https://insightsoftwareconsortium.github.io/SimpleITK-Notebooks/Python_html/30_Segmentation_Region_Growing.html to set seed points by gui.PointDataAquisition() , but no image showed up.

Is there anything wrong with my code below?

 data = sitk.ReadImage('test.nii')
 data = sitk.Cast(sitk.IntensityWindowing(data, 
                          windowMinimum=WINDOW_LEVEL[1]-WINDOW_LEVEL[0]/2.0, 
                          windowMaximum=WINDOW_LEVEL[1]+WINDOW_LEVEL[0]/2.0), 
                          sitk.sitkUInt8)
 imgsmooth = sitk.CurvatureFlow(data,timeStep=0.05,numberOfIterations=5)

 # get seeds by mouse
 point_acquisition_interface = gui.PointDataAquisition(imgsmooth, 
                                            window_level=(400,40))

seg_implicit_thresholds = sitk.ConfidenceConnected(liver_itk, 
                                                    seedList=initial_seed_point_indexes,
                                                    numberOfIterations=0,
                                                    multiplier=1,
                                                    initialNeighborhoodRadius=1,
                                                    replaceValue=1)

BTW, when i use

point_acquisition_interface.set_point_indexes([(163,226,150),
                                               (199,242,160),
                                               (146,229,141),
                                               (161,227,147),
                                               (194,261,128)])

to set seed points, it seems that everything's going right. But the result contains many isolate objects, which, in my best knowledge, is against with the nature of region growing.

image

Random Initial parameter selection for registration

@zivy

Here is a simple doubt.
As we know registration optimization algorithm like Gradient Descent etc can end up to local maxima or minima because in registration we formulate non convex optimization problem to convex problem. Right? Else we will always get global optima as a solution. Now we have seen that reaching this local optimum point is dependent upon the initial parameter selection.

I want to make these parameters random, like for rigid registration if I have 5 parameter for iteration,metric, optimization algo etc and within each parameter I will specify a range. And then I will select a set of parameter randomly and after that I want to look at the behavior of the initial guess. Because an efficient initial guess can give us better result. Is that a valid observation? Is there any way to achieve this in SimpleITK?

Thanks
Subhajit

Mattes Mutual Information basic doubts

Hi @zivy

  1. Can you please tell , whether Mattes Mutual information is a maximizing function or minimizing function.
    Metric Mattes Mutual Info and Gradient Descent Optimizer
    output was like

numofbins = 30
Optimizer stop condition: RegularStepGradientDescentOptimizerv4: Step too small after 24 iterations. Current step (7.62939e-06) is less than minimum step (1e-05).
Iteration: 25
Metric value: -0.871268982129


numofbins = 4096
Optimizer stop condition: RegularStepGradientDescentOptimizerv4: Step too small after 34 iterations. Current step (7.62939e-06) is less than minimum step (1e-05).
Iteration: 23
Metric value: -1.7890


If it is a minimization function then the lower one is better, which I suspect.

TranslationTransform (0x44fbd20)
RTTI typeinfo: itk::TranslationTransform<double, 3u>
Reference Count: 2
Modified Time: 5528423

What do we mean by Modified Time?

Thanks

Add Windows CI to GithubAction

Test the notebooks on Windows due to various advanced notebooks using parallel processing and symbolic links which needs to be tested to verify portability.

Differences between demons metric and demons registration filters

Hi there!

I'm trying to understand the differences between using the DemonsMetric in the registration method and DemonsRegistrationFilter Notebook 66.

In the notebooks, it is said that the latter is not part of the registration framework, but technically, when implementing a custom multiscale_demons, the registration filter is used as the registration algorithm. Also, at SimpleITK documentation it's said that the registration filter computes the classic Demons registration algorithm.
So wouldn't both the latter and the former be similar? Might the main difference rely on the optimizer? Could you please point me to the technical definition of the DemonsMetric and the filters, used in SimpleITK?

Thank you!

read DICOM series

Hello,
When I running the code of 03_Image_Details in jupyter notebook, there has a error about reader.GetGDCMSeriesFileName or reader.GetGDCMSeriesIDs, these functions return empty. but there are DICOM files in related path.

image

Is it about the jupyter notebook version or other reason?

I think the solution of this problem is important to me, because reading series DICOM files will be used in next tutorial.

Image compressing while using sitk.WriteImage()

Hi,

I have encountered a strange problem regarding reading of a .nii image using SimpleITK.

I have 209MB "read.nii" file, I have just read it using

readImg = sitk.ReadImage("read.nii",sitkFloat32)

and then just write it back using

sitk.WriteImage(readImg,"output.nii")

the "output.nii" becomes 103.2 MB

I want to know why is it happening? Is anything I am missing here.

Thanks

Migrate CircleCI to Github Actions

In an effort to consolidate CI platforms used across SimpleITK, the existing CircleCI PR based testing should be migrated to use GitHub actions.

Exception thrown in SimpleITK FastSymmetricForcesDemonsRegistrationFilter_Execute

Hi @zivy

I am using Demon registration with initialTransform and I have two images as Input.
Fixed and Moving
GetSize() , GetOrigin() , GetSpacing() , GetDirection() , GetNumberOfComponentsPerPixel() of these two images are

FIXED:

(480, 480, 60)
(-171.75405883789062, -184.29881286621094, -104.79915618896484)
(0.71428573131561, 0.71428573131561, 3.000001907348633)
(0.9996509902344435, -3.962109940438712e-06, 0.02641775364406197, 2.5970854287893896e-13, 0.9999999887531421, 0.00014997905157428486, -0.026417753941178738, -0.00014992670741379563, 0.9996509789915108)
1

MOVING:

(512, 512, 60)
(-169.4098663330078, -181.95379638671875, -104.86145782470703)
(0.66037738323211, 0.66037738323211, 3.000001907348633)
(0.9996509902344435, -3.962109940438712e-06, 0.02641775364406197, 2.5970854287893896e-13, 0.9999999887531421, 0.00014997905157428486, -0.026417753941178738, -0.00014992670741379563, 0.9996509789915108)
1

Error is
RuntimeError: Exception thrown in SimpleITK FastSymmetricForcesDemonsRegistrationFilter_Execute: /home/subha/build/SimpleITK-build/Code/BasicFilters/src/sitkFastSymmetricForcesDemonsRegistrationFilter.cxx:205:
sitk::ERROR: Input image movingImage does not match dimension or size of first image!

I know about shrink() which can make the size of the approximately equal, is there any other good mechanism to resize images in SimpleITK or make spacing equal using some sort of griding and interpolation like methods? I mean how to resolve this kind of issues in general?

Thanks

Optimization Methods in SimpleITK

Hi @zivy ,

I have small doubts regarding optimization methods in reRistration

  1. In SimpleITK , there is no Stochastic Gradient Descent or Adaptive SGD optimizer, is there any reason of skipping this method? I don't think for registering two image this algo would be helpful, I don't know, the algorithm tells about multiple samples optimization.

  2. In ITK there are many more Optimizer like LM, Particle Swarm etc. itk::SPSAOptimizer, itk::ParticleSwarmOptimizerBase, itk::LBFGSBOptimizer , itk::CumulativeGaussianOptimizer, and itk::LevenbergMarquardtOptimizer.
    But SimpleITK has not included these in its registration method class. Is there any way to access them via python?

Thanks

Subhajit

ModuleNotFoundError: No module named '_SimpleITK'

I installed sitkpy via: conda env create -f environment.yml and then tried importing via ipython:
import SimpleITK as sitk
and got the error:

Type 'copyright', 'credits' or 'license' for more information
IPython 7.0.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import SimpleITK as sitk
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
~\AppData\Local\Continuum\anaconda3\envs\sitkpy\lib\site-packages\SimpleITK\SimpleITK.py in swig_import_helper()
     13         try:
---> 14             return importlib.import_module(mname)
     15         except ImportError:

~\AppData\Local\Continuum\anaconda3\envs\sitkpy\lib\importlib\__init__.py in import_module(name, package)
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127

~\AppData\Local\Continuum\anaconda3\envs\sitkpy\lib\importlib\_bootstrap.py in _gcd_import(name, package, level)

~\AppData\Local\Continuum\anaconda3\envs\sitkpy\lib\importlib\_bootstrap.py in _find_and_load(name, import_)

~\AppData\Local\Continuum\anaconda3\envs\sitkpy\lib\importlib\_bootstrap.py in _find_and_load_unlocked(name, import_)

~\AppData\Local\Continuum\anaconda3\envs\sitkpy\lib\importlib\_bootstrap.py in _load_unlocked(spec)

~\AppData\Local\Continuum\anaconda3\envs\sitkpy\lib\importlib\_bootstrap.py in module_from_spec(spec)

~\AppData\Local\Continuum\anaconda3\envs\sitkpy\lib\importlib\_bootstrap_external.py in create_module(self, spec)

~\AppData\Local\Continuum\anaconda3\envs\sitkpy\lib\importlib\_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-083a0dc1974c> in <module>
----> 1 import SimpleITK as sitk

~\AppData\Local\Continuum\anaconda3\envs\sitkpy\lib\site-packages\SimpleITK\__init__.py in <module>
----> 1 from .SimpleITK import *

~\AppData\Local\Continuum\anaconda3\envs\sitkpy\lib\site-packages\SimpleITK\SimpleITK.py in <module>
     15         except ImportError:
     16             return importlib.import_module('_SimpleITK')
---> 17     _SimpleITK = swig_import_helper()
     18     del swig_import_helper
     19 elif _swig_python_version_info >= (2, 6, 0):

~\AppData\Local\Continuum\anaconda3\envs\sitkpy\lib\site-packages\SimpleITK\SimpleITK.py in swig_import_helper()
     14             return importlib.import_module(mname)
     15         except ImportError:
---> 16             return importlib.import_module('_SimpleITK')
     17     _SimpleITK = swig_import_helper()
     18     del swig_import_helper

~\AppData\Local\Continuum\anaconda3\envs\sitkpy\lib\importlib\__init__.py in import_module(name, package)
    124                 break
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127
    128

ModuleNotFoundError: No module named '_SimpleITK'

Does anyone know how to install SimpleITK properly? (I had the same issue with pip install SimpleITK , conda install -c simpleitk simpleitk)! Running anaconda3 on Windows 64...

Error in Demons Registration notebook example code

Trying to execute code of Demons Registration raises an error

transform_to_displacment_field_filter = sitk.TransformToDisplacementFieldFilter()
transform_to_displacment_field_filter.SetReferenceImage(fixed_image)

initial_transform = sitk.DisplacementFieldTransform(transform_to_displacment_field_filter.Execute(sitk.Transform()))
RuntimeError: Exception thrown in SimpleITK TransformToDisplacementFieldFilter_Execute: D:\SimpleElastix\build\SimpleITK-build\Code\BasicFilters\src\sitkTransformToDisplacementFieldFilter.cxx:178:
sitk::ERROR: Unexpected error converting transform! Possible miss matching dimensions!

Error when running Jupyter Notebooks Fetch Data

Hello,

i am having some problems while trying to load data using the Simple ITK Jupyter Notebooks. I have internet connection and I have alrealdy loaded the data from other notebooks using the same process. In the specific Registration notebooks (61, 62 and 63 so far) I get the following error when trying to load the CIRS057A_MR_CT_DICOM data:

image

The readme.txt does not exist in the directory as I checked.

Can someone help me, please?

Mutual Information metric in Deformable registrations

Hi,
@zivy

I went through some papers on Deformable registration which includes demon registration, diffeomorphic and fastSymmetric registration. Finally I have realized that these are generally used for intra-modal registration because metrics are derived from image differences which depends on the intensity(SSD and Optical flow concepts). But if we follow the same mathematical calculation with Mutual information, it will also work and eventually it will be applicable to multi-modal registrations also. In SimpleITK we have demon as metric and different filters for deformable registrations. But they are not capable of changing metric type.

I have seen AnTs has support(derived from ITKv4?) for changing metric to MI,CC with regularization Gauss,DMFFD and transformation Elastic,Symmetric etc.

Is there any way to change metric to MI in demon registration algorithm in SimpleITK also? I have not seen ITK's code, so I don't have idea whether it supports or not?

Thanks

Data is not detected as cached

When running the last cell in 00_Setup repeatedly, the downloaded data is not detected, and it is re-downloaded.

'''
fetch_data_all("Data", "Data/manifest.json")

Fetching cthead1.png
Fetching nac-hncma-atlas2013-Slicer4Version/Data/A1_grayT2.nrrd
Fetching CIRS057A_MR_CT_DICOM/readme.txt
Fetching CIRS057A_MR_CT_DICOM/readme.txt
Downloaded 96187036 of 96187036 bytes (100.00%)
Fetching B1_fixed_B2_moving0GenericAffine.mat
Fetching spherical_fiducials.mha
Fetching ct_T1.standard
Fetching B1_fixed_B2_movingComposite.h5
Fetching 2th_cthead1.png
Fetching nac-hncma-atlas2013-Slicer4Version/Data/A1_grayT1.nrrd
Fetching B1.tiff
Fetching nac-hncma-atlas2013-Slicer4Version/Data/hncma-atlas.nrrd
Fetching vm_head_rgb.mha
Fetching vm_head_mri.mha
Fetching VM1111Shrink-RGB.png
Fetching B2.tiff
Fetching coins.png
Fetching training_001_ct.mha
Fetching a_vm1108.png
Fetching SimpleITK.jpg
Fetching training_001_mr_T1.mha
'''

myshow.py for a 3D image display

Hi,

If I want to show a 3D image let say (512*512)*60 slices. The function myshow3D() is failed to give any output rendering the 3D image. I think there is some conceptual issue. Will it be able to show any kind of 3D image, like http://docs.enthought.com/mayavi/mayavi/ is for brain(not accurate though). Is there any other way to visualize a stack of images in 3D space?

Thanks

FFD using Bspline throwing _bad_alloc error

Hi @zivy
I have found that there are two way to configure mesh for doing registration using BSpline.

  1. transfromDomainMeshSize=[10]*moving.GetDimension()
    tx = sitk.BSplineTransformInitializer(fixed, transfromDomainMeshSize )

  2. grid_physical_spacing = [50.0, 50.0, 50.0]
    image_physical_size = [size*spacing for size,spacing in zip(fixed_image.GetSize(), fixed_image.GetSpacing())]
    mesh_size = [int(image_size/grid_spacing + 0.5) \ for image_size,grid_spacing in zip(image_physical_size,grid_physical_spacing)]

    initial_transform = sitk.BSplineTransformInitializer(image1 = fixed_image, transformDomainMeshSize = mesh_size, order=3)

Problem

My image dimension is [480 480 60]
In the 1st case If I put transfromDomainMeshSize = [8]*moving.GetDimension() then it gives me _bad_alloc error, while I put 6 , it started working but it takes excessive amount of time.

In the 2nd case, It does not work for < 70mm spacing, it gives error in registration.execute().

Doubts

  1. What's the difference between these two and which one is recommended?
  2. If I want to add Affine transform as global registration, then FFD using B-spline, what should I do ?

Thanks

sitk.show never stops running in Jupyter

Hello,

I have installed 3D Slicer and Sitk on my Windows 10 (Python 3.7.1, Sitk 1.2.0) computer for image registration tasks; those notebooks are really helpfull, so thanks a lot for the authors, however, I just have an issue when running sitk.show() on a jupyter cell, indeed it never stops running and I have to shutdown the notebook manually to explore the next cells...

Any suggestion will be appreciated,
Thank you.

Deformable Image registration using simpleITK python framework

I am looking for deformable registrations using SimpleITK python framework.

As in RegistrationITKV4 there are FEM based ( itkFEMRegistrationFilter.h) deformable registration and thin plate spline code is available, I was trying to figure out how to start using them in SimpleITK or python based platform.

Demon registration is available in SimpleITK.

I need a sample code snippet for how to use FEM in simpleITK( python)

Thanks

registration_errors() function working in Registration_Utilities.py

Hi,

This is not an issue, this is regarding a problem I have been encountered in image registration.
Let me first discuss my problem in brief.

Experiment :

  1. I have a reference image and a moving image.(multimodal image)
  2. Registered using lets say method A, B , C, and D.
  3. I just want to compare A,B,C,D's accuracy in registration.
  4. I don't have any golden point-set database, neither it is possible in my case. I have only three image, fixed, moving and registered.

Thoughts :

Now while I come across this registration_utilities function, I thought if the fixed image is registered with moving image accurately, then ideal case, fixed image coordinate space = registered image coordinate space.
Now if we pass some random point from Fixed image in two arguments of registration_errors(fixed_image_random,fixed_image_random,transformation_matrix).
Then fixed_image_random will be transformed to a new point set, and will be compared with fixed_image_random in some sort of distance measurements. Should this be a measure for accuracy of registration?

Other Inputs:

Is there any other way to check which method A,B,C,D is better in registration. How can we measure registration accuracy with just

  1. Fixed image
  2. Moving Image
  3. TransformationA, TransformationB, TransformationC, TransformationD
    Thanks

Slice mismatch problem in 3D MRI registration

Hi,

I have tried to register two 3D stack of images using SimpleITK Affine Registration method. But it failed to register the moving image with the fixed image.
The problem is that there is slice mismatch in the fixed and moving images.

For eg. slice no. 6 of fixed image matches with slice no. 7 of moving image. But the total number of slices in both images are 12.
Also there is movement in slices when I compare fixed with output image.

I have used the following code to register these two images
`def GlobalAffineRegistration(fixed_image,moving_image):

initial_transform = sitk.CenteredTransformInitializer(sitk.Cast(fixed_image,sitk.sitkFloat32), 
                                                                                   sitk.Cast(moving_image,sitk.sitkFloat32), 
                                                                                   sitk.AffineTransform(3),
                                                                                   sitk.CenteredTransformInitializerFilter.GEOMETRY)


# Perform simplest (single level) registration
registration_method = sitk.ImageRegistrationMethod()
registration_method.SetMetricAsMattesMutualInformation(numberOfHistogramBins=32)
registration_method.SetInterpolator(sitk.sitkLinear)
registration_method.SetOptimizerAsGradientDescent(learningRate=1.0, numberOfIterations=300, convergenceMinimumValue=1e-6, convergenceWindowSize=10)
registration_method.SetOptimizerScalesFromPhysicalShift()
registration_method.SetInitialTransform(initial_transform, inPlace=False)
final_transform = registration_method.Execute(sitk.Cast(fixed_image,sitk.sitkFloat32) , sitk.Cast(moving_image,sitk.sitkFloat32))
 out = sitk.Resample(moving, fixed, final_transform, sitk.sitkLinear, 0.0, moving.GetPixelID())			
  sitk.WriteImage(out,outFileName)

I have attached the fixed, moving and output image respectively in a .zip file for a better understanding of my problem.
Moreover when I was using MATLAB imregister function, it was able to detect slice mismatch and take care of it. Please suggest what type of method or parameter setting should I use to get rid of this type of problem.

outImage.zip

Error while executing registration

Hi @zivy ,

I was using some registration methods like bspline, demons etc. Suddenly I have encountered the below problem while going to execute registration and after printing the error on terminal, the code exits. What could be the possible reason and how I can correct the issue?

Error

File "/usr/local/lib/python2.7/dist-packages/SimpleITK/SimpleITK.py", line 11064, in Execute return _SimpleITK.ImageRegistrationMethod_Execute(self, fixed, moving) RuntimeError: Exception thrown in SimpleITK ImageRegistrationMethod_Execute: /home/subha/build/ITK/Modules/Core/Common/src/itkMultiThreader.cxx:416: itk::ERROR: MultiThreader(0x4cf8d60): Exception occurred during SingleMethodExecute

Thanks

Regards
Subhajit

Feature based Registration in SimpleITK

Is there any function in SimpleITK to find intensity dependent as well independent features from a 3D image? OpenCV have functions for SIFT, SURF features etc but they all work in 2D images. I want these in 3D as well. If we have such feature extraction facility then it can also help us in segmentation or registration quality measurement.

Any comments?

Thanks

change the default external viewer to 3D Slicer,sitk::ERROR: Unable to determine ImageIO reader

%env SITK_SHOW_COMMAND /Applications/Slicer.app/Contents/MacOS/Slicer
sitk.Show(sitk.ReadImage(fetch_data("SimpleITK.jpg")), "SimpleITK Logo", debugOn=True)

env: SITK_SHOW_COMMAND=‘/Applications/Slicer.app/Contents/MacOS/Slicer’
Fetching SimpleITK.jpg
---------------------------------------------------------------------------RuntimeError                              Traceback (most recent call last)
 in 
      1 \# Uncomment the line below to change the default external viewer to your viewer of choice and test that it works.
      2 get_ipython().run_line_magic('env', 'SITK_SHOW_COMMAND ‘/Applications/Slicer.app/Contents/MacOS/Slicer’')
----> 3 sitk.Show(sitk.ReadImage(fetch_data("SimpleITK.jpg")), "SimpleITK Logo", debugOn=True)

~/anaconda3/lib/python3.7/site-packages/SimpleITK/SimpleITK.py in ReadImage(*args)
   8874 
   8875     """
-> 8876     return _SimpleITK.ReadImage(\*args)
   8877 class ImageViewer(_object):
   8878     """

RuntimeError: Exception thrown in SimpleITK ReadImage: ../../Code/IO/src/sitkImageReaderBase.cxx:107:
sitk::ERROR: Unable to determine ImageIO reader for "/Users/apple/Documents/GitHub/SimpleITK-Notebooks-master/Data/SimpleITK.jpg"

Registration using PyCharm

Hi,

I'm using PyCharm for 3D registration with Dicom data, and i'm having some problems in the final steps because of the registration_callbacks:

Traceback (most recent call last):
File "/Users/nunoloucao/PycharmProjects/Teste_simpleitk/teste_ITK.py", line 19, in
import registration_callbacks
ModuleNotFoundError: No module named 'registration_callbacks'

i can't find it in any library.

thanks,
Nuno

example of 2D registration

Hi,
First of all thank you very much for this notebook. I have test almost all the function with R and it works very well.
I am trying to make a 2D image registration in R with SimpleITK on Linux and i was wondering if you plan to make an example for 2D registration with .png images. I work with aerial remote sensing image and i am particularly interest with the Diffeomorphic demons registration for two image with one presenting distortion due the plane movement.
I have try some of your function for registration with simulated 2D image but I didn't manage to make it work. It would be very nice to have a simple example such as the Figure 5 of "Diffeomorphic Demons: Efficient Non-parametric Image Registration" of Tom Vercauteren et al (http://www-sop.inria.fr/asclepios/Publications/Tom.Vercauteren/DiffeoDemons-NeuroImage08-Vercauteren.pdf)

here is how I have generate two square with some difference in size to further make a registration of one wit the other, in case it could help

library(raster)
library(imager)
r=raster(ncol=256,nrow=256)
r=setValues(r,0)
im1=as.cimg(r)
im1[125:150,125:150]=255
plot(im1)

im2=as.cimg(r)
im2[130:170,130:170]=255
plot(im2)

save.image(im1,"square1.png")
save.image(im2,"square2.png")

Thank you very much,

Fabien

Notebook widget imports need to be updated

When running 03_Image_Details with latest Jupyter/IPython this error occurs:

/home/matt/bin/sitk-venv/local/lib/python2.7/site-packages/IPython/html.py:14: ShimWarning: The IPython.html package has been deprecated. You should import from notebook instead. IPython.html.widgets has moved to ipywidgets.
"IPython.html.widgets has moved to ipywidgets.", ShimWarning)

update BSplineTransform example to include construction vis tuple of images

Update notebook 22_Transforms to include the BSplineTransform construction using the BSplineTransform (std::vector< Image > &coefficientImages, unsigned int order=3) constructor. Also remember to emphasize that creation+initialization is either done with this constructor or with the BSplineTransform (unsigned int dimensions, unsigned int order=3) constructor followed by setting the transform domain and parameters, but not to mix the two approaches.

sitk.GetArrayFromImage and sitk.GetImageFromArray

I use simpleITK read a image(.nii format),then I transform it to array,and again transform array into image, then I found something has changed,why this happen?
code
import numpy as np
import SimpleITK as sitk

itk_img=sitk.ReadImage('AD_001/AD_001.nii')
print(itk_img)
print(itk_img.GetSize())
print(itk_img.GetSpacing())
img=sitk.GetArrayFromImage(itk_img)
itk_img1=sitk.GetImageFromArray(img)
print(itk_img1.GetSpacing())
print(itk_img1.GetSize())
#itk_img1.SetSpacing(itk_img.GetSpacing())
#itk_img1.SetOrigin(itk_img.GetOrigin())
print(itk_img1)

the part of result
Image (0x27df6e0)
RTTI typeinfo: itk::Image<unsigned short, 3u>
Reference Count: 1
Modified Time: 965
Debug: Off
Object Name:
Observers:
none
Source: (none)
Source output name: (none)
Release Data: Off
Data Released: False
Global Release Data: Off
PipelineMTime: 942
UpdateMTime: 964
RealTimeStamp: 0 seconds
LargestPossibleRegion:
Dimension: 3
Index: [0, 0, 0]
Size: [176, 240, 256]
BufferedRegion:
Dimension: 3
Index: [0, 0, 0]
Size: [176, 240, 256]
RequestedRegion:
Dimension: 3
Index: [0, 0, 0]
Size: [176, 240, 256]
Spacing: [1.2, 1, 1]
Origin: [-138, -135, 376]
Direction:
-1 0 0
0 -1 0
0 0 1

IndexToPointMatrix:
-1.2 0 0
0 -1 0
0 0 1

PointToIndexMatrix:
-0.833333 0 0
0 -1 0
0 0 1

Inverse Direction:
-1 0 0
0 -1 0
0 0 1

PixelContainer:
ImportImageContainer (0x275e3c0)
RTTI typeinfo: itk::ImportImageContainer<unsigned long, unsigned short>
Reference Count: 1
Modified Time: 961
Debug: Off
Object Name:
Observers:
none
Pointer: 0x7fa41d482010
Container manages memory: true
Size: 10813440
Capacity: 10813440

(176, 240, 256)
(1.1999999284744263, 1.0, 1.0)
(1.0, 1.0, 1.0)
(176, 240, 256)
Image (0x2776bf0)
RTTI typeinfo: itk::Image<unsigned short, 3u>
Reference Count: 1
Modified Time: 973
Debug: Off
Object Name:
Observers:
none
Source: (none)
Source output name: (none)
Release Data: Off
Data Released: False
Global Release Data: Off
PipelineMTime: 0
UpdateMTime: 0
RealTimeStamp: 0 seconds
LargestPossibleRegion:
Dimension: 3
Index: [0, 0, 0]
Size: [176, 240, 256]
BufferedRegion:
Dimension: 3
Index: [0, 0, 0]
Size: [176, 240, 256]
RequestedRegion:
Dimension: 3
Index: [0, 0, 0]
Size: [176, 240, 256]
Spacing: [1.2, 1, 1]
Origin: [-138, -135, 376]
Direction:
1 0 0
0 1 0
0 0 1

IndexToPointMatrix:
1.2 0 0
0 1 0
0 0 1

PointToIndexMatrix:
0.833333 0 0
0 1 0
0 0 1

Inverse Direction:
1 0 0
0 1 0
0 0 1

PixelContainer:
ImportImageContainer (0x2709b50)
RTTI typeinfo: itk::ImportImageContainer<unsigned long, unsigned short>
Reference Count: 1
Modified Time: 970
Debug: Off
Object Name:
Observers:
none
Pointer: 0x43c8260
Container manages memory: true
Size: 10813440
Capacity: 10813440

generate_random_pointset() function working in Registration_utilities.py

Hi,
To generate some random points inside the image only, we must ensure that we are taking points which have intensity value > 0. The input is a SimpleITK.Image. the domain or size does not ensure that the image has only nonzero pixel. Suppose we have a 512512 image but the Field of view of the image is in 12080 or may be it can not be depicted in rectangular tile. It may have a shape or different anatomy. So my question is we should check whether the pixel value is > 0 at that point.Right? Otherwise we may somehow skip relevant point. Though the whole 512*512 get registered. Still we will be interested on random points which are actually inside the image, I guess. How should we proceed in that case?

Is there any bound of how many random points should we take for best results in suppose for 512*512? It is clear that we should not take a huge number of points from the set, it will nullify the registration error in some sense. (mean / SD). Please suggest.

Thanks

The static rendering of the Notebooks should be automatically updated.

Using Github Actions, the gh-pages branch should be automatically updated with the html rendered notebooks.

This process should be run nightly when changes have occurred to the master branch.

As some notebooks do not run with out errors ( for now to illustrate issues ), there will need to a list for notebooks not to be rendered.

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.