CBICA / CaPTk

Cancer Imaging Phenomics Toolkit (CaPTk) is a software platform to perform image analysis and predictive modeling tasks. Documentation: https://cbica.github.io/CaPTk
https://www.cbica.upenn.edu/captk
Other
181 stars 64 forks source link

Perfusion alignment doesn't output image #1235

Closed chiharusako closed 4 years ago

chiharusako commented 4 years ago

Describe the bug PerfusionAlignment only outputs csv and not an image. Also, help documentation needs to be updated.

To Reproduce

$ dir="/cbica/home/sakoc/comp_space/lab/captk/180b/perfalign"
$ /cbica/software/lab/captk/centos7/1.8.0.Beta/bin/PerfusionAlignment \
       -i $dir/AAAA_2007.01.21_perf.nii.gz \
       -d $dir/AAAA_2007.01.21_anonymized_000.dcm \
       -o $dir/output \
       -b 15 -a 17 \
       -c $dir/AAAA_2007.01.21_t1ce.nii.gz \
       -e 0.045
base: 4.52968e-307 drop: 0 min: 1.52459e+07 max: 4.52968e-307
Finished successfully.

Press any key to continue............
$ ls $dir/output
original_curve.csv  revised_curve.csv

Expected behavior Output an aligned perfusion image

CaPTk Version 1.8.0.Beta on cbica-cluster

Desktop (please complete the following information):

Additional context Documentation example says

Examples of Usage:
 Command: PerfusionAlignment -i AAAC_PreOp_perf_pp.nii.gz -d AAAC_PreOp_perf_pp.dcm -o <output dir>
 Result : Aligns the perfusion signal of the input image based on the time points

However there is no -d option in the required parameters. Also, do we need the t1ce file and echo time? I gave it as parameters above as it won't run without it, but I am not sure if it is using it, especially if requiring the perfusion dicom as input.

sarthakpati commented 4 years ago

Hi @chiharusako, this issue shoud be fixed buy #1291. Could you please verify this? The artifacts are here: https://dev.azure.com/CBICA/CaPTk/_build/results?buildId=2321&view=artifacts&type=publishedArtifacts

I am compiling this on my home directory, as well and it should be available on ~patis/testing/captkMyFork_1.8.0.nonRelease.20200908.834dc79

chiharusako commented 4 years ago

@sarthakpati It still doesn't output an image. Also why do you need a t1ce input? Is it being used? If so, are there requirements for this, such as registered with perfusion etc?

dir=/cbica/home/sakoc/comp_space/lab/captk/180b/perfalign2

$ ~patis/testing/captkMyFork_1.8.0.nonRelease.20200908.834dc79/bin/PerfusionAlignment \
  -i $dir/ACST_2019.08.29_perf.nii.gz \
  -c $dir/ACST_2019.08.29_t1ce.nii.gz \
  -b 15 -a 17 -t 2 -o $dir/output > $dir/output/log

$ ls $dir/output
interpolated_curve.csv  original_curve.csv  revised_curve.csv  truncated_curve.csv
sarthakpati commented 4 years ago

I think the T1Gd DICOM is required [ref] and not NIfTI.

chiharusako commented 4 years ago

That documentation is old. It no longer requires the 2. DSC dicom slice either. This is what -h gives now. Is it using t1ce it in the calculation?


$ ~patis/testing/captkMyFork_1.8.0.nonRelease.20200908.834dc79/bin/PerfusionAlignment -h

Executable Name: PerfusionAlignment v1.8.0.nonRelease.20200908.834dc79

Description:

Perfusion Alignment of the input based based on specified time points

Usage:

:::Required parameters:::

[  -i, --input]                   The input DSC-MRI image.

                                  Expected Type  :: STRING

                                  Expected Range ::

[  -c, --t1ce file]               The input T1 post-weighted image.

                                  Expected Type  :: STRING

                                  Expected Range ::

[  -b, --timepoints before drop]  The number of time-points before the drop.

                                  Expected Type  :: STRING

                                  Expected Range ::

[  -a, --timepoints after drop]   The number of time-points after the drop.

                                  Expected Type  :: STRING

                                  Expected Range ::

