-
Notifications
You must be signed in to change notification settings - Fork 69
geodesic notebook #277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thewtex
wants to merge
2
commits into
InsightSoftwareConsortium:master
Choose a base branch
from
thewtex:geodesic-notebook
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
geodesic notebook #277
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
48 changes: 24 additions & 24 deletions
48
src/Segmentation/LevelSets/SegmentWithGeodesicActiveContourLevelSet/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 195 additions & 0 deletions
195
src/Segmentation/LevelSets/SegmentWithGeodesicActiveContourLevelSet/Code.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "7c8b935b", | ||
"metadata": {}, | ||
"source": [ | ||
"# Segment with geodesic active contour level set" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "196c6071", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import sys\n", | ||
"import os\n", | ||
"from urllib.request import urlretrieve\n", | ||
"\n", | ||
"import itk\n", | ||
"\n", | ||
"from itkwidgets import view" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "d6f35e01", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"input_filename = 'BrainProtonDensitySlice.png'\n", | ||
"if not os.path.exists(input_filename):\n", | ||
" url = 'https://data.kitware.com/api/v1/file/57b5d8028d777f10f2694bbf/download'\n", | ||
" urlretrieve(url, input_filename)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "52104b31", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"InputPixelType = itk.ctype('float')\n", | ||
"\n", | ||
"input_image = itk.imread(input_filename, InputPixelType)\n", | ||
"\n", | ||
"view(input_image)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "4297e2ac", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"smoothed = itk.curvature_anisotropic_diffusion_image_filter(input_image,\n", | ||
" time_step=0.125,\n", | ||
" number_of_iterations=5,\n", | ||
" conductance_parameter=9.0)\n", | ||
"view(smoothed)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "99186583", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"sigma = 1.0\n", | ||
"\n", | ||
"gradient_magnitude = itk.gradient_magnitude_recursive_gaussian_image_filter(smoothed,\n", | ||
" sigma=sigma)\n", | ||
"view(gradient_magnitude)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "8a219f34", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"alpha = -0.5\n", | ||
"beta = 3.0\n", | ||
"\n", | ||
"sigmoid = itk.sigmoid_image_filter(gradient_magnitude,\n", | ||
" output_minimum=0.0,\n", | ||
" output_maximum=1.0,\n", | ||
" alpha=alpha,\n", | ||
" beta=beta)\n", | ||
"\n", | ||
"view(sigmoid)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "499443a8", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"Dimension = input_image.GetImageDimension()\n", | ||
"seeds = itk.VectorContainer[itk.UI, itk.LevelSetNode[InputPixelType, Dimension]].New()\n", | ||
"seeds.Initialize()\n", | ||
"\n", | ||
"seed_position = itk.Index[Dimension]()\n", | ||
"seed_position[0] = 81\n", | ||
"seed_position[1] = 114\n", | ||
"node = itk.LevelSetNode[InputPixelType, Dimension]()\n", | ||
"node.SetValue(-5.0)\n", | ||
"node.SetIndex(seed_position)\n", | ||
"seeds.InsertElement(0, node)\n", | ||
"\n", | ||
"fast_marching = itk.fast_marching_image_filter(trial_points=seeds,\n", | ||
" speed_constant=1.0,\n", | ||
" output_size=input_image.GetBufferedRegion().GetSize())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "d2c5e205", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"propagation_scaling = 2.0\n", | ||
"number_of_iterations = 800\n", | ||
"\n", | ||
"geodesic_active_contour = \\\n", | ||
" itk.geodesic_active_contour_level_set_image_filter(fast_marching,\n", | ||
" propagation_scaling=propagation_scaling,\n", | ||
" curvature_scaling=1.0,\n", | ||
" advection_scaling=1.0,\n", | ||
" maximum_r_m_s_error=0.02,\n", | ||
" number_of_iterations=number_of_iterations,\n", | ||
" feature_image=sigmoid)\n", | ||
"\n", | ||
"view(geodesic_active_contour)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "1269f1b4", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"OutputPixelType = itk.ctype('unsigned char')\n", | ||
"thresholded = itk.binary_threshold_image_filter(geodesic_active_contour,\n", | ||
" lower_threshold=-1000.0,\n", | ||
" upper_threshold=0.0,\n", | ||
" outside_value=itk.NumericTraits[OutputPixelType].min(),\n", | ||
" inside_value=itk.NumericTraits[OutputPixelType].max(),\n", | ||
" ttype=[type(geodesic_active_contour), itk.Image[OutputPixelType,Dimension]])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "58bdf582", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"view(thresholded)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Point picker for itkwidgets would come in handy here for interactive experimentation.
Reply via ReviewNB
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, on the agenda :-).