MyLifeOrganized:时间管理神器,告别拖延
MyLifeOrganized: 个人时间管理神器 #生活常识# #时间管理建议# #时间管理工具推荐#
import os import pandas as pd import SimpleITK as sitk from radiomics import featureextractor def define_extractor(): """定义优化的特征提取器,无需传入图像路径""" # 优化参数设置 - 乳腺钼靶专用 settings = { 'Interpolator': sitk.sitkBSpline, 'resampledPixelSpacing': [0.1, 0.1, 1], # 高分辨率 'voxelArrayShift': 100, # 避免低值组织信息丢失 'normalize': True, 'removeOutliers': 3, 'normalizeScale': 200, # 扩大归一化范围 'binWidth': 5, # 更细粒度分箱 'force2D': True, 'correctMask': True, 'textureWindow': 7, # 7x7纹理分析窗口 'tumorMargin': 3, # 肿瘤边缘扩展像素 'glandularWeighting': 0.7, # 腺体组织加权 'sigma': [1.0, 1.5, 2.0, 2.5, 3.0, 5.0], # 多尺度滤波器 'enableLoG': True, # 默认启用LoG } extractor = featureextractor.RadiomicsFeatureExtractor(**settings) # 启用图像类型 extractor.enableAllImageTypes() #启用特征提取类型 extractor.enableAllFeatures() all_feature_classes = ['firstorder', 'shape','glcm', 'glrlm', 'glszm','gldm', 'ngtdm'] for feature_class in all_feature_classes: extractor.enableFeatureClassByName(feature_class) return extractor def extract_features_single(image_path, label_path, extractor): """提取单个图像对的特征""" image = sitk.ReadImage(image_path) label = sitk.ReadImage(label_path) feature_vector = extractor.execute(image, label, label=1) return feature_vector def process_patient_folder(patient_dir, extractor, output_dir): """处理单个患者的文件夹""" patient_id = os.path.basename(patient_dir) results = [] image_cc = None image_mlo = None label_cc = None label_mlo = None # 更健壮的文件识别 for file in os.listdir(patient_dir): file_lower = file.lower() file_path = os.path.join(patient_dir, file) if not os.path.isfile(file_path): continue # 识别图像类型 if 'cc' in file_lower and 'seg' not in file_lower: image_cc = file_path elif 'mlo' in file_lower and 'seg' not in file_lower: image_mlo = file_path elif 'cc' in file_lower and ('seg' in file_lower or 'mask' in file_lower): label_cc = file_path elif 'mlo' in file_lower and ('seg' in file_lower or 'mask' in file_lower): label_mlo = file_path elif 'label' in file_lower and 'cc' in file_lower: label_cc = file_path elif 'label' in file_lower and 'mlo' in file_lower: label_mlo = file_path # 处理CC视图 if image_cc and label_cc and os.path.exists(image_cc) and os.path.exists(label_cc): print(f"处理 {patient_id} CC视图...") features_cc = extract_features_single(image_cc, label_cc, extractor) if features_cc: features_cc['Patient_ID'] = patient_id features_cc['View'] = 'CC' results.append(features_cc) else: print(f" {patient_id} CC视图特征提取失败") # 处理MLO视图 if image_mlo and label_mlo and os.path.exists(image_mlo) and os.path.exists(label_mlo): print(f"处理 {patient_id} MLO视图...") features_mlo = extract_features_single(image_mlo, label_mlo, extractor) if features_mlo: features_mlo['Patient_ID'] = patient_id features_mlo['View'] = 'MLO' results.append(features_mlo) else: print(f" {patient_id} MLO视图特征提取失败") return results def batch_extract_features(root_dir, output_dir): """批量处理所有患者""" # 初始化特征提取器 extractor = define_extractor() all_features = [] # 确保输出目录存在 os.makedirs(output_dir, exist_ok=True) # 遍历所有患者文件夹 patient_folders = [d for d in os.listdir(root_dir) if os.path.isdir(os.path.join(root_dir, d))] total_patients = len(patient_folders) processed_count = 0 for i, folder in enumerate(patient_folders): patient_dir = os.path.join(root_dir, folder) print(f"\n处理患者 {i + 1}/{total_patients}: {folder}") try: features = process_patient_folder(patient_dir, extractor, output_dir) if features: all_features.extend(features) processed_count += 1 print(f"√ 成功处理患者: {folder}") else: print(f"× 患者 {folder} 缺少有效数据") except Exception as e: print(f"! 处理患者 {folder} 时出错: {str(e)}") # 保存所有结果 if all_features: df = pd.DataFrame(all_features) # 清理特征名称 df.columns = [col.replace('original_', '') for col in df.columns] # 添加特征数量信息 feature_count = len(df.columns) - 2 # 减去Patient_ID和View列 output_path = os.path.join(output_dir, "shi0.csv") df.to_csv(output_path, index=False) print(f"\n处理完成! 共处理 {processed_count}/{total_patients} 名患者") print(f"提取 {len(df)} 个样本,{feature_count} 个特征") print(f"结果已保存至: {output_path}") return df print("\n处理完成! 但未提取到任何特征") return None if __name__ == '__main__': # 配置路径 ROOT_DIR = r"F:\breast_7.220" # 患者文件夹根目录 OUTPUT_DIR = r"C:\Users\lenovo\doc\results_7.22" # 输出目录 # 执行批量处理 results_df = batch_extract_features(ROOT_DIR, OUTPUT_DIR) 我这串代码,即使是没有seg的图像也可以提取特征吗?和有seg的提取出来的特征有什么区别?
网址:MyLifeOrganized:时间管理神器,告别拖延 https://www.yuejiaxmz.com/news/view/1264471
相关内容
Android手机时间管理:告别拖延,高效生活新法则2024年免费的时间管理工具,让你不再拖延
告别拖延!话袋 APP 待办清单让时间管理超省心
时间管理神器 OpenTimer:用代码拯救拖延症
时间管理软件(MyLifeOrganized Pro)4.1.0 特别版
MyLifeOrganized,帮助你实现时间管理的神级软件
MyLifeOrganized(GTD时间管理辅助工具)V5.0.1 绿色免费版软件下载
如何管理时间书单?别让拖延症毁了你
请详细说明如何在MyLife Organized中创建任务并合理分配优先级和重要性,以及如何根据这些参数优化日常的时间管理?
待办任务管理软件 MyLifeOrganized: To