Skip to content

Commit

Permalink
Merge pull request #1363 from sarthakpati/1235
Browse files Browse the repository at this point in the history
Perfusion Alignment fixes
  • Loading branch information
sarthakpati authored Nov 6, 2020
2 parents e4debd3 + 9b6b68a commit 5883f99
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 175 deletions.
91 changes: 42 additions & 49 deletions src/applications/PerfusionAlignment.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,64 @@

int main(int argc, char **argv)
{
std::cout << "This functionality has been removed from this CaPTk release, \
and we are actively testing an optimized robust implementation that would enable \
generalization in multi-institutional data. We expect this to be released in our \
next patch release, expected in Q4 2020.\n";
return EXIT_FAILURE;
int tempPosition;
int pointsbeforedrop, pointsafterdrop;
bool dropscaling = 0;
double timeresolution;
float baseline = 300, stdDev = 10;
size_t time_beforeDrop, time_afterDrop;
float time_inputPerfTime, time_outputPerfTime = 1.0, scale_maxIntensityBeforeDrop = 300, scale_intensityDropInMeanCurve = 100;
cbica::CmdParser parser = cbica::CmdParser(argc, argv, "PerfusionAlignment");
parser.addRequiredParameter("i", "input", cbica::Parameter::STRING, "File with read access", "The input DSC-MRI image.");
parser.addRequiredParameter("b", "timePointsBeforeDrop", cbica::Parameter::STRING, "0-100", "The number of time-points before the drop.");
parser.addRequiredParameter("a", "timePointsAfterDrop", cbica::Parameter::STRING, "0-100", "The number of time-points after the drop.");
parser.addRequiredParameter("t", "timeDomainResolution", cbica::Parameter::FLOAT, "0.01-100", "The time-interval (spacing) between two consecutive volumes in time-domain (in seconds).");
parser.addRequiredParameter("i", "input", cbica::Parameter::FILE, "File with read access", "The input DSC-MRI image.");
parser.addOptionalParameter("m", "mask", cbica::Parameter::STRING, "File with read access", "The brain mask corresponding to the input", "If not defined, it performs Otsu thresholding on input");
parser.addRequiredParameter("t1", "tInputPerfRep", cbica::Parameter::FLOAT, "0-100", "The input perfusion repetition time");
parser.addOptionalParameter("t2", "tOutputPerfRep", cbica::Parameter::FLOAT, "0-100", "The output perfusion repetition time", "Defaults to: " + std::to_string(time_outputPerfTime));
parser.addRequiredParameter("t3", "tBeforeDrop", cbica::Parameter::INTEGER, "0-100", "Number of timepoints BEFORE drop (starting index '1')");
parser.addRequiredParameter("t4", "tAfterDrop", cbica::Parameter::INTEGER, "0-100", "Number of timepoints AFTER drop (starting index '1')");

parser.addOptionalParameter("s1", "sMaxBeforeDrop", cbica::Parameter::FLOAT, "0-100", "The maximum intensity before drop in mean curve inside ROI", "Defaults to: " + std::to_string(scale_maxIntensityBeforeDrop));
parser.addOptionalParameter("s2", "sDropInMeanCurve", cbica::Parameter::FLOAT, "0-100", "The intensity drop in mean curve inside ROI", "Defaults to: " + std::to_string(scale_intensityDropInMeanCurve));

parser.addRequiredParameter("o", "output", cbica::Parameter::STRING, "Directory with write access", "The output directory.");
parser.addOptionalParameter("d", "dropScaling", cbica::Parameter::BOOLEAN, "0-1", "Whether to scale the value of the drop for the curve? 1=yes, 0=no; defaults to '0'");
parser.addOptionalParameter("s", "stdDev", cbica::Parameter::FLOAT, "0-100", "The standard deviation threshold of time series signal above which the", "location is considered to part of brain");
parser.addOptionalParameter("bl", "baseLine", cbica::Parameter::FLOAT, "0-1000", "The value of the baseline to which the output gets scaled", "Only used if '-d' is '1'", "Defaults to " + std::to_string(baseline));
parser.addOptionalParameter("L", "Logger", cbica::Parameter::STRING, "log file which user has write access to", "Full path to log file to store console outputs", "By default, only console output is generated", "Defaults to " + std::to_string(stdDev));
//parser.exampleUsage("PerfusionAlignment -i AAAC_PreOp_perf_pp.nii.gz -d AAAC_PreOp_perf_pp.dcm -o <output dir>");
parser.addExampleUsage("-i AAAC_PreOp_perf_pp.nii.gz -c AAAC_PreOp_t1ce_pp.nii.gz -b 15 -a 17 -t 2 -o <output dir>", "Aligns the perfusion signal of the input image based on the time points");

parser.addOptionalParameter("L", "Logger", cbica::Parameter::STRING, "log file which user has write access to", "Full path to log file to store console outputs", "By default, only console output is generated");
parser.addExampleUsage("-i AAAC_PreOp_perf_pp.nii.gz -m brainMask.nii.gz -t1 2 -t3 15 -t4 30 -o C:/testPerf", "Aligns the perfusion signal of the input image based on the time points");
parser.addApplicationDescription("Perfusion Alignment of the input based based on specified time points");

// parameters to get from the command line
cbica::Logging logger;
std::string loggerFile;
bool loggerRequested = false;
std::string inputFileName, inputDicomName, outputDirectoryName, inputt1ceName;
std::string inputFileName, inputMaskFileName, inputDicomName, outputDirectoryName;

if (parser.compareParameter("L", tempPosition))
{
loggerFile = argv[tempPosition + 1];
loggerRequested = true;
logger.UseNewFile(loggerFile);
}
if (parser.compareParameter("i", tempPosition))
parser.getParameterValue("i", inputFileName);
parser.getParameterValue("t1", time_inputPerfTime);
parser.getParameterValue("t3", time_beforeDrop);
parser.getParameterValue("t4", time_afterDrop);
parser.getParameterValue("o", outputDirectoryName);

if (parser.isPresent("m"))
{
inputFileName = argv[tempPosition + 1];
parser.getParameterValue("m", inputMaskFileName);
}
if (parser.compareParameter("o", tempPosition))

if (parser.isPresent("t2"))
{
outputDirectoryName = argv[tempPosition + 1];
parser.getParameterValue("t2", time_outputPerfTime);
if (time_outputPerfTime < 0)
{
std::cerr << "The output time resolution cannot be less than 0, using default, instead.\n";
time_outputPerfTime = 1;
}
}

if (parser.compareParameter("b", tempPosition))
pointsbeforedrop = atoi(argv[tempPosition + 1]);

if (parser.compareParameter("t", tempPosition))
timeresolution = atof(argv[tempPosition + 1]);

if (parser.compareParameter("a", tempPosition))
pointsafterdrop = atoi(argv[tempPosition + 1]);

if (parser.isPresent("d"))
if (parser.isPresent("s1"))
{
parser.getParameterValue("d", dropscaling);
parser.getParameterValue("s1", scale_maxIntensityBeforeDrop);
}
if (parser.isPresent("s"))
if (parser.isPresent("s2"))
{
parser.getParameterValue("s", stdDev);
parser.getParameterValue("s2", scale_intensityDropInMeanCurve);
}
if (parser.isPresent("bl"))
if (parser.isPresent("L"))
{
parser.getParameterValue("bl", baseline);
parser.getParameterValue("L", loggerFile);
loggerRequested = true;
logger.UseNewFile(loggerFile);
}

if (!cbica::isFile(inputFileName))
Expand All @@ -82,14 +74,15 @@ next patch release, expected in Q4 2020.\n";
PerfusionAlignment objPerfusion;
std::vector<double> OriginalCurve, InterpolatedCurve, RevisedCurve, TruncatedCurve;
//std::vector<typename ImageTypeFloat3D::Pointer> =
auto output = objPerfusion.Run<ImageTypeFloat3D, ImageTypeFloat4D>(inputFileName, pointsbeforedrop, pointsafterdrop, OriginalCurve, InterpolatedCurve, RevisedCurve, TruncatedCurve, timeresolution, dropscaling, stdDev, baseline);
auto output = objPerfusion.Run<ImageTypeFloat3D, ImageTypeFloat4D>(inputFileName, inputMaskFileName, time_beforeDrop, time_afterDrop, OriginalCurve, InterpolatedCurve, RevisedCurve, TruncatedCurve,
time_inputPerfTime, time_outputPerfTime, scale_maxIntensityBeforeDrop, scale_intensityDropInMeanCurve); // , dropscaling, stdDev, baseline);

auto PerfusionAlignment = output.first;
auto calculatedMask = output.second;

if (!PerfusionAlignment.empty())
{
auto joinedImage = cbica::GetJoinedImage< ImageTypeFloat3D, ImageTypeFloat4D >(PerfusionAlignment);
auto joinedImage = cbica::GetJoinedImage< ImageTypeFloat3D, ImageTypeFloat4D >(PerfusionAlignment, time_outputPerfTime);
cbica::WriteImage< ImageTypeFloat4D >(joinedImage, outputDirectoryName + "/perfusionAlignedImage.nii.gz");

cbica::WriteImage< ImageTypeFloat3D >(calculatedMask, outputDirectoryName + "/calculatedMask.nii.gz");
Expand Down
Loading

0 comments on commit 5883f99

Please sign in to comment.