[  -t, --timedomain resolution]   The time-interval between two consecutive volumes in time-domain (in seconds).

                                  Expected Type  :: FLOAT

                                  Expected Range ::

[  -o, --output]                  The output directory.

                                  Expected Type  :: STRING

                                  Expected Range ::
sarthakpati commented 4 years ago

You are right; I was mistaken. The documentation needs to be updated after the usage has been finalized (I have no idea whether T1Gd is required or not).

saimarathore commented 4 years ago

@chiharusako are you using the same input as you mentioned earlier? what time-resolution you are providing as input; this is different from echo time? time-resolution is generally 2sec for penn data having 45 time-points.

the code needs the following parameters as input:

  1. t1ce image
  2. perfusion image registered to t1ce
  3. time-points before drop
  4. time-points after drop
  5. output
  6. time-resolution

like this: -i AAAC_PreOp_perf_pp.nii.gz -c AAAC_PreOp_t1ce_pp.nii.gz -b 15 -a 17 -t 2 -o

chiharusako commented 4 years ago

@saimarathore Is the 6. time-resolution the time resolution (TR) for the input or output? Also why do you need a t1ce input?

saimarathore commented 4 years ago

time-resolution is for the input perfusion image. it is actually the spacing in the 4th dimension, which is generally 2sec for perfusion images having 45 time-points.

saimarathore commented 4 years ago

we need t1ce to write the aligned perfusion volumes in the t1ce space.

chiharusako commented 4 years ago

I talked to @saimarathore Here is my updated feedback and results, understanding the updated usage and required input.

Updated feedback:

  1. Instead of the t1ce input, the program should use the perfusion input to get image information for output. t1ce input requirement can be removed.
  2. As of now, it doesn't output a 4D aligned image. Instead, it outputs a series of 3D images. This should be combined to one 4D image as output.
  3. Also, the 3D image doesn't seem right when visualizing (screenshot below)
  4. The output 3D images are written to current folder, not specified output folder, which should be updated.
  5. Finally please update documentation on both website and CLI -h option so that the usage is clear. The part that wasn't clear was (a) you give input TR (b) output is always TR=1s and that is not a user input.

Updated Results: (the output nii.gz were written in current directory but I moved to the output folder)

$ dir=/cbica/home/sakoc/comp_space/lab/captk/180b/perfalign3
$ t=AAAA_2007.01.21
$ /cbica/home/patis/testing/captkMyFork_1.8.0.nonRelease.20200908.834dc79/bin/PerfusionAlignment \
     -i input/${t}_perf_LPS_rSRI_SSFinal.nii.gz \
     -c input/${t}_t1ce_LPS_rSRI_SSFinal.nii.gz \
     -b 15 -a 17 \
     -t 2 \
     -o out_$t > out_$t/log
$ mv out_*nii.gz out_$t
$ ls out_$t
interpolated_curve.csv        out_AAAA_2007.01.2120.nii.gz  out_AAAA_2007.01.2127.nii.gz  out_AAAA_2007.01.2134.nii.gz  out_AAAA_2007.01.2141.nii.gz  out_AAAA_2007.01.2148.nii.gz
log               out_AAAA_2007.01.2121.nii.gz  out_AAAA_2007.01.2128.nii.gz  out_AAAA_2007.01.2135.nii.gz  out_AAAA_2007.01.2142.nii.gz  revised_curve.csv
original_curve.csv        out_AAAA_2007.01.2122.nii.gz  out_AAAA_2007.01.2129.nii.gz  out_AAAA_2007.01.2136.nii.gz  out_AAAA_2007.01.2143.nii.gz  truncated_curve.csv
out_AAAA_2007.01.2116.nii.gz  out_AAAA_2007.01.2123.nii.gz  out_AAAA_2007.01.2130.nii.gz  out_AAAA_2007.01.2137.nii.gz  out_AAAA_2007.01.2144.nii.gz
out_AAAA_2007.01.2117.nii.gz  out_AAAA_2007.01.2124.nii.gz  out_AAAA_2007.01.2131.nii.gz  out_AAAA_2007.01.2138.nii.gz  out_AAAA_2007.01.2145.nii.gz
out_AAAA_2007.01.2118.nii.gz  out_AAAA_2007.01.2125.nii.gz  out_AAAA_2007.01.2132.nii.gz  out_AAAA_2007.01.2139.nii.gz  out_AAAA_2007.01.2146.nii.gz
out_AAAA_2007.01.2119.nii.gz  out_AAAA_2007.01.2126.nii.gz  out_AAAA_2007.01.2133.nii.gz  out_AAAA_2007.01.2140.nii.gz  out_AAAA_2007.01.2147.nii.gz

