AIM-Harvard / pyradiomics

Open-source python package for the extraction of Radiomics features from 2D and 3D images and binary masks. Support: https://discourse.slicer.org/c/community/radiomics
http://pyradiomics.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.16k stars 499 forks source link

3D features #358

Closed tommydino93 closed 6 years ago

tommydino93 commented 6 years ago

Hi everyone! I am about to start a feature extraction on a set of images obtained from cardiac MRI.

Since I will have to deal with 3D volumes (stacks of slices), I wanted to ask: "are there some of the pyradiomics features that are suitable for these task or should I just apply the 2D feature extraction for each slice and then combine them in some other way?

Thanks a lot in advance. Tommaso

JoostJM commented 6 years ago

Hello @tommydino93,

You can extract in 3D if you ensure that your voxels are isotropic (same dimension in-plane and out-of-plane). If this is not the case (the usual in MR), you can enable resampling). On the other hand you can also extract 2D. This does not produce a value per-slice, but just does not consider voxels on adjacent slices to be neighbours (only applies for texture, i.e. texture). 2D/3D therfore does not affect calculations in firstorder or shape statistics.

tommydino93 commented 6 years ago

Ok thank you very much! To keep things simple, I think I will firstly extract 2D features. Just some other few questions:

1) Can I run (and eventually HOW) pyradiomics programs in PyCharm? 2) Since I am new to GitHub, I also wanted to understand: "which version of the programs should I use?"...meaning..."from which of the many folders I extract the correct (most updated) code that I can later apply to my images?"

Sorry in advance if these are trivial questions but I can't really find a "help" or "guide" that explains how to use functions in GitHub (e.g: which are the inputs, which are the outputs, ecc)

Thank you again, Tommaso

JoostJM commented 6 years ago

@tommydino93, yes you can run pyradiomics from PyCharm. Easiest to start with this is to take a look at the examples folder.

As to your second question, what exactly do you mean? Which version of PyRadiomics? In that case, I'd advise to clone the repository and run from the master branch. See here for making/cloning a git repository. The git url for pyradiomics is https://github.com/Radiomics/pyradiomics.git. TLDR: install git on your computer and run git clone https://github.com/Radiomics/pyradiomics.git from a bash shell

tommydino93 commented 6 years ago

Thank you again! Before installing Git I wanted to give it a try with PyCharm. I followed the specific guide, created a specific repository. Everything seemed to work fine. I tried the "brain1" example but then I get this error:

**Error loading C extensions, switching to python calculation: Traceback (most recent call last): File "D:\Getting_Started_PyCharm\Pyradiomics\radiomics__init__.py", line 295, in from radiomics import _cmatrices as cMatrices ImportError: cannot import name '_cmatrices' Traceback (most recent call last): File "D:/Getting_Started_PyCharm/Pyradiomics/Trial_Pyradiomics.py", line 5, in from radiomics import firstorder, getTestCase, glcm, glrlm, glszm, imageoperations, shape File "D:\Getting_Started_PyCharm\Pyradiomics\radiomics__init.py", line 307, in getFeatureClasses() File "D:\Getting_Started_PyCharm\Pyradiomics\radiomics\init.py", line 121, in getFeatureClasses import__('radiomics.' + mod) File "D:\Getting_Started_PyCharm\Pyradiomics\radiomics\featureextractor.py", line 10, in import pykwalify.core ModuleNotFoundError: No module named 'pykwalify'

Process finished with exit code 1**

I have seen that this has also happened here. I followed that guide, I deleted the "radiomics" folder contained in the site-packages but I didn't understand quite well the second part. Where should I insert my new line of command?

Thank you very much in advance! Tommaso

JoostJM commented 6 years ago

@tommydino93, issue #340 is not exactly the same as your error. In that case, it could not find the correct installation of PyRadiomics and subsequently, it could not load a module which was part of PyRadiomics. Your problem however, is that you are missing a 3rd-party package required by PyRadiomics to run.

