Skip to content
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

Added an option for keypoints transformation #2533

Merged
merged 20 commits into from Nov 28, 2019

Conversation

lrouhier
Copy link
Contributor

@lrouhier lrouhier commented Nov 21, 2019

This PR aims to add the -label flag to the sct_apply_transfo script. This flag can be used when applying a warping field to images containing point-like labels (e.g., discs label).
It performs the following :

  • Change interpolation to 'nearest neighbor'
  • Dilate labels on the image
  • Apply the warping field to the dilated image
  • Apply cubic_to_point function to retrieve point-like labels on the transformed image.

Fixes #2519

lrouhier and others added 9 commits November 20, 2019 14:48
…n to perform because the input file contains point like label. It seems fonctionnal but is still a work in progress. The transformed file overwrite the first created one. the option is here activated by default but an accepted argument
…n question about where to save the actual straight file before using cubic to points.
…ate the dilatation and nearest neighbors interpolation.
@lrouhier lrouhier changed the title adding an option for keypoints transformation in sct_apply_transfo adding an option for keypoints transformation in sct_apply_transfo (fix #2519) Nov 21, 2019
@jcohenadad jcohenadad changed the title adding an option for keypoints transformation in sct_apply_transfo (fix #2519) Added an option for keypoints transformation in sct_apply_transfo Nov 21, 2019
@jcohenadad jcohenadad self-requested a review November 21, 2019 21:40
@@ -19,10 +19,12 @@
import sys, io, os, time, functools
import argparse


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from spinalcordtoolbox.utils import Metavar, SmartFormatter
from spinalcordtoolbox.image import Image
from spinalcordtoolbox.cropping import ImageCropper


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single line

@@ -120,7 +128,7 @@ def get_parser():


class Transform:
def __init__(self, input_filename, fname_dest, list_warp, list_warpinv=[], output_filename='', verbose=0, crop=0,
def __init__(self, input_filename, fname_dest, list_warp, list_warpinv=[], output_filename='', verbose=0, crop=0,label=0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after comma-- PEP8

@@ -132,7 +140,8 @@ def __init__(self, input_filename, fname_dest, list_warp, list_warpinv=[], outpu
self.verbose = verbose
self.remove_temp_files = remove_temp_files
self.debug = debug

self.label=label
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space between =.
PEP8

@@ -142,6 +151,9 @@ def apply(self):
verbose = self.verbose
remove_temp_files = self.remove_temp_files
crop_reference = self.crop # if = 1, put 0 everywhere around warping field, if = 2, real crop
label=self.label
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space. Please apply PEP8 for all your modifs (there are other formatting issues below)

tmp_src=os.path.join(path_tmp, "dilated_data.nii")
tmp_out=os.path.join(path_tmp, "dilated_data_reg.nii")

sct.run(['isct_antsApplyTransforms',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicated code (see below)

@jcohenadad
Copy link
Member

@lrouhier after giving it some thoughts, how about adding a possible value label to the flag -x, instead of creating a new boolean flag -label? It would save some lines of code, and make it explicit that "label" is very much related to the interpolation (and cannot be used with any other interpolation method)

@lrouhier
Copy link
Contributor Author

Maybe it will be clearer! It does not change much in the code for me and i think it's easier for the user. Any thoughts on how to explain it in the help?

for now I wrote : Interpolation method. the 'label' interpolation method is designed to improve results on keypoints label file (e.g., disc label files) by dilating the original label and retrieving key points after the transformation. (line 102-103)

@jcohenadad
Copy link
Member

i would go with:

Interpolation method. the 'label' method is to be used if you would like to apply a transformation on a file that has single-voxel labels (classical interpolation methods won't work, as resampled labels might disappear or their values be altered). The function will dilate each label, apply the transformation using nearest neighbour interpolation, and then take the center-of-mass of each "blob" and output a single voxel per blob.

@jcohenadad jcohenadad added feature category: new functionality sct_apply_transfo context: labels Nov 26, 2019
@jcohenadad jcohenadad changed the title Added an option for keypoints transformation in sct_apply_transfo Added an option for keypoints transformation Nov 26, 2019
@jcohenadad jcohenadad added this to the 4.1.1 milestone Nov 26, 2019
Copy link
Member

@jcohenadad jcohenadad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great contribution! 👍

@jcohenadad
Copy link
Member

Let's merge #2522 before this one

@jcohenadad jcohenadad merged commit f89d6cb into master Nov 28, 2019
@jcohenadad jcohenadad deleted the lrouhier/2519-xlabel-option branch November 28, 2019 14:29
jcohenadad pushed a commit that referenced this pull request Dec 18, 2019
* First implementation of a -label option that specify certain operation to perform because the input file contains point like label. It seems fonctionnal but is still a work in progress. The transformed file overwrite the first created one. the option is here activated by default but an accepted argument

* forget to change a parameter. which causes it to not label every points. removing extra lines as well

* refactoring with precisting sct function. everything look smooth. open question about where to save the actual straight file before using cubic to points.

* force the nearest neighbors interpolation when using the -label flag.

* added creation of tmp folder to stor dilated and straighten dilated image (before applying cubic to point)

* Added the removal of temporary files (if not stated otherwise)

* removing lines. PEP-8 normalization

* remove extra lines

* refactor parser. the -label flag does not need any argument and activate the dilatation and nearest neighbors interpolation.

* PEP-8 formatting

* remove duplicated code

* put -label flag as an interpolation option.

* changing help discription for -x flag

* removing extra lines

* rmoving extra line and defining label in the case that the flag is not used.

* sct_apply_transfo: Updated usage

* sct_apply_transfo: Minor refactoring

- Added verbose
- Added ImplementationError for dim=4 case


Former-commit-id: f89d6cb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature category: new functionality sct_apply_transfo context:
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Creation of extra points when using sct_straighten_spinalcord on disc label files
2 participants