image of one of the outputs. The intensity is bright on the outside and very low inside brain image

sarthakpati commented 4 years ago

From our meeting today, there are 2 things that need to be addressed:

  1. Instead of using T1Gd, use first time point of Perfusion image for computation
  2. Instead of writing N 3D volumes, write a single 4D volume

Is that right @saimarathore?

chiharusako commented 4 years ago

@sarthakpati Yes, and the 3 items I wrote before your comment..

sarthakpati commented 4 years ago

Hey @chiharusako, I have made some changes. Could you please check on the cluster? It will be available in ~patis/testing/captkMyFork_1.8.0.nonRelease.20200916.596fd79

chiharusako commented 4 years ago

@sarthakpati It didn't finish. Did it work for you?

$ dir=/cbica/home/sakoc/comp_space/lab/captk/180b/perfalign4
$ /cbica/home/patis/testing/captkMyFork_1.8.0.nonRelease.20200916.596fd79/bin/PerfusionAlignment \
      -i input/AAAA_2007.01.21_perf_LPS.nii.gz \
      -b 15 -a 17 -t 2 \
      -o out_AAAA_2007.01.21 > out_AAAA_2007.01.21/log
$ tail out_AAAA_2007.01.21/log
82 : 275
83 : 275
84 : 276
85 : 276
86 : 275
87 : 275
88 : 275
89 : 0
Curve characteristics after base normalization::: base = 299; drop = 35; min = 194; max = 300
Segmentation fault
sarthakpati commented 4 years ago

Yeah, I tried with a few images and it worked fine. Can you email/message the path to the image?

chiharusako commented 4 years ago

/cbica/home/sakoc/comp_space/lab/captk/180b/perfalign4/input/AAAA_2007.01.21_perf_LPS.nii.gz or /cbica/home/sakoc/comp_space/lab/captk/180b/perfalign4/input/AAAA_2007.01.21_perf.nii.gz if you need the 4th dimension to be correct (2s)

sarthakpati commented 4 years ago

Got it. I can replicate the seg-fault. I will debug and let you know.

sarthakpati commented 4 years ago

So, this is happening because the total number of volumes in the perfusion image is 45, drop is detected at 35 but the pointsAfterDrop parameter (-a in CLI) is 17, which makes the vector go out of range. I have added a message to tackle this:

Drop has been estimated at '35' and total number of time-points are '45' but time-points after drop is given as '10', which is not possible.

Let me know if you want some other wording.

chiharusako commented 4 years ago

@sarthakpati The drop is not at 35 out of 45. Perhaps it's confusing the drop after resampling to 1 sec. For this example, the drop is around 17 out of 45 (curve below), 2sec interval. Once you resample to 1sec, it will have 90 timepoints and drop will be at around 35 but it should have enough timepoints after.

image

We can talk tomorrow if it helps.

sarthakpati commented 4 years ago

Ah, now I understand this much better. Yes, it was trying to perform the extraction on the original perfusion, hence the error. I am testing a fix right now.

Update: https://github.com/CBICA/CaPTk/commit/e89823b3fd9145ae25b6b7ab6091538bafdcf11b seems to have fixed it. I am compiling on the cluster right now (and ready at ~patis/testing/captkMyFork_1.8.0.nonRelease.20200917.e89823b).

sarthakpati commented 4 years ago

After conversing with Hamed, the function NormalizeBaselineValue needs to be re-written to ensure the baseline shift happens correctly.

sarthakpati commented 4 years ago

Done.