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
179 stars 64 forks source link

FeatureExtraction issue #264

Closed schakrab closed 5 years ago

schakrab commented 5 years ago

Hi Sarthak,

So in the nibabel documentation I see the following: "Nibabel images always use RAS+ output coordinates, regardless of the preferred output coordinates of the underlying format. For example, we convert affines for DICOM images to output RAS+ coordinates instead of LPS+ coordinates. We chose this convention because it is the most popular in neuroimaging; for example, it is the standard used by NIfTI and MINC formats."

Could this be part of the problem in using nibabel?

Best, Shuvam

sarthakpati commented 5 years ago

Hi Shuvam,

I am not sure if this is an issue since the FE module in CaPTk does not care about the orientation (as long as the input image and mask are defined in the same space). Are you able to visualize them together in CaPTk?

Cheers, Sarthak

schakrab commented 5 years ago

Hi Sarthak,

I managed to get everything to work and extract the features. Thanks for all the help!

Best, Shuvam

schakrab commented 5 years ago

Hi Sarthak,

So upon running I get the output as a csv file with 334 features for each image. Since I want the lattice feature extraction for input to a CNN, I changed my command to include the lattice param file as well as the additional '-f 1' flag to save the feature maps. However, running this I still see it is writing to that same .csv file with no feature maps being saved. Do you know what I am missing

sarthakpati commented 5 years ago

By default, the feature maps should get saved to the same location as the output CSV. Could you create a new folder and point a new CSV file there? Also, try running with -d 1 to give some additional information in the console.

schakrab commented 5 years ago

Hi Sarthak, Do the feature maps get saved before or after the entire csv is written? If it is after, then it is possible it may have worked as I cut the code off midway seeing as it was not being saved. Would creating a new folder change anything? I am using the "-f 1" flag and the params file 2_params_default_lattice.csv (is there any difference in using the other file? I see the other file has more parameters). Is there anything else needed to ensure that the script runs in Lattice mode?

sarthakpati commented 5 years ago

To answer your question in order:

schakrab commented 5 years ago

Ok I see. I will just let it run in full this time. Do you know what format the feature maps are saved in (is it based on the file name of the input image, for instance?)? Thanks!

sarthakpati commented 5 years ago

The format is:

${imageModality}_${roiLabel}_${featureFamily}_${feature}.nii.gz

schakrab commented 5 years ago

Hi Sarthak,

So I ran with just one image with -f 1 and -d 1 and the debugger printed that it was calculating all the features (and writing them to the csv) but it made no reference to feature maps and no files were saved for that. Just for reference, this is my full command

FeatureExtraction.exe -p C:\CaPTk_Full\1.6.0\data\features\2_params_default_lattice.csv -i {image location} -m {mask location} -o {output directory} -n {sample number} -t T1 -r 1 -l 1 -d 1 -f 1

Something I was thinking was that I was using 1 for both the ROI value and label parameter (since my masks have value 1 or 0). Also for -t I was using T1, although I only know about these image types in reference to brain MRIs, I do not know what they would be for breast images. Is this appropriate? Thanks!

sarthakpati commented 5 years ago

Hey, I think this is a bug on our part. I have fixed it on my fork. We are planning to do an internal Alpha release on Monday, which will have these fixes. Let me know if you want to give it a test and I will add you to the announcement?

schakrab commented 5 years ago

Yes definitely as I need the lattice computation.

Best, Shuvam

schakrab commented 5 years ago

Hi Sarthak,

I ran the Beta version with the same command and results were the same. Has the package been updated with regards to the lattice computation and is my command appropriate for running lattice computation?

Best Regards, Shuvam

sarthakpati commented 5 years ago

Can you post the console output? A separate file will be fine.

schakrab commented 5 years ago