There are several dependencies for PyRadiomics to function, and are detailed in requirements.txt, which is located in the repository root. Run the following command in a terminal to have python install all the requirements you need to run pyradiomics:

python -m pip install -r <path/to/requirements.txt>

tommydino93 commented 6 years ago

@JoostJM Thank you, that did solve almost all the errors it gave me. Now I just get:

C:\Users\tommaso\PycharmProjects\Prova\venv\Scripts\python.exe D:/Getting_Started_PyCharm/Pyradiomics/Trial_Pyradiomics.py Error loading C extensions, switching to python calculation: Traceback (most recent call last): File "D:\Getting_Started_PyCharm\Pyradiomics\radiomics__init__.py", line 295, in from radiomics import _cmatrices as cMatrices ImportError: cannot import name '_cmatrices' [1 2] Process finished with exit code 0

considering that I just tried a simple:

a = np.array([1,2]) print(a)

to see if it worked. Should I be worried about "Error loading C extensions" ?

Thanks

JoostJM commented 6 years ago

@tommydino93, This means that the C-extensions are not yet compiled. To do so in-source (allowing you to run/debug using pycharm), run the following command: python setup.py develop This will compile the C code (available in ./radiomics/src) and store it in ./radiomics. That should fix your error.

tommydino93 commented 6 years ago

@JoostJM, I just tried following this PyCharm guide, I chose "develop" and a console opens saying:

**running develop running egg_info writing Solver.egg-info\PKG-INFO writing dependency_links to Solver.egg-info\dependency_links.txt writing top-level names to Solver.egg-info\top_level.txt reading manifest file 'Solver.egg-info\SOURCES.txt' writing manifest file 'Solver.egg-info\SOURCES.txt' running build_ext Creating c:\users\tommaso\pycharmprojects\prova\venv\lib\site-packages\Solver.egg-link (link to .) Adding Solver 0.0.0 to easy-install.pth file

Installed d:\getting_started_pycharm Processing dependencies for Solver==0.0.0 Finished processing dependencies for Solver==0.0.0

Process finished with exit code 0**

So it seemed ok. After this I re-tried running my "Trial_Pyradiomics" which is now just:

**from future import print_function import numpy as np import SimpleITK as sitk import six from radiomics import firstorder, getTestCase, glcm, glrlm, glszm, imageoperations, shape

imageName, maskName = getTestCase('brain1')**

and I keep on having the same error:

**Error loading C extensions, switching to python calculation: Traceback (most recent call last): File "D:\Getting_Started_PyCharm\Pyradiomics\radiomics__init__.py", line 295, in from radiomics import _cmatrices as cMatrices ImportError: cannot import name '_cmatrices'

Process finished with exit code 0**

I really don't understand what I'm doing wrong. Sorry if the question is trivial.

Thanks again!

JoostJM commented 6 years ago

@tommydino93, what is the content of the radiomics folder? is there a file called _cmatrices.pyd?

What is the output of the following:

import radiomics
print(radiomics.__file__)
JoostJM commented 6 years ago

on a side not, your last comment seemed to have installed something called 'solver', but not PyRadiomics. Do try to run the setup.py directly from the commandline (where you first cd into the root of the repository)

tommydino93 commented 6 years ago

@JoostJM, inside pyradiomics/radiomics there is a sub-folder named src and the cmatrices file is inside that sub-folder but it has a .c extension and not a .pyd one.

Anyway:

import radiomics print(radiomics.file)

gives me once again as output the error:

Error loading C extensions, switching to python calculation: Traceback (most recent call last): File "D:\Getting_Started_PyCharm\Pyradiomics\radiomics__init__.py", line 295, in from radiomics import _cmatrices as cMatrices ImportError: cannot import name '_cmatrices'

with the word radiomics in the code which is highlighted in red.

Moreover, I tried writing:

setup.py

in the PyCharm terminal but it tells me that the command is neither recognized as internal nor as external. Maybe I didn't understand precisely what you meant with "where you first cd into the root of the repository"?

JoostJM commented 6 years ago

@tommydino93 The contents of your folder mean that the extensions are not yet compiled and therefore not available when you try to start it (the file with the .c extension is a source code file, not the compiled, loadable file).

To compile these you first need to run the setup script, which I usually do outside of PyCharm altogether.

If you execute the following steps, it should work:

  1. start a command terminal (on windows: cmd.exe) in your repository. the easiest way to do this is to go to the repository in windows explorer and then click on the address bar. You should then be able to type an address, but instead, type "cmd" and press enter. This should start a terminal which has it's working directory set to the repository root.
  2. Run the setup script by entering the following line in the terminal and press enter: python setup.py develop
  3. Check your script again in PyCharm

ALTERNATE:

  1. start cmd.exe from your start menu
  2. Change your drive to D:/ by entering this command D: and press enter
  3. Change to the pyradiomics source directory by entering this command cd Getting_Started_PyChar\PyRadiomics and press enter
  4. Run the setup script for develop by entering this command python setup.py develop and press enter
  5. Check your script angain in PyCharm

The reason setup.py did not work in the pycharm terminal is because you did not specify that it should be run with python (i.e. python setup.py). Moreover, for this script to work, you also need to specify the command (i.e. install, test, develop)

JoostJM commented 6 years ago

see this stack overflow thread for more info on what setup.py is.

tommydino93 commented 6 years ago

Hi @JoostJM! I arrived to the Pyradiomics directory through the cmd prompt, but then if I run python setup.py develop I get the error:

"python is neither recognized as an internal command nor an external command, nor an exe program, nor a batch file.

I tried typing just setup.py develop and the prompt gives me this error:

File "D:\Getting_Started_PyCharm\Pyradiomics\setup.py", line 7, in import numpy ModuleNotFoundError: No module named 'numpy'

which I believe it's strange because I checked in PyCharm and I have installed the numpy package. What am I doing wrong?

Thank you again!!!

tommydino93 commented 6 years ago

Furthermore, is it mandatory to have Git installed on my PC in order to use GitHub Packages in PyCharm? I am asking you just because I also tried running setup.py in PyCharm but on the event log I get these two errors:

  1. Can't start Git: C:\Users\tommaso\Downloads\Git-2.16.2-64-bit.exe The path to Git executable is probably not valid. Fix it.
  2. Install packages failed: Installing packages: error occurred.
JoostJM commented 6 years ago

python is neither recognized as an internal command nor an external command, nor an exe program, nor a batch file.

This means python is not in your PATH variable. What kind of python interpreter did you install? Anaconda, Python 2.7, Python 3.x?

If you know how to update your PATH variable, add the folder containing python.exe and the scripts folder. In case of regularly installed python: C:\PythonX.X;C:\PythonX.X\Scripts. If not reinstall python and ensure you select "add python to PATH"

JoostJM commented 6 years ago

Furthermore, is it mandatory to have Git installed on my PC in order to use GitHub Packages in PyCharm?

For PyCharm I don't know, but PyRadiomics uses git to determine the version of PyRadiomics during installation, so for pyradiomics it is sort of required yes. It's good practice to have git installed anyway when you're working with GitHub repositories, because it allows you to have and work with local copies of the entire repository.

tommydino93 commented 6 years ago

Thank you very much! I added the python PATH, I downloaded Git and integrated into PyCharm, and now the simple code I wrote there works without any errors. I finally managed to upload the "brain1" images and masks!

Now the real programming begins! I will surely ask you something about the programs too!! Please stick around @JoostJM! :) :)

Thanks again

JoostJM commented 6 years ago

You're welcome! Be sure to check out the examples and notebooks in the repository, the frequently asked questions in the documentation and questions from the community both here in the issues and on the google groups. Between them, you should be able to many answers for questions you might run into during your programming and use of pyradiomics.

Happy coding!