-
Notifications
You must be signed in to change notification settings - Fork 497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature extractions on 2D tiff images #339
Comments
The images are already gray scale. Do they need to be converted to nrrd files, and does the mask also need to be in 3d? |
Yes and yes. Image and Mask must both be 3D (but when converting from 2D, they will have a size of 1 in the 3rd dimension). You can do this using Related: what is the origin of your tiff images? If the origin is DICOM, it is better to directly convert DICOM to NRRD (as in tiff, spacing information etc. is often discarded). |
The images are original in tif. We made the mask from numpy.ones(), and
made it the same size as the image (since the whole image is of interest).
Then added a new axis to make it 3d and made a nrrd-file.
We also converted the tif image to 3d with "image3d =
sitk.JoinSeries(image2d)", but we are having problems to make it in to a
nrrd file so we can us it as input in the RadiomicsFirstOrder class.
2018-01-22 12:07 GMT+01:00 Joost van Griethuysen <notifications@github.com>:
… Yes and yes. Image and Mask must both be 3D (but when converting from 2D,
they will have a size of 1 in the 3rd dimension).
You can do this using SimpleITK.JoinSeries(), but check that the images
are really grayscale (i.e. not a vector for each pixel value, check this by
print(im), where im is a SimpleITK image object).
Related: what is the origin of your tiff images? If the origin is DICOM,
it is better to directly convert DICOM to NRRD (as in tiff, spacing
information etc. is often discarded).
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#339 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AV5s4FtOlCaX37e7WJULUztHCSzAO2AHks5tNGv5gaJpZM4Rmcep>
.
|
Try this:
|
If you want to store it as a nrrd, run this as well:
|
Looks like it's working now. Thanks a lot!
2018-01-22 14:51 GMT+01:00 Joost van Griethuysen <notifications@github.com>:
… Try this:
import SimpleITK as sitk
import numpy
from radiomics import featureextractor
# Transform input
im_tiff = sitk.ReadImage('path/to/image.tiff')
im_vect = sitk.JoinSeries(im_tiff) # Add 3rd dimension
im = sitk.VectorImageSelectionCast(im_vect, 0, sitk.sitkFloat64) # Select first color channel (if image is grayscale, all channels are equal)
# Build full mask
im_arr = sitk.GetArrayFromImage(im)
ma_arr = numpy.ones(im_arr.shape)
ma = sitk.GetImageFromArray(ma_arr)
ma.CopyInformation(im)
# Instantiate extractor
extractor = featureextractor.RadiomicsFeaturesExtractor('path/to/config') # optional supply parameter file)
# extractor = featureextractor.RadiomicsFeaturesExtractor() # Default settings
# Enable just first order
extractor.disableAllFeatures
extractor.enableFeatureClassByName('firstorder')
# Extract features
results = extractor.execute(im, ma)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#339 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AV5s4CjqSQn1t-fHYKI53dBCas_poa6Wks5tNJJIgaJpZM4Rmcep>
.
|
@JoostJM I have a similar question , whether the DCM image (2D) also needs to convert to 3D? |
@QiChen2014 Yes |
How to convert tif image (RGB) into grayscale image? |
@destinybuilt, PyRadiomics has since been upgraded and now also supports 2D input. Therefore, the addition of the 3rd dimension is no longer necessary. However, PyRadiomics does still require a scalar datatype. Your example constitutes one way of dealing with this (extracting features for channels separately). You can also put this in a loop to extract for all channels:
Alternatively, you can merge the channels prior to extraction (yielding a scalar volume). For this, you'd need to decide how to aggregate the information from the separate channels. E.g. take the mean, max, min... |
Thank you for your reply! import radiomics file namemain_path = r'D:\1Transition\1Trans\Test' File pathori_path = main_path + ori_name # image path Initialize the feature extractor using a configuration fileextractor = FEE.RadiomicsFeaturesExtractor(para_path) Extract featuresresult = extractor.execute(ori_path, lab_path) # Extract features |
You can apply the following code, it will extract features for each channel in the image, and use the first channel in mask to get the mask (I assume all 3 channels in the mask are identical). Finally, I'd advise using a parameter file. The documentation for this is here. You need a list of python tuples, which each tuple consisting of 3 values: p_name (identifier for your case), string pointing to the location of the image file and string pointing to the location of the mask file. e.g.:
You can then use this piece of code:
This will give you a python dictionary (results_dict), with 1 entry for each case.
|
@JoostJM Thank you very much, I will run your code a bit, but it will still report an error. The error is: param_file = r'D:\1Transition\1Trans\Test\Params.yaml' Instantiate extractorextractor = featureextractor.RadiomicsFeaturesExtractor(r'D:\1Transition\1Trans\Test\Params.yaml') # optional supply parameter file) get_patients=[('case_1',r'D:\1Transition\1Trans\Test\tissueSlide.tif',r'D:\1Transition\1Trans\Test\mask.tif'),('case_2',r'D:\1Transition\1Trans\Test\tissueSlide.tif',r'D:\1Transition\1Trans\Test\mask.tif')] results_dict = {} Extract features for each casefor p_name, im_path, ma_path in get_patients: Transform inputim_vect = sitk.ReadImage(im_path) Extract featuresresults = [] I can't upload more than 10MB files (even if I use zip files). Can you give me one of your emails? I can pass you a tif file and the corresponding mask so that you can debug it. |
Try this
|
@JoostJM It still reports an error.... TypeError: execute() got an unexpected keyword argument 'label_channel |
@JoostJM The following is the image and mask I shared with Google Cloud Drive: https://drive.google.com/file/d/1tEj9AwFzrh_j-rjQtXeb_7bf5HN8BP5U/view?usp=sharing |
Is it possible to use extract first order features on 2D tiff images using the built in class?
The text was updated successfully, but these errors were encountered: