Package: ifree
ifreeifreeis a small python package for making you free.Radiomics Feature ExtractionFeature Pre-Processing and Selecting,Dicom ProcessingCrop CT/MR according to RT StructureCalculate dose volume histogram (DVH)One of the main benefits ofifreeis that it handles data easily (seeexample below).Installationifreecan be installed with pip:pipinstallifreeFor the bleeding edge version, install directly from github (consider adding--force-reinstall):pipinstallgit+git://github.com/linzhenyuyuchen/ifree.gitor by cloning the repo:gitclonehttps://github.com/linzhenyuyuchen/ifree.gitcdifree
pythonsetup.pyinstallExampleFeature ProcessingRadiomics Feature Extractorradiomics.yaml# https://github.com/Radiomics/pyradiomics/blob/master/examples/exampleSettings/exampleMR_NoResampling.yaml# https://github.com/Radiomics/pyradiomics/blob/master/examples/exampleSettings/MR_2D_extraction.yamlimageType:Original:{}LoG:# If the in-plane spacing is large (> 2mm), consider removing sigma value 1.sigma:[1.0,3.0,5.0]Wavelet:{}setting:label:1# 255#  interpolator: 'sitkBSpline'#  resampledPixelSpacing: [2, 2, 2]#  normalize: true#  normalizeScale: 100  # This allows you to use more or less the same bin width.featureClass:firstorder:shape:glcm:glrlm:glszm:gldm:ngtdm:fromifreeimportprocessingidx=list()imagePaths=list()maskPaths=list()paramPath="./radiomics.yaml"outputPath="./features.csv"helper=processing.FeatureExtractor(idx,imagePaths,maskPaths,paramPath,outputPath)helper.extract(force=True)Feature Pre-Processingdf_train=pd.DataFrame()df_test=pd.DataFrame()helper=processing.FeatureProcess(df_train,df_test)# preprocessing methodshelper.simpleImpute(strategy='mean')# mean, median, most_frequent, constanthelper.standardScale()helper.normalizer()helper.minMaxScaler()helper.pca(n_components=10)array_train=helper.X_trainarray_test=helper.X_testFeature Selectorx_array=np.array()y_list=list()featureNames=list()selector=processing.FeatureSelector(x_array,y_list,featureNames)# selection methodsx_array_new,y_array_new=selector.univarSelector(top_k=600,method_name="f_classif",inplace=True)print(x_array_new.shape)x_array_new,y_array_new=selector.ttestSelector(inplace=True)print(x_array_new.shape)x_array_new,y_array_new=selector.mannSelector(inplace=True)print(x_array_new.shape)x_array_new,y_array_new=selector.modelSelector(inplace=True)print(x_array_new.shape)# name of selected featuresprint(selector.featureNames)Dicom ProcessingCrop CT/MR according to RTfromifreeimportdicom# get paths for CT, MR, DOSE and RTfileDir="./p/"ctfiles,rtfile,mrfiles,dosefile,patientID,patientName=dicom.GetFilePath(fileDir)# get MRs or CTs related to RT and copy them to new dirpatientNames,patientIDs,id2mrs,id2rt,id2dose=dicom.archiveFiles(old_Dir,new_Dir,copyed=True)# crop ROI-MASK and its CT or MRroiName="ctv"newDir="./p/"newSize=[100,100,100]# leave None to get origin sizeidx_done_list=dicom.cropROI(id2mrs,id2rt,roiName,newDir,newSize)idx_done_list=dicom.cropDose(id2dose,id2rt,roiName,newDir,newSize)Get Dose-Volume Histogram (DVH)# Get Dose-Volume Histogram (DVH)rtssfile="./RT.dicom"rtdosefile="./RS.dicom"# percents is the space between 0-100roiname="Body"data,percents=dicom.get_dvh_of_key(rtssfile,rtdosefile)dose_list,max_value,min_value,mean_value=data[roiname]# saved to dataframedose_features={}roiname="Body"fori,(pid,rtssfile)inenumerate(id2rt.item()):rtdosefile=id2dose[pid]# percents is the space between 0-100data,percents=dicom.get_dvh_of_key(rtssfile,rtdosefile)dose_list,max_value,min_value,mean_value=data[roiname]tmp={"pid":pid,"dose_max":max_value,"dose_min":min_value,"dose_mean":mean_value,}fori,pcinenumerate(percents):tmp[f"dose_{pc}"]=dose_list[i]dose_features[i]=tmpdf_dose_features=pd.DataFrame.from_dict(dose_features,orient='index')df_dose_features.head()For more examples, see theexamples folder.