Commit c82ab95f authored by Marc Modat's avatar Marc Modat

f3d had an issue with scl_slope and _inter. Fixed.

parent 91b2c8aa
...@@ -58,6 +58,7 @@ typedef struct ...@@ -58,6 +58,7 @@ typedef struct
bool normFlag; bool normFlag;
int operationTypeFlag; int operationTypeFlag;
bool iso; bool iso;
bool nosclFlag;
} FLAG; } FLAG;
...@@ -87,6 +88,7 @@ void Usage(char *exec) ...@@ -87,6 +88,7 @@ void Usage(char *exec)
printf("\t-thr <float>\t\tThreshold the input image (val<thr?val=0:val=1)\n"); printf("\t-thr <float>\t\tThreshold the input image (val<thr?val=0:val=1)\n");
printf("\t-nan <filename>\t\tThis image is used to mask the input image.\n\t\t\t\tVoxels outside of the mask are set to nan\n"); printf("\t-nan <filename>\t\tThis image is used to mask the input image.\n\t\t\t\tVoxels outside of the mask are set to nan\n");
printf("\t-iso\t\t\tThe resulting image is made isotropic\n"); printf("\t-iso\t\t\tThe resulting image is made isotropic\n");
printf("\t-noscl\t\t\tThe scl_slope and scl_inter are set to 1 and 0 respectively\n");
#ifdef _SVN_REV #ifdef _SVN_REV
printf("\t-v Print the subversion revision number\n"); printf("\t-v Print the subversion revision number\n");
#endif #endif
...@@ -237,6 +239,10 @@ int main(int argc, char **argv) ...@@ -237,6 +239,10 @@ int main(int argc, char **argv)
{ {
flag->normFlag=1; flag->normFlag=1;
} }
else if(strcmp(argv[i], "-noscl") == 0)
{
flag->nosclFlag=1;
}
else else
{ {
fprintf(stderr,"Err:\tParameter %s unknown.\n",argv[i]); fprintf(stderr,"Err:\tParameter %s unknown.\n",argv[i]);
...@@ -520,6 +526,14 @@ int main(int argc, char **argv) ...@@ -520,6 +526,14 @@ int main(int argc, char **argv)
nifti_image_free(resultImage); nifti_image_free(resultImage);
} }
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\// //\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//
if(flag->nosclFlag)
{
reg_tools_removeSCLInfo(image);
if(flag->outputImageFlag)
reg_io_WriteImageFile(image,param->outputImageName);
else reg_io_WriteImageFile(image,"output.nii");
}
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//
// reg_tools_changeDatatype<float>(image); // reg_tools_changeDatatype<float>(image);
// nifti_image *temp=nifti_copy_nim_info(image); // nifti_image *temp=nifti_copy_nim_info(image);
......
...@@ -1159,7 +1159,7 @@ int main(int argc, char **argv) ...@@ -1159,7 +1159,7 @@ int main(int argc, char **argv)
// Compute the orthonormal matrix // Compute the orthonormal matrix
float qb,qc,qd,qx,qy,qz,dx,dy,dz,qfac; float qb,qc,qd,qx,qy,qz,dx,dy,dz,qfac;
nifti_mat44_to_quatern(affine,&qb,&qc,&qd,&qx,&qy,&qz,&dx,&dy,&dz,&qfac); nifti_mat44_to_quatern(affine,&qb,&qc,&qd,&qx,&qy,&qz,&dx,&dy,&dz,&qfac);
affine = nifti_quatern_to_mat44(qb,qc,qd,qx,qy,qz,dx,dy,dz,qfac); affine = nifti_quatern_to_mat44(qb,qc,qd,qx,qy,qz,1.f,1.f,1.f,qfac);
reg_tool_WriteAffineFile(&affine, param->outputTransName); reg_tool_WriteAffineFile(&affine, param->outputTransName);
} }
// Free allocated object // Free allocated object
......
...@@ -487,6 +487,8 @@ void reg_base<T>::AllocateWarped() ...@@ -487,6 +487,8 @@ void reg_base<T>::AllocateWarped()
(size_t)this->warped->ny * (size_t)this->warped->ny *
(size_t)this->warped->nz * (size_t)this->warped->nz *
(size_t)this->warped->nt; (size_t)this->warped->nt;
this->warped->scl_slope=1.f;
this->warped->scl_inter=0.f;
this->warped->datatype = this->currentFloating->datatype; this->warped->datatype = this->currentFloating->datatype;
this->warped->nbyper = this->currentFloating->nbyper; this->warped->nbyper = this->currentFloating->nbyper;
this->warped->data = (void *)calloc(this->warped->nvox, this->warped->nbyper); this->warped->data = (void *)calloc(this->warped->nvox, this->warped->nbyper);
......
...@@ -74,7 +74,7 @@ bool reg_isAnImageFileName(char *name) ...@@ -74,7 +74,7 @@ bool reg_isAnImageFileName(char *name)
/* *************************************************************** */ /* *************************************************************** */
/* *************************************************************** */ /* *************************************************************** */
template<class DTYPE> template<class DTYPE>
void reg_intensityRescale2(nifti_image *image, void reg_intensityRescale_core(nifti_image *image,
int timePoint, int timePoint,
float newMin, float newMin,
float newMax float newMax
...@@ -123,6 +123,11 @@ void reg_intensityRescale2(nifti_image *image, ...@@ -123,6 +123,11 @@ void reg_intensityRescale2(nifti_image *image,
break; break;
} }
std::cout << "Slope:" << image->scl_slope << std::endl;
std::cout << "Inter:" << image->scl_inter << std::endl;
std::cout << "Before Min:" << currentMin << std::endl;
std::cout << "Before Max:" << currentMax << std::endl;
// Extract the minimal and maximal values from the current volume // Extract the minimal and maximal values from the current volume
if(image->scl_slope==0) image->scl_slope=1.0f; if(image->scl_slope==0) image->scl_slope=1.0f;
for(unsigned int index=0; index<voxelNumber; index++) for(unsigned int index=0; index<voxelNumber; index++)
...@@ -135,6 +140,9 @@ void reg_intensityRescale2(nifti_image *image, ...@@ -135,6 +140,9 @@ void reg_intensityRescale2(nifti_image *image,
} }
} }
std::cout << "After Min:" << currentMin << std::endl;
std::cout << "After Max:" << currentMax << std::endl;
// Compute constant values to rescale image intensities // Compute constant values to rescale image intensities
double currentDiff = (double)(currentMax-currentMin); double currentDiff = (double)(currentMax-currentMin);
double newDiff = (double)(newMax-newMin); double newDiff = (double)(newMax-newMin);
...@@ -156,10 +164,12 @@ void reg_intensityRescale2(nifti_image *image, ...@@ -156,10 +164,12 @@ void reg_intensityRescale2(nifti_image *image,
// Normalise the value between 0 and 1 // Normalise the value between 0 and 1
value = (value-(double)currentMin)/currentDiff; value = (value-(double)currentMin)/currentDiff;
// Rescale the value using the specified range // Rescale the value using the specified range
value = (value * newDiff + newMin)/image->scl_slope - image->scl_inter; value = value * newDiff + newMin;
} }
*volumePtr++=(DTYPE)value; *volumePtr++=(DTYPE)value;
} }
image->scl_slope=1.f;
image->scl_inter=0.f;
} }
/* *************************************************************** */ /* *************************************************************** */
void reg_intensityRescale(nifti_image *image, void reg_intensityRescale(nifti_image *image,
...@@ -171,28 +181,28 @@ void reg_intensityRescale(nifti_image *image, ...@@ -171,28 +181,28 @@ void reg_intensityRescale(nifti_image *image,
switch(image->datatype) switch(image->datatype)
{ {
case NIFTI_TYPE_UINT8: case NIFTI_TYPE_UINT8:
reg_intensityRescale2<unsigned char>(image, timepoint, newMin, newMax); reg_intensityRescale_core<unsigned char>(image, timepoint, newMin, newMax);
break; break;
case NIFTI_TYPE_INT8: case NIFTI_TYPE_INT8:
reg_intensityRescale2<char>(image, timepoint, newMin, newMax); reg_intensityRescale_core<char>(image, timepoint, newMin, newMax);
break; break;
case NIFTI_TYPE_UINT16: case NIFTI_TYPE_UINT16:
reg_intensityRescale2<unsigned short>(image, timepoint, newMin, newMax); reg_intensityRescale_core<unsigned short>(image, timepoint, newMin, newMax);
break; break;
case NIFTI_TYPE_INT16: case NIFTI_TYPE_INT16:
reg_intensityRescale2<short>(image, timepoint, newMin, newMax); reg_intensityRescale_core<short>(image, timepoint, newMin, newMax);
break; break;
case NIFTI_TYPE_UINT32: case NIFTI_TYPE_UINT32:
reg_intensityRescale2<unsigned int>(image, timepoint, newMin, newMax); reg_intensityRescale_core<unsigned int>(image, timepoint, newMin, newMax);
break; break;
case NIFTI_TYPE_INT32: case NIFTI_TYPE_INT32:
reg_intensityRescale2<int>(image, timepoint, newMin, newMax); reg_intensityRescale_core<int>(image, timepoint, newMin, newMax);
break; break;
case NIFTI_TYPE_FLOAT32: case NIFTI_TYPE_FLOAT32:
reg_intensityRescale2<float>(image, timepoint, newMin, newMax); reg_intensityRescale_core<float>(image, timepoint, newMin, newMax);
break; break;
case NIFTI_TYPE_FLOAT64: case NIFTI_TYPE_FLOAT64:
reg_intensityRescale2<double>(image, timepoint, newMin, newMax); reg_intensityRescale_core<double>(image, timepoint, newMin, newMax);
break; break;
default: default:
fprintf(stderr,"[NiftyReg ERROR] reg_intensityRescale\tThe image data type is not supported\n"); fprintf(stderr,"[NiftyReg ERROR] reg_intensityRescale\tThe image data type is not supported\n");
...@@ -202,6 +212,56 @@ void reg_intensityRescale(nifti_image *image, ...@@ -202,6 +212,56 @@ void reg_intensityRescale(nifti_image *image,
/* *************************************************************** */ /* *************************************************************** */
/* *************************************************************** */ /* *************************************************************** */
template<class DTYPE> template<class DTYPE>
void reg_tools_removeSCLInfo_core(nifti_image *image)
{
if(image->scl_slope==1.f && image->scl_inter==0.f)
return;
DTYPE *imgPtr = static_cast<DTYPE *>(image->data);
for(size_t i=0;i<image->nvox; ++i){
*imgPtr=*imgPtr*(DTYPE)image->scl_slope+(DTYPE)image->scl_inter;
imgPtr++;
}
image->scl_slope=1.f;
image->scl_inter=0.f;
}
/* *************************************************************** */
void reg_tools_removeSCLInfo(nifti_image *image)
{
switch(image->datatype)
{
case NIFTI_TYPE_UINT8:
reg_tools_removeSCLInfo_core<unsigned char>(image);
break;
case NIFTI_TYPE_INT8:
reg_tools_removeSCLInfo_core<char>(image);
break;
case NIFTI_TYPE_UINT16:
reg_tools_removeSCLInfo_core<unsigned short>(image);
break;
case NIFTI_TYPE_INT16:
reg_tools_removeSCLInfo_core<short>(image);
break;
case NIFTI_TYPE_UINT32:
reg_tools_removeSCLInfo_core<unsigned int>(image);
break;
case NIFTI_TYPE_INT32:
reg_tools_removeSCLInfo_core<int>(image);
break;
case NIFTI_TYPE_FLOAT32:
reg_tools_removeSCLInfo_core<float>(image);
break;
case NIFTI_TYPE_FLOAT64:
reg_tools_removeSCLInfo_core<double>(image);
break;
default:
fprintf(stderr,"[NiftyReg ERROR] reg_tools_removeSCLInfo\tThe image data type is not supported\n");
exit(1);
}
return;
}
/* *************************************************************** */
/* *************************************************************** */
template<class DTYPE>
void reg_getRealImageSpacing(nifti_image *image, void reg_getRealImageSpacing(nifti_image *image,
DTYPE *spacingValues) DTYPE *spacingValues)
{ {
...@@ -1849,6 +1909,7 @@ int reg_createImagePyramid(nifti_image *inputImage, nifti_image **pyramid, int u ...@@ -1849,6 +1909,7 @@ int reg_createImagePyramid(nifti_image *inputImage, nifti_image **pyramid, int u
memcpy(pyramid[levelToPerform-1]->data, inputImage->data, memcpy(pyramid[levelToPerform-1]->data, inputImage->data,
pyramid[levelToPerform-1]->nvox* pyramid[levelToPerform-1]->nbyper); pyramid[levelToPerform-1]->nvox* pyramid[levelToPerform-1]->nbyper);
reg_tools_changeDatatype<DTYPE>(pyramid[levelToPerform-1]); reg_tools_changeDatatype<DTYPE>(pyramid[levelToPerform-1]);
reg_tools_removeSCLInfo(pyramid[levelToPerform-1]);
// Images are downsampled if appropriate // Images are downsampled if appropriate
for(unsigned int l=levelToPerform; l<levelNumber; l++) for(unsigned int l=levelToPerform; l<levelNumber; l++)
......
...@@ -53,6 +53,16 @@ void reg_intensityRescale(nifti_image *image, ...@@ -53,6 +53,16 @@ void reg_intensityRescale(nifti_image *image,
float newMin, float newMin,
float newMax float newMax
); );
/* *************************************************************** */
/** @brief Set the scl_slope to 1 and the scl_inter to 0 and rescale
* the intensity values
* @param image Image to be updated
*/
extern "C++"
void reg_tools_removeSCLInfo(nifti_image *img);
/* *************************************************************** */ /* *************************************************************** */
/** @brief reg_getRealImageSpacing /** @brief reg_getRealImageSpacing
* @param image image * @param image image
......
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