[DEBUG] Performing dos2unix using CBICA TK function; doesn't do anything in Windows machines. Using param file: C:\CaPTk_Full\1.6.0\data\features\2_params_default_lattice.csv Single subject computation selected. [DEBUG] Patient ID: 3 [DEBUG] Images: C:\Research\Data\20040524_080855ROUTINEs1480a000.nii.gz [DEBUG] Modalities: T1 [DEBUG] Mask File: C:\Research\Data\20040524_080855ROUTINEs1480a000_roi.nii.gz [DEBUG] ROI Values: 1 [DEBUG] ROI Labels: 1 [DEBUG] Initializing FE class. [DEBUG] Checking if selected ROIs are present in mask or not. 2019:03:05,22:10:19;FeatureExtraction;suntech-shu;Checking mask validity (whether it is empty or not) 2019:03:05,22:10:19;FeatureExtraction;suntech-shu;Started Construction of ROIs 2019:03:05,22:10:19;FeatureExtraction;suntech-shu;Starting feature extraction for every image and every ROI 2019:03:05,22:10:19;FeatureExtraction;suntech-shu;Calculating Features for modality 'T1' and ROI '1' 2019:03:05,22:10:19;FeatureExtraction;suntech-shu;Intensity Features for modality 'T1' and ROI '1' calculated in 251 milliseconds 2019:03:05,22:10:20;FeatureExtraction;suntech-shu;Histogram Features for modality 'T1' and ROI '1' calculated in 335 milliseconds 2019:03:05,22:10:21;FeatureExtraction;suntech-shu;Volumetric Features for modality 'T1' and ROI '1' calculated in 1441 milliseconds 2019:03:05,22:10:30;FeatureExtraction;suntech-shu;GLCM Features for modality 'T1' and ROI '1' calculated in 8769 milliseconds 2019:03:05,22:10:47;FeatureExtraction;suntech-shu;GLRLM Features for modality 'T1' and ROI '1' calculated in 17001 milliseconds 2019:03:05,22:10:55;FeatureExtraction;suntech-shu;GLRLM Features for modality 'T1' and ROI '1' calculated in 8227 milliseconds FE took 36422 milliseconds Finished.

sarthakpati commented 5 years ago

It seems like lattice was not detected at all. Can you check whether the lattice parameters being provided in the parameter file are valid? The step and lattice window sizes default to 6.3mm.

schakrab commented 5 years ago

Hi Sarthak,

So previously I was using the 2_params..._lattice.csv file for the parameters, which has the 6.3 values you mentioned. I changed to using the other param file, which has values 10 for those parameters, and it started writing to files, which seems good, but then gave me the following error:

Error occurred while trying to write the image 'C:/Research/test_results/T1_resampled_3.000000-Linear.nii.gz': e:\libscaptk\itk-source\modules\io\imagebase\include\itkimagefilewriter.hxx:290:
itk::ERROR: ImageFileWriter(0000022F1C6D24B0): Largest possible region does not fully contain requested paste IO regionPaste IO region: ImageIORegion (000000BFD75AB800)
  Dimension: 3
  Index: 0 0 0
  Size: 638 765 0
Largest possible region: ImageRegion (000000BFD75AB980)
  Dimension: 3
  Index: [0, 0, 0]
  Size: [638, 765, 0]

Error occurred while trying to write the image 'C:/Research/test_results/mask_resampled_3.000000-Nearest.nii.gz': e:\libscaptk\itk-source\modules\io\imagebase\include\itkimagefilewriter.hxx:290:
itk::ERROR: ImageFileWriter(0000022F1C6D3670): Largest possible region does not fully contain requested paste IO regionPaste IO region: ImageIORegion (000000BFD75AB800)
  Dimension: 3
  Index: 0 0 0
  Size: 638 765 0
Largest possible region: ImageRegion (000000BFD75AB980)
  Dimension: 3
  Index: [0, 0, 0]
  Size: [638, 765, 0]

Visualizing the images, they seem to simply be copies of the original image and the mask.

sarthakpati commented 5 years ago

