Commit a92af38f authored by Marc Modat's avatar Marc Modat

Updated reg_aladin, reg_f3d, reg_resample and reg_jacobian xml description for...

Updated reg_aladin, reg_f3d, reg_resample and reg_jacobian xml description for CLI. UPdated reg_jacobian to enable multiple outputs
parent 87a89bc3
......@@ -172,7 +172,6 @@ void Usage(char *exec)
int main(int argc, char **argv)
{
if(argc==1)
{
PetitUsage(argv[0]);
......
......@@ -58,7 +58,7 @@ char xml_f3d[] =
" <name>inputControlPointPosition</name>\n"
" <longflag>incpp</longflag>\n"
" <description>Control point position image from NiftyReg</description>\n"
" <label>Input trans. from RefF3D</label>\n"
" <label>Input trans. from RegF3D</label>\n"
" <default></default>\n"
" <channel>input</channel>\n"
" </file>\n"
......@@ -200,6 +200,13 @@ char xml_f3d[] =
" <default>false</default>\n"
" </boolean>\n"
" <boolean>\n"
" <name>UseNMI</name>\n"
" <longflag>nmi</longflag>\n"
" <description>To use the NMI as a measure of similarity</description>\n"
" <label>Use NMI</label>\n"
" <default>true</default>\n"
" </boolean>\n"
" <boolean>\n"
" <name>UseSSD</name>\n"
" <longflag>ssd</longflag>\n"
" <description>To use the SSD as a measure of similarity instead of the NMI used by default</description>\n"
......
......@@ -26,7 +26,9 @@ typedef struct
{
char *refImageName;
char *inputTransName;
char *outputJacName;
char *outputJacDetName;
char *outputJacMatName;
char *outputLogDetName;
} PARAM;
typedef struct
{
......@@ -34,7 +36,7 @@ typedef struct
bool inputTransFlag;
bool outputJacDetFlag;
bool outputJacMatFlag;
bool outputLogJacDetFlag;
bool outputLogDetFlag;
} FLAG;
template <class DTYPE>
......@@ -110,7 +112,9 @@ void Usage(char *exec)
printf("\n* * INPUT * *\n");
printf("\t-trans <filename>\n");
printf("\t\tFilename of the file containing the transformation.\n");
printf("\t\tFilename of the file containing the transformation (mandatory).\n");
printf("\t-ref <filename>\n");
printf("\t\tFilename of the reference image (required if the transformation is a spline parametrisation)\n");
printf("\n* * OUTPUT * *\n");
printf("\t-jac <filename>\n");
printf("\t\tFilename of the Jacobian determinant map.\n");
......@@ -118,20 +122,20 @@ void Usage(char *exec)
printf("\t\tFilename of the Jacobian matrix map. (9 or 4 values are stored as a 5D nifti).\n");
printf("\t-jacL <filename>\n");
printf("\t\tFilename of the Log of the Jacobian determinant map.\n");
printf("\n* * EXTRA * *\n");
printf("\t-ref <filename>\tFilename of the reference image (required if the transformation is a spline parametrisation)\n");
printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
return;
}
int main(int argc, char **argv)
{
if(argc==1){
PetitUsage(argv[0]);
return 1;
}
PARAM *param = (PARAM *)calloc(1,sizeof(PARAM));
FLAG *flag = (FLAG *)calloc(1,sizeof(FLAG));
// Set a default output name
param->outputJacName=(char *)"outputJac.nii";
// read the input parameters
for(int i=1; i<argc; i++)
{
......@@ -174,20 +178,20 @@ int main(int argc, char **argv)
else if(strcmp(argv[i], "-jac") == 0 ||
(strcmp(argv[i],"--jac")==0))
{
param->outputJacName=argv[++i];
param->outputJacDetName=argv[++i];
flag->outputJacDetFlag=1;
}
else if(strcmp(argv[i], "-jacM") == 0 ||
(strcmp(argv[i],"--jacM")==0))
{
param->outputJacName=argv[++i];
param->outputJacMatName=argv[++i];
flag->outputJacMatFlag=1;
}
else if(strcmp(argv[i], "-jacL") == 0 ||
(strcmp(argv[i],"--jacL")==0))
{
param->outputJacName=argv[++i];
flag->outputLogJacDetFlag=1;
param->outputLogDetName=argv[++i];
flag->outputLogDetFlag=1;
}
else
{
......@@ -231,7 +235,7 @@ int main(int argc, char **argv)
// Create a deformation field if needed
nifti_image *referenceImage=NULL;
if(inputTransformation->intent_p1==SPLINE_GRID ||
inputTransformation->intent_p1==SPLINE_VEL_GRID){
inputTransformation->intent_p1==SPLINE_VEL_GRID){
if(!flag->refImageFlag){
reg_print_msg_error("A reference image has to be specified with a spline parametrisation.");
reg_exit(1);
......@@ -246,34 +250,28 @@ int main(int argc, char **argv)
reg_checkAndCorrectDimension(referenceImage);
}
// Create the Jacobian image
nifti_image *jacobianImage=NULL;
if(referenceImage!=NULL){
jacobianImage=nifti_copy_nim_info(referenceImage);
nifti_image_free(referenceImage);referenceImage=NULL;
}
else jacobianImage=nifti_copy_nim_info(inputTransformation);
if(flag->outputJacDetFlag || flag->outputLogJacDetFlag){
if(flag->outputJacDetFlag || flag->outputLogDetFlag){
// Compute the map of Jacobian determinant
// Create the Jacobian image
nifti_image *jacobianImage=NULL;
if(referenceImage!=NULL){
jacobianImage=nifti_copy_nim_info(referenceImage);
nifti_image_free(referenceImage);referenceImage=NULL;
}
else jacobianImage=nifti_copy_nim_info(inputTransformation);
jacobianImage->ndim=jacobianImage->dim[0]=jacobianImage->nz>1?3:2;
jacobianImage->nu=jacobianImage->dim[5]=1;
}
else{
jacobianImage->ndim=jacobianImage->dim[0]=5;
jacobianImage->nu=jacobianImage->dim[5]=jacobianImage->nz>1?9:4;
}
jacobianImage->nt=jacobianImage->dim[4]=1;
jacobianImage->nvox=(size_t)jacobianImage->nx *jacobianImage->ny*
jacobianImage->nz*jacobianImage->nt*jacobianImage->nu;
jacobianImage->datatype = inputTransformation->datatype;
jacobianImage->nbyper = inputTransformation->nbyper;
jacobianImage->cal_min=0;
jacobianImage->cal_max=0;
jacobianImage->scl_slope = 1.0f;
jacobianImage->scl_inter = 0.0f;
jacobianImage->data = (void *)calloc(jacobianImage->nvox, jacobianImage->nbyper);
jacobianImage->nt=jacobianImage->dim[4]=1;
jacobianImage->nvox=(size_t)jacobianImage->nx *jacobianImage->ny*
jacobianImage->nz*jacobianImage->nt*jacobianImage->nu;
jacobianImage->datatype = inputTransformation->datatype;
jacobianImage->nbyper = inputTransformation->nbyper;
jacobianImage->cal_min=0;
jacobianImage->cal_max=0;
jacobianImage->scl_slope = 1.0f;
jacobianImage->scl_inter = 0.0f;
jacobianImage->data = (void *)calloc(jacobianImage->nvox, jacobianImage->nbyper);
if(flag->outputJacDetFlag || flag->outputLogJacDetFlag){
// Compute the map of Jacobian determinant
switch((int)inputTransformation->intent_p1){
case DISP_FIELD:
reg_getDeformationFromDisplacement(inputTransformation);
......@@ -292,7 +290,9 @@ int main(int argc, char **argv)
reg_spline_GetJacobianDetFromVelocityGrid(jacobianImage,inputTransformation);
break;
}
if(flag->outputLogJacDetFlag){
if(flag->outputJacDetFlag)
reg_io_WriteImageFile(jacobianImage,param->outputJacDetName);
if(flag->outputLogDetFlag){
switch(jacobianImage->datatype){
case NIFTI_TYPE_FLOAT32:
reg_jacobian_computeLog<float>(jacobianImage);
......@@ -301,9 +301,31 @@ int main(int argc, char **argv)
reg_jacobian_computeLog<double>(jacobianImage);
break;
}
reg_io_WriteImageFile(jacobianImage,param->outputLogDetName);
}
nifti_image_free(jacobianImage);jacobianImage=NULL;
}
else{
if(flag->outputJacMatFlag){
nifti_image *jacobianImage=NULL;
if(referenceImage!=NULL){
jacobianImage=nifti_copy_nim_info(referenceImage);
nifti_image_free(referenceImage);referenceImage=NULL;
}
else jacobianImage=nifti_copy_nim_info(inputTransformation);
jacobianImage->ndim=jacobianImage->dim[0]=5;
jacobianImage->nu=jacobianImage->dim[5]=jacobianImage->nz>1?9:4;
jacobianImage->nt=jacobianImage->dim[4]=1;
jacobianImage->nvox=(size_t)jacobianImage->nx *jacobianImage->ny*
jacobianImage->nz*jacobianImage->nt*jacobianImage->nu;
jacobianImage->datatype = inputTransformation->datatype;
jacobianImage->nbyper = inputTransformation->nbyper;
jacobianImage->cal_min=0;
jacobianImage->cal_max=0;
jacobianImage->scl_slope = 1.0f;
jacobianImage->scl_inter = 0.0f;
jacobianImage->data = (void *)calloc(jacobianImage->nvox, jacobianImage->nbyper);
mat33 *jacobianMatriceArray=(mat33 *)malloc(jacobianImage->nx*jacobianImage->ny*jacobianImage->nz*sizeof(mat33));
// Compute the map of Jacobian matrices
switch((int)inputTransformation->intent_p1){
......@@ -333,13 +355,11 @@ int main(int argc, char **argv)
break;
}
free(jacobianMatriceArray);jacobianMatriceArray=NULL;
reg_io_WriteImageFile(jacobianImage,param->outputJacMatName);
nifti_image_free(jacobianImage);jacobianImage=NULL;
}
// Save the Jacobian image
reg_io_WriteImageFile(jacobianImage,param->outputJacName);
// Free the allocated image
nifti_image_free(jacobianImage);jacobianImage=NULL;
nifti_image_free(inputTransformation);inputTransformation=NULL;
return EXIT_SUCCESS;
......
......@@ -25,36 +25,24 @@ char xml_jacobian[] =
" <parameters advanced=\"false\">\n"
" <label>Input reference image</label>\n"
" <description>Input images</description>\n"
" <file fileExtensions=\"*.nii,*.nii.gz,*.nrrd,*.txt,.mat\">\n"
" <name>InTrans</name>\n"
" <longflag>trans</longflag>\n"
" <description>Input transformation</description>\n"
" <label>Input Trans.</label>\n"
" <default>required</default>\n"
" <channel>input</channel>\n"
" </file>\n"
" <image fileExtensions=\"*.nii,*.nii.gz,*.nrrd,*.png\">"
" <name>referenceImageName</name>\n"
" <longflag>ref</longflag>\n"
" <description>Reference image filename (also called Target or Fixed)</description>\n"
" <description>Reference image filename, required if the transformation is a spline parametrisation</description>\n"
" <label>Reference image</label>\n"
" <default>required</default>\n"
" <channel>input</channel>\n"
" </image>\n"
" </parameters>"
" <parameters advanced=\"false\">\n"
" <label>Input non-rigid transformation</label>\n"
" <description>Input transformation generated by a NiftyReg module or executable</description>\n"
" <file fileExtensions=\"*.nii,*.nii.gz,*.nrrd\">\n"
" <name>CPP_image</name>\n"
" <longflag>cpp</longflag>\n"
" <description>Control point position grid image</description>\n"
" <label>CPP image</label>\n"
" <default></default>\n"
" <channel>input</channel>\n"
" </file>\n"
" <file fileExtensions=\"*.nii,*.nii.gz,*.nrrd\">\n"
" <name>DEF_image</name>\n"
" <longflag>def</longflag>\n"
" <description>Deformation field image</description>\n"
" <label>DEF image</label>\n"
" <default></default>\n"
" <channel>input</channel>\n"
" </file>\n"
" </parameters>\n"
" <parameters advanced=\"false\">\n"
" <label>Output image</label>\n"
" <description>Jacobian determinants or matrices images</description>\n"
" <image fileExtensions=\"*.nii,*.nii.gz,*.nrrd,*.png\">"
......@@ -82,17 +70,5 @@ char xml_jacobian[] =
" <channel>output</channel>\n"
" </image>"
" </parameters>\n"
" <parameters advanced=\"true\">\n"
" <label>Jacobian matrices modulation using the affine transformation</label>\n"
" <description>If provided, the affine transformation is used to modulate the Jacobian matrices</description>\n"
" <file fileExtensions=\"*.txt,*.mat\">\n"
" <name>affMatrix</name>\n"
" <longflag>aff</longflag>\n"
" <description>Input affine matrix</description>\n"
" <label>Affine matrix file</label>\n"
" <default></default>\n"
" <channel>input</channel>\n"
" </file>\n"
" </parameters>\n"
"</executable>"
;
......@@ -45,27 +45,11 @@ char xml_resample[] =
" <parameters advanced=\"false\">\n"
" <label>Input transformation. Identity transformation is used by default.</label>\n"
" <description>Input transformation generated by a NiftyReg module or executable</description>\n"
" <file fileExtensions=\"*.txt,*.mat\">\n"
" <name>affineTransformation</name>\n"
" <longflag>aff</longflag>\n"
" <description>Input affine transformation</description>\n"
" <label>Affine trans.</label>\n"
" <default></default>\n"
" <channel>input</channel>\n"
" </file>\n"
" <file fileExtensions=\"*.nii,*.nii.gz,*.nrrd\">\n"
" <name>CPP_image</name>\n"
" <longflag>cpp</longflag>\n"
" <description>Control point position grid image</description>\n"
" <label>CPP image</label>\n"
" <default></default>\n"
" <channel>input</channel>\n"
" </file>\n"
" <file fileExtensions=\"*.nii,*.nii.gz,*.nrrd\">\n"
" <name>DEF_image</name>\n"
" <longflag>def</longflag>\n"
" <description>Deformation field image</description>\n"
" <label>DEF image</label>\n"
" <file fileExtensions=\"*.txt,*.mat,*.nii,*.nii.gz,*.nrrd\">\n"
" <name>inputTransformation</name>\n"
" <longflag>trans</longflag>\n"
" <description>Input transformation</description>\n"
" <label>Input trans.</label>\n"
" <default></default>\n"
" <channel>input</channel>\n"
" </file>\n"
......@@ -103,6 +87,13 @@ char xml_resample[] =
" <element>1</element>\n"
" <element>3</element>\n"
" </integer-enumeration>\n"
" <float>\n"
" <name>paddingValue</name>\n"
" <longflag>pad</longflag>\n"
" <description>Padding value</description>\n"
" <label>Padding value</label>\n"
" <default>0</default>\n"
" </float>\n"
" </parameters>\n"
"</executable>"
;
......@@ -457,25 +457,25 @@ void reg_f3d_sym<T>::Initialise()
reg_f3d<T>::Initialise();
if(this->inputControlPointGrid==NULL){
// Define the spacing for the first level
float gridSpacing[3] = {this->spacing[0],this->spacing[1],this->spacing[2]};
if(this->spacing[0]<0)
gridSpacing[0] *= -(this->inputReference->dx+this->inputFloating->dx)/2.f;
if(this->spacing[1]<0)
gridSpacing[1] *= -(this->inputReference->dy+this->inputFloating->dy)/2.f;
if(this->spacing[2]<0)
gridSpacing[2] *= -(this->inputReference->dz+this->inputFloating->dz)/2.f;
gridSpacing[0] *= powf(2.0f, (float)(this->levelNumber-1));
gridSpacing[1] *= powf(2.0f, (float)(this->levelNumber-1));
gridSpacing[2] *= powf(2.0f, (float)(this->levelNumber-1));
// Create the forward and backward control point grids
reg_createSymmetricControlPointGrids<T>(&this->controlPointGrid,
&this->backwardControlPointGrid,
this->referencePyramid[0],
this->floatingPyramid[0],
this->affineTransformation,
gridSpacing);
// Define the spacing for the first level
float gridSpacing[3] = {this->spacing[0],this->spacing[1],this->spacing[2]};
if(this->spacing[0]<0)
gridSpacing[0] *= -(this->inputReference->dx+this->inputFloating->dx)/2.f;
if(this->spacing[1]<0)
gridSpacing[1] *= -(this->inputReference->dy+this->inputFloating->dy)/2.f;
if(this->spacing[2]<0)
gridSpacing[2] *= -(this->inputReference->dz+this->inputFloating->dz)/2.f;
gridSpacing[0] *= powf(2.0f, (float)(this->levelNumber-1));
gridSpacing[1] *= powf(2.0f, (float)(this->levelNumber-1));
gridSpacing[2] *= powf(2.0f, (float)(this->levelNumber-1));
// Create the forward and backward control point grids
reg_createSymmetricControlPointGrids<T>(&this->controlPointGrid,
&this->backwardControlPointGrid,
this->referencePyramid[0],
this->floatingPyramid[0],
this->affineTransformation,
gridSpacing);
}
else{
// The control point grid image is initialised with the provided grid
......@@ -493,10 +493,13 @@ void reg_f3d_sym<T>::Initialise()
this->spacing[2] = this->controlPointGrid->dz / powf(2.0f, (float)(this->levelToPerform-1));
// The backward grid is derived from the forward
this->backwardControlPointGrid=nifti_copy_nim_info(this->controlPointGrid);
this->backwardControlPointGrid->data = (void *)malloc( this->backwardControlPointGrid->nvox *
this->backwardControlPointGrid->data = (void *)malloc(this->backwardControlPointGrid->nvox *
this->backwardControlPointGrid->nbyper);
if(this->controlPointGrid->num_ext>0)
nifti_copy_extensions(this->backwardControlPointGrid,this->controlPointGrid);
memcpy(this->backwardControlPointGrid->data,
this->controlPointGrid->data,
this->backwardControlPointGrid->nvox*this->backwardControlPointGrid->nbyper);
reg_getDisplacementFromDeformation(this->backwardControlPointGrid);
reg_tools_multiplyValueToImage(this->backwardControlPointGrid,this->backwardControlPointGrid,-1.f);
reg_getDeformationFromDisplacement(this->backwardControlPointGrid);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment