Commit c4fc3249 authored by Marc Modat's avatar Marc Modat

An error with the resampling of a blank grid in reg_resample has been fixed.

reg_measure can now directly output a text file rather than using stdin if needed.
parent a1f8a2f4
......@@ -31,6 +31,7 @@ typedef struct
char *floMaskImageName;
int interpolation;
float paddingValue;
char *outFileName;
} PARAM;
typedef struct
{
......@@ -42,6 +43,7 @@ typedef struct
bool returnSSDFlag;
bool returnLNCCFlag;
bool returnNCCFlag;
bool outFileFlag;
} FLAG;
......@@ -65,8 +67,9 @@ void Usage(char *exec)
printf("\t-lncc\t\tReturns the LNCC value\n");
printf("\t-nmi\t\tReturns the NMI value (64 bins are used)\n");
printf("\t-ssd\t\tReturns the SSD value\n");
printf("\n\t-out\t\tText file output where to store the value(s).\n\t\t\tThe stdout is used by default\n");
#ifdef _GIT_HASH
printf("\n\t--version\t\tPrint current source code git hash key and exit\n\t\t\t\t(%s)\n",_GIT_HASH);
printf("\n\t--version\tPrint current source code git hash key and exit\n\t\t\t(%s)\n",_GIT_HASH);
#endif
printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
return;
......@@ -161,6 +164,12 @@ int main(int argc, char **argv)
{
flag->returnSSDFlag=true;
}
else if(strcmp(argv[i], "-out") == 0 ||
(strcmp(argv[i],"--out")==0))
{
flag->outFileFlag=true;
param->outFileName=argv[++i];
}
else
{
fprintf(stderr,"Err:\tParameter %s unknown.\n",argv[i]);
......@@ -257,6 +266,10 @@ int main(int argc, char **argv)
param->paddingValue);
nifti_image_free(defField);
FILE *outFile=NULL;
if(flag->outFileFlag)
outFile=fopen(param->outFileName, "w");
/* Compute the NCC if required */
if(flag->returnNCCFlag){
float *refPtr = static_cast<float *>(refImage->data);
......@@ -290,24 +303,10 @@ int main(int argc, char **argv)
warSTDValue /= (double)refMaskVoxNumber;
measure /= sqrt(refSTDValue)*sqrt(warSTDValue)*
(double)refMaskVoxNumber;
printf("NCC: %g\n", measure);
}
/* Compute the NMI if required */
if(flag->returnNMIFlag){
reg_nmi *nmi_object=new reg_nmi();
for(int i=0;i<(refImage->nt<warpedFloImage->nt?refImage->nt:warpedFloImage->nt);++i)
nmi_object->SetActiveTimepoint(i);
nmi_object->InitialiseMeasure(refImage,
warpedFloImage,
refMask,
warpedFloImage,
NULL,
NULL);
double measure=nmi_object->GetSimilarityMeasureValue();
printf("NMI: %g\n", measure);
delete nmi_object;
if(outFile!=NULL)
fprintf(outFile, "NCC: %g\n", measure);
else printf("%g\n", measure);
}
/* Compute the LNCC if required */
if(flag->returnLNCCFlag){
reg_lncc *lncc_object=new reg_lncc();
......@@ -320,9 +319,28 @@ int main(int argc, char **argv)
NULL,
NULL);
double measure=lncc_object->GetSimilarityMeasureValue();
printf("LNCC: %g\n", measure);
if(outFile!=NULL)
fprintf(outFile, "LNCC: %g\n", measure);
else printf("%g\n", measure);
delete lncc_object;
}
/* Compute the NMI if required */
if(flag->returnNMIFlag){
reg_nmi *nmi_object=new reg_nmi();
for(int i=0;i<(refImage->nt<warpedFloImage->nt?refImage->nt:warpedFloImage->nt);++i)
nmi_object->SetActiveTimepoint(i);
nmi_object->InitialiseMeasure(refImage,
warpedFloImage,
refMask,
warpedFloImage,
NULL,
NULL);
double measure=nmi_object->GetSimilarityMeasureValue();
if(outFile!=NULL)
fprintf(outFile, "NMI: %g\n", measure);
else printf("%g\n", measure);
delete nmi_object;
}
/* Compute the SSD if required */
if(flag->returnSSDFlag){
reg_ssd *ssd_object=new reg_ssd();
......@@ -335,9 +353,16 @@ int main(int argc, char **argv)
NULL,
NULL);
double measure=ssd_object->GetSimilarityMeasureValue();
printf("SSD: %g\n", measure);
if(outFile!=NULL)
fprintf(outFile, "SSD: %g\n", measure);
else printf("%g\n", measure);
delete ssd_object;
}
// Close the output file if required
if(outFile!=NULL)
fclose(outFile);
// Free the allocated images
nifti_image_free(refImage);
nifti_image_free(floImage);
......
......@@ -523,7 +523,7 @@ int main(int argc, char **argv)
}
}
nifti_image *warpedImage = nifti_copy_nim_info(warpedImage);
nifti_image *warpedImage = nifti_copy_nim_info(referenceImage);
warpedImage->cal_min=0;
warpedImage->cal_max=255;
warpedImage->scl_slope=1.f;
......
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