Can you send the mask and your edited parameter file? A link to some cloud storage sercice here will be fine.

schakrab commented 5 years ago

I did not edit the parameter file. Do you mean the original files that were provided with the installation?

I believe I can simply attach files into this chat, would that be ok?

sarthakpati commented 5 years ago

Shuvam, I think I am a bit confused. Which parameter file are you using to get these features? If you are using breast image(s) as input, you need to use 2_params_default.csv as the base template and edit it to suit your needs.

schakrab commented 5 years ago

Yes I used 2_params_default_lattice.csv but that did not produce the lattice maps. I did not change any of the parameters in the file.

sarthakpati commented 5 years ago

The parameter files are to be used as templates so that users can alter values to meet the specific needs of their own datasets. In this case, I am sure that the Lattice Window/Step size of 6.3mm is not what you want for your data and that needs to be changed.

schakrab commented 5 years ago

How can I find out what size I need?

sarthakpati commented 5 years ago

Unfortunately, that is not something I can help you with since I do not know the details about your data. @gastouna might be able to shed more light into it. The parameters in the file 2_params_default.csv are specifically designed for images coming from Penn, which have a specific resolution and hence a Lattice Window Width and Step size of 6.3mm make sense for it. For some other data, it might not make sense to use those numbers (the same goes for all other parameters).

schakrab commented 5 years ago

Would it help if I sent you an image?

sarthakpati commented 5 years ago

I believe @gastouna is a better person to check the exact parameterization of the feature extraction.

gastouna commented 5 years ago

Hello @schakrab.

The Penn data (always talking about full-field digital mammography images) usually come with an image resolution of 0.07 mm/pixel. At some point we have also dealt with 0.10 mm/pixel. So, the default parameter of the lattice size (6.3 mm) has been defined based on experiments with the aforementioned image resolutions and it is the only lattice size we can confidently recommmend on our end.

From my experience in collaborations with other sites, this lattice size should work fine for most vendors of full-field digital mammography images. If this is not the case with you images, you can always adjust the lattice size as you wish and identify the optimal parameterization for you data. Good luck!

schakrab commented 5 years ago

Hi Sarthak/Gastouna,

So would the lattice size be the reason that the lattice feature extraction is not even being detected?

sarthakpati commented 5 years ago

It would depend on the image but it is possible.

schakrab commented 5 years ago

Could there be any other reasons? My command seems fine, right?

sarthakpati commented 5 years ago

You command does seem fine (it is clear since it actually runs). The thing is that any radiomic feature extraction is extremely dependent on the underlying image and how the parameters of different classes are structured. Hence, the same set of parameters can and should never be used for other datasets.

The build that you are running (Beta.20190305) has an option to resample input images and masks. Might I suggest trying that to ensure your images fall into the same world space? But I will second what @gastouna said: https://github.com/CBICA/CaPTk/issues/264#issuecomment-470606147

sarthakpati commented 5 years ago

Closing issue since the discussion has veered towards non-implementation details. Discussion can continue in the same thread.

schakrab commented 5 years ago

Hi Sarthak,

By resampling do you mean it would get it into the same format as the Penn images, making those parameters valid? If so, where is the documentation for this function?

Best, Shuvam

sarthakpati commented 5 years ago

If you see the latest build, there will be a a feature family called "Generic", which will have the option to resample images.

schakrab commented 5 years ago

I see. I don't see this under C:\CaPTk_Full\1.6.2.Beta\bin, do you know where it is located?

sarthakpati commented 5 years ago

The parameter files are located in ${captk_install_directory}/data/features/ for Windows and Linux packages [documentation reference]. There are 3 example parameter files and the options I am talking about will be in the 1_params_default.csv file.

schakrab commented 5 years ago

Didn't you say before that the 1_params_default.csv file was inappropriate for breast images? I see that the 2_params file also has the Generic resampling parameter. Should I use this instead?

sarthakpati commented 5 years ago

Both are intended as templates only. In the first file, you change the image dimension from 3D to 2D and it will be fine. Or, you can take the Generic feature family from it and add it to the 2nd file.

schakrab commented 5 years ago

Hi Sarthak,

So I see that the second file has all the generic parameters besides ResamplingInterpolator_Mask. Do you mean I should add this feature in? Also what values do you suggest passing? Should I use the Penn image resolutions for Generic Resampling parameter, and what about the other two?

sarthakpati commented 5 years ago

I would suggest you add the mechanism you need your mask to be interpolated (the exact method will depend on the data).

I cannot give you guidance on any values for particular feature family parameters since that is entirely dependent on the dataset.

schakrab commented 5 years ago

I see. So if I try it with various parameters, you are saying the optimal ones should result in the feature maps being written?

sarthakpati commented 5 years ago

Yup. Try with a single case first. With some basic features (intensity only) and lattice enabled. See how that works and extend onwards.

schakrab commented 5 years ago

I see there is no default value for intensity. Do you have any good starting points?

sarthakpati commented 5 years ago

Intensity features do not need any parameters. You only need to play with the lattice parameters to get it working.

schakrab commented 5 years ago

Hi Sarthak, So I have tried some initial configurations of the parameters and have noticed some interesting things. When I try changing the resampling parameter (to .07 and .1 as Gastouna says these are the voxel resolutions that are the most standard) the feature extraction does not run at all. The Debug output prints

[DEBUG] Performing dos2unix using CBICA TK function; doesn't do anything in Windows machines. Using param file: C:\CaPTk_Full\1.6.2.Beta\data\features\2_params_default_lattice_test.csv Single subject computation selected. [DEBUG] Patient ID: 2 [DEBUG] Images: C:\BoobResearch\Data\20040524_080855ROUTINEs1480a000.nii.gz [DEBUG] Modalities: T1 [DEBUG] Mask File: C:\BoobResearch\Data\20040524_080855ROUTINEs1480a000_roi.nii.gz [DEBUG] ROI Values: 1 [DEBUG] ROI Labels: 1 [DEBUG] Initializing FE class. [DEBUG] Checking if selected ROIs are present in mask or not. 2019:03:30,16:44:04;FeatureExtraction;suntech-shu;Checking mask validity (whether it is empty or not)

and quits. When I set the resampling parameter to 0 (none) or 1(the default) then it runs as is before, with no lattice features being extracted. I also tried changing the lattice window and step parameters and this did not seem to affect anything either as it seems the lattice FE is not being detected at all. Do you have any inclination as to what is going on and why the resampling is not quite working?

sarthakpati commented 5 years ago

I am not sure why that is happening. Would you mind pasting the mask (not the image) you are using? I am assuming the image is in the same physical space (origin, spacing, size and direction cosines are the same) as the mask.

schakrab commented 5 years ago

Hi Sarthak,

20040524_080855ROUTINEs1480a000_roi.nii.gz

Here is a mask for one of the images.

sarthakpati commented 5 years ago

Hi Shuvam,

I think you had emailed me this subject earlier and I was able to find the main image for this as well. It seems like the mask and the image are not defined in the same physical space (the origins for both are different). This might be a reason why feature extraction is not working. Please ensure that the mask and image are in the same physical space (see quote below) before trying to extract features.

I am not sure why that is happening. Would you mind pasting the mask (not the image) you are using? I am assuming the image is in the same physical space (origin, spacing, size and direction cosines are the same) as the mask.

schakrab commented 5 years ago

Yes, I remember that was the case before but I believe I fixed it. Before, when I visualized the images they were not aligned and CaPTK would say they were not registered, but I do not get that issue anymore, with any of the images.

sarthakpati commented 5 years ago

Oh okay. Then could you email the image and mask for this particular case? I am not sure why it would cause an issue.

schakrab commented 5 years ago

20040524_080855ROUTINEs1480a000.nii.gz

Here is the image