folder ground 文件访问

本文介绍了一种使用Objective-C从资源包加载HTML文件到WebView的方法。通过NSBundle获取HTML路径,并读取文件内容,最后加载到WebView中展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

   

蓝色文件访问

  NSString * path = [[NSBundle mainBundle]pathForResource:@"one/two/two" ofType:@"html"];

    

        NSString *html = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];

        [_webview loadHTMLString:html baseURL:[NSURL URLWithString:path]];

 

转载于:https://www.cnblogs.com/xiezefeng/p/6902940.html

``` import numpy as np from sklearn.metrics import precision_recall_curve import cv2 import os import argparse def load_image(path): """加载图像为灰度图并归一化""" img = cv2.imread(path, cv2.IMREAD_GRAYSCALE) if img is None: raise ValueError(f"Failed to load image: {path}") # 归一化到[0,1]区间,确保精度 img = img.astype(np.float32) / 255.0 return img.flatten() def calculate_ods_fmeasure(predictions, ground_truths): """计算 ODS F-measure""" all_preds = [] all_gts = [] for pred_path, gt_path in zip(predictions, ground_truths): pred = load_image(pred_path) gt = load_image(gt_path) # 检查预测图像是否有效 if np.all(pred == 0) or np.all(pred == 1): print(f"Warning: Prediction image {pred_path} is all zeros or ones, possible issue with prediction.") all_preds.extend(pred) all_gts.extend(gt) precision, recall, _ = precision_recall_curve(all_gts, all_preds) f_scores = 2 * precision * recall / (precision + recall + 1e-10) ods_fmeasure = np.max(f_scores) return ods_fmeasure def main(): parser = argparse.ArgumentParser(description='Calculate ODS F-measure') parser.add_argument('--pred_folder', type=str, required=True, help='./val_output_test/RCF') parser.add_argument('--gt_folder', type=str, required=True, help='./GT') args = parser.parse_args() # 确保按照文件名排序,保证一一对应 pred_files = sorted([os.path.join(args.pred_folder, f) for f in os.listdir(args.pred_folder) if os.path.isfile(os.path.join(args.pred_folder, f))]) gt_files = sorted([os.path.join(args.gt_folder, f) for f in os.listdir(args.gt_folder) if os.path.isfile(os.path.join(args.gt_folder, f))]) if len(pred_files) != len(gt_files): print("Error: The number of prediction and ground truth files does not match.") exit(1) # 打印文件对比信息,确保顺序正确 for pred, gt in zip(pred_files, gt_files): print(f"Comparing Prediction: {os.path.basename(pred)} with Ground Truth: {os.path.basename(gt)}") ods_f = calculate_ods_fmeasure(pred_files, gt_files) print(f"ODS F-measure: {ods_f:.4f}") if __name__ == '__main__': main()```我运行了这个代码,显示这个报错,什么原因?(pytorch_xumg) xumg@hailab-System-Product-Name:~/graduate/PIED$ python ods.py --pred_folder /home/xumg/graduate/PIED/val_output_test --gt_folder /home/xumg/graduate/PIED/GT Error: The number of prediction and ground truth files does not match.
03-15
import os import numpy as np import matplotlib.pyplot as plt import SimpleITK as sitk from skimage import segmentation, morphology, measure, filters, exposure def load_mhd_file(file_path): """加载.mhd文件并返回numpy数组""" image = sitk.ReadImage(file_path) array = sitk.GetArrayFromImage(image) return array def preprocess_ct(ct_slice): """CT图像预处理(归一化+直方图均衡化)""" # 限制HU值范围(-1000到400) ct_slice = np.clip(ct_slice, -1000, 400) # 归一化到0-255 ct_normalized = ((ct_slice - (-1000)) / (400 - (-1000)) * 255).astype(np.uint8) # 直方图均衡化增强对比度 return exposure.equalize_hist(ct_normalized) def lung_segmentation(ct_slice): """肺部区域分割算法""" # 1. 大津阈值法(Otsu)进行初始分割 thresh = filters.threshold_otsu(ct_slice) binary = ct_slice > thresh # 2. 形态学开运算去除小噪声 cleaned = morphology.opening(binary, morphology.disk(2)) # 3. 填充孔洞 filled = morphology.remove_small_holes(cleaned, area_threshold=300) # 4. 连通区域分析,保留最大两个区域(左右肺) label_image = measure.label(filled) regions = measure.regionprops(label_image) areas = [r.area for r in regions] if len(areas) > 0: # 按面积降序排序 areas_sorted = sorted(areas, reverse=True) # 保留前两个最大区域 mask = np.zeros_like(binary) for region in regions: if region.area in areas_sorted[:2]: mask |= label_image == region.label return mask return filled def main(): # 文件路径设置(修改为实际路径) ct_dir = "path/to/CT_folder" mask_dir = "path/to/Mask_folder" sample_file = "case_001.mhd" # 示例文件名 # 加载CT和Mask数据 ct_array = load_mhd_file(os.path.join(ct_dir, sample_file)) mask_array = load_mhd_file(os.path.join(mask_dir, sample_file)) # 选择中间切片进行处理 slice_idx = ct_array.shape[0] // 2 ct_slice = ct_array[slice_idx] true_mask = mask_array[slice_idx] # CT图像预处理 processed_ct = preprocess_ct(ct_slice) # 执行分割算法 pred_mask = lung_segmentation(processed_ct) # 结果可视化 plt.figure(figsize=(15, 10)) plt.subplot(1, 3, 1) plt.imshow(processed_ct, cmap='gray') plt.title('Original CT Slice') plt.axis('off') plt.subplot(1, 3, 2) plt.imshow(true_mask, cmap='gray') plt.title('Ground Truth Mask') plt.axis('off') plt.subplot(1, 3, 3) plt.imshow(pred_mask, cmap='gray') plt.title('Segmentation Result') plt.axis('off') plt.tight_layout() plt.savefig('lung_segmentation_results.png', dpi=300) plt.show() if __name__ == "__main__": main() 这个最终只能显示一个图像,我想显示文件夹中所有组数据最终显示的图像
07-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值