【Radiomics】Use 3Dslicer or Python to extract radiomics features


1. Using 3Dslicer software to extract radiomics features

  1. Install plugin : SlicerRadiomics
  2. Import image files : breast1_label.nrrd (mask file) and breast1_image.nrrd (personal image file).
    insert image description here
  3. Toggle plugin : Welcome to Slicer → Informatics → Radiomics
    insert image description here
  4. Setting parameters (as shown in the figure) :
    Select Input Volume and Segmentation
    input image Volume : breast1_image (personal image file)
    input regionsROI: breast1_label (mask file)
    Extraction Customization : Manual Customization
    Featrue Classesselects which class features to extract, such as firstorder and gldm
    Resampling and Filteringresampling→ Resampled voxel size: 3 ,3,3 (The distance between voxels is 3mm, it is recommended that the voxel intervals in each direction be the same) → LoG kernel sizes: 3,4 (If you use the Gaussian Laplace filter, you need to set it, you can set it multiple sizes). Check Wavelet-based features(whether to extract the features of the wavelet filter)
    Other default
    output
    output table : Table1 (modify the output table name), after setting the table name Apply.
    insert image description here
  5. After Apply, a table is generated in the lower right corner of the window :
    Image type: The original image is still a picture generated by some kind of filter. The previous diagnostics is the basic information of the image. Starting from log-sigma-3-0-mm-3D, it is useful information for feature extraction. (log filter, sigma size 3.0).
    Feature class: feature classification
    insert image description here
  6. Export table : format selection csv.
    insert image description here
  7. When doing radiomics research, cases are usually used as rows and features as columns, so it is necessary to transpose the csv table for subsequent research: select all data → select transpose when pasting to a new table.
    insert image description here
    insert image description here

2. Using python to extract radiomics features

  • Basic version: To extract the characteristics of a case,
    you need to install pyradiomics first.
    Reference: [Radiomics] Problems with installing the pyradiomics package in windows system

    # pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyradiomics
    from radiomics import featureextractor 
    
    
    imageFile = 'file5/breast1/breast1_image.nrrd'
    maskFile = 'file5/breast1/breast1_label.nrrd'
    
    extractor = featureextractor.RadiomicsFeatureExtractor() # 初始化,给这一长串起个简写的名字
    featureVector = extractor.execute(imageFile, maskFile) # 
    # print(featureVector.items()) 结果太多太杂乱
    # for循环遍历提取所需的信息 featureName
    for featureName in featureVector.keys():
        print("%s: %s" % (featureName, featureName[featureName]))
    

    insert image description here

Common parameter setting

  • Select by features to be extracted

    extractor.disableAllFeatures()  # 禁用所有特征
    extractor.enableFeaturesByName(firstorder=['Mean', 'Skewness']) # 只选几个特征提取
    
    featureVector = extractor.execute(imageFile, maskFile)
    for featureName in featureVector.keys():
        print("%s: %s" % (featureName, featureVector[featureName]))
    

    insert image description here

  • Select according to the type of feature to be extracted

    extractor.disableAllFeatures()  # 禁用所有特征
    extractor.enableFeatureClassByName('glcm') # 输出想要类型的特征,如 glcm
    
    featureVector = extractor.execute(imageFile, maskFile)
    for featureName in featureVector.keys():
        print("%s: %s" % (featureName, featureVector[featureName]))
    
  • Filter settings : Extract features on the image with the filter (modified image).

    extractor.enableImageTypes(Original={
          
          }, LoG={
          
          }, Wavelet={
          
          }) 
    # Original原始图像 LoG滤波器 Wavelet小波滤波器
    
    featureVector = extractor.execute(imageFile, maskFile)
    for featureName in featureVector.keys():
        print("%s: %s" % (featureName, featureVector[featureName]))
    

    insert image description here

  • Batch processing to extract radiomics features

    import os
    import pandas as pd
    
    basePath = 'data/featureExtraction'
    folders = os.listdir(basePath) # 读取featureExtraction文件夹下所有文件名
    print(folders)
    
    df = pd.DataFrame() 
    for folder in folders:  # 遍历文件夹
        files = os.listdir(os.path.join(basePath,folder)) # 拼接文件夹下的文件路径
    #     print(files) 区分影像文件和 mask 文件
        for file in files:
            if file.endswith('image.nrrd'):  
                imageFile = os.path.join(basePath,folder,file) # 影像文件路径
            if file.endswith('label.nrrd'):
                maskFile = os.path.join(basePath,folder,file) # mask文件路径
    #     print(imageFile, maskFile) 特征提取
        extractor = featureextractor.RadiomicsFeatureExtractor()
        featureVector = extractor.execute(imageFile, maskFile)  # 得到结果是字典 dict
        # 从featureVector字典中提取数据转换成数据框,并 .T 转置(特征作为列)
        df_new = pd.DataFrame.from_dict(featureVector.values()).T  
        df_new.columns = featureVector.keys() # 列名
        df = pd.concat([df,df_new])  # 合并之前的数据框
    df.to_excel(os.path.join(basePath,'results.xlsx'))
    

    insert image description here

Guess you like

Origin blog.csdn.net/zea408497299/article/details/125295402