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.14k stars 493 forks source link

Can the binary image be the mask file? #368

Closed lisherlock closed 6 years ago

lisherlock commented 6 years ago

Hi! Recently I use the open-source project called pyradiomics, but now I have a very big problem about the mask image. I really hope you can help me solve it!

The problem is the mask file named maskname in the program. Now I get one mask file which is made by myself. It’s a Binary Image including the ROI. I tried to use it as the mask-file in the program named Helloradiomics, but there’s one log error saying ’Label (1) not present in mask’.

I have been solving it for 2 weeks but it still can’t work! I really hope you can help me! Thanks!

lisherlock commented 6 years ago

mask.zip That's the Binary Image mask file that can't work in pyradiomics.

JoostJM commented 6 years ago

@lisherlock, the error is due to the fact in how you defined your ROI. In the file you sent over, there are only values 0 (I assume background) and 255 (I assume your ROI). As 255 is of course not 1, PyRadiomics is unable to find a ROI defined by label '1'. To extract for label 255, you need to specify it to PyRadiomics. You can do this in the parameter file (under setting, parameter label), on the command line (specify additional argument -s label:255)) or in the interactive python by passing it to the execute() function (e.g. extractor.execute(image, mask, label=255)

JoostJM commented 6 years ago

By the way, does your image have the same size and orientation? if not, you might want to set parameter correctMask to True, this will resample the mask to the image geometry. If you do the, first check that the mask nicely overlaps the image in a visualisation program (e.g. 3D Slicer)

lisherlock commented 6 years ago

Thanks for your letter!

I'm sorry that the file(mask.zip) I uploaded is not the binary image. I just downloaded it then I found it's a grey level pic. Sorry for that!

I found my images have the same size and orientation after checking my image and mask again. It worked after I change the label to 255 by using the mask file I uploaded above!

So do you mean that I can't use the Binary Image as the mask file even I change the label to 1? Or I have to convert the binary images to the gray level (0-255) images every time? (Even the gray lever images have three channels?)

Looking forward to your reply! Thanks again!

JoostJM commented 6 years ago

@lisherlock, the pixels in your mask file can have any value you want, as long as all the voxels defining the ROI have the same value and you specified that value in the label parameter. In this way, your mask file is able to hold multiple (non-overlapping) ROIs and you can extract features from each ROI separately by specifying the different label values for each extraction run (you can even create a column Label in the input CSV when your extracting in batch mode, it will then be used to set the label value).

lisherlock commented 6 years ago

Thanks a lot!

I know that the binary image maybe can't be the mask-file because there's no software that can convert binary image (.bmp) to the dcm files or the nrrd files. So the best solution maybe is to try to convert the bmp files to grey level dcm files which has no RGB channels. Thanks again!

By the way, can you recommend me some softwares that could convert many bmp files to dcm or nrrd files? Now i use sante Dicom editor to do this work, but the dcm files always have 3 channals(RGB) rather than the cure grey level dcm images. :(

Looking forward to your reply! Thanks again!

fedorov commented 6 years ago

By the way, can you recommend me some softwares that could convert many bmp files to dcm or nrrd files?

You can use 3D Slicer (http://slicer.org) to load a stack of BMP files as a volume, and you can then save that volume as a NRRD file.

Diana228 commented 6 years ago

Hello, I would like to know if can I use pyradiomics library without mask or label file.

JoostJM commented 6 years ago

@Diana228, No, PyRadiomics requires you to supply a mask file. However, if you want to extract features based upon the whole image, you can create a full mask (in python):

import numpy as np
import SimpleITK as sitk

# Load the image
im = sitk.ReadImage('path/to/image.nrrd')

# GetSize() return x, y, z size, array should be z, y, x. use [::-1] to reverse direction
ma_arr = np.ones(im.GetSize()[::-1], dtype='int')

# Get the SimpleITK image object from the array
ma = sitk.GetImageFromArray(ma_arr)

# Copy geometric information from the image (origin, spacing, direction)
ma.CopyInformation(im)

# Store the full mask
sitk.WriteImage(ma, 'path/to/mask.nrrd', True)  # True specifies it can use compression

That said, what is your use case that you need to extract from the whole image?

YH2010 commented 5 years ago

Hi! I want to filter the image by wavelet transform and then extract all the image features of the offspring. My images are gray images of ROI, 2D,BMP formats, size32*32. I use MIPAV software to convert them into nrrd format one by one and make mask files, but Pyradiomics can't work. I tried to find solutions through the Internet, but there are too little information. I really wish I can get your help. Thank you very much!Merry Christmas!

lisherlock commented 5 years ago

@Diana228, No, PyRadiomics requires you to supply a mask file. However, if you want to extract features based upon the whole image, you can create a full mask (in python):

import numpy as np
import SimpleITK as sitk

# Load the image
im = sitk.ReadImage('path/to/image.nrrd')

# GetSize() return x, y, z size, array should be z, y, x. use [::-1] to reverse direction
ma_arr = np.ones(im.GetSize()[::-1], dtype='int')

# Get the SimpleITK image object from the array
ma = sitk.GetImageFromArray(ma_arr)

# Copy geometric information from the image (origin, spacing, direction)
ma.CopyInformation(im)

# Store the full mask
sitk.WriteImage(ma, 'path/to/mask.nrrd', True)  # True specifies it can use compression

That said, what is your use case that you need to extract from the whole image?

Hi! Thanks a lot! I have some other solutions to apply the Pyradiomics by dcm files!

lisherlock commented 5 years ago

Hi! I want to filter the image by wavelet transform and then extract all the image features of the offspring. My images are gray images of ROI, 2D,BMP formats, size32*32. I use MIPAV software to convert them into nrrd format one by one and make mask files, but Pyradiomics can't work. I tried to find solutions through the Internet, but there are too little information. I really wish I can get your help. Thank you very much!Merry Christmas!

Hi! Merry Christmas! Sorry maybe it's late to reply your questions!

As i said before, i wanna get radiomics information by using pyradimics. But i just only have dcm files and bmp files which are gotton by u-net. And i try to convert dcm files to nrrd files but it failed. Fortunately, i find the reason that pyradiomics can't work is that non-corrected between the data files and mask files. So my advice is that you can convert your data&label from other formats to dcm. Then you can try to correct the coordinate system between your data files and mask files. And early next year, i will upload the tools about it on my github. By using it, maybe your data will be calculated by pyradiomics successfully. I hope it could help you!

Best wishes!