这类项目标题看起来像是课程或教材里的编号没有直接给出具体内容。但根据“图像”和“项目1-7”的线索我推测这很可能是一套图像处理或计算机视觉的实践项目集合适合想通过实际案例上手图像技术的人。如果你拿到的是类似课程大纲但缺少详细步骤的材料最实际的落地方式不是空等完整教程而是先确认每个项目要解决的核心问题再自己搭建环境、准备数据、跑通基础流程最后再针对输出效果做调优。下面我按真实项目开发的顺序把这类图像项目从环境准备到结果验证的全流程拆解一遍。即使你的具体项目内容和我的示例不同这个框架也能帮你把零散的标题变成可执行的实验。1. 先明确每个图像项目到底要解决什么问题看到“项目1-7”这样的编号第一步不是急着找代码而是先推断每个项目的目标。常见的图像项目类型包括但不限于1.1 基础操作类图像读取、显示、保存颜色空间转换RGB、灰度、HSV图像缩放、旋转、裁剪亮度、对比度、饱和度调整1.2 图像增强与滤波平滑滤波均值滤波、高斯滤波锐化滤波边缘检测Sobel、Canny噪声添加与去噪椒盐噪声、高斯噪声1.3 图像分割阈值分割全局阈值、自适应阈值区域生长分水岭算法基于深度学习的语义分割1.4 特征提取与匹配角点检测Harris、SIFT、ORB特征描述与匹配图像拼接全景图生成1.5 目标检测与识别模板匹配传统方法HOGSVM深度学习目标检测YOLO、SSD、Faster R-CNN1.6 图像生成与风格迁移基于GAN的图像生成神经风格迁移超分辨率重建1.7 图像分类传统特征分类器卷积神经网络CNN分类你需要根据你的课程材料或项目说明确定每个编号对应哪种类型。如果完全没有说明就从最简单的图像读写开始逐步增加难度。2. 搭建一个可复用的图像项目实验环境图像项目对环境配置比较敏感不同库的版本兼容性会影响代码运行。我建议用以下配置作为基础环境2.1 基础Python环境# 创建专用环境 conda create -n image-projects python3.8 conda activate image-projects # 核心图像处理库 pip install opencv-python4.5.5.64 pip install Pillow9.0.1 pip install matplotlib3.5.1 pip install numpy1.21.52.2 深度学习相关环境可选如果你的项目涉及深度学习额外安装# 根据你的CUDA版本选择合适的pytorch pip install torch1.12.1cu113 torchvision0.13.1cu113 -f https://download.pytorch.org/whl/torch_stable.html # 或使用CPU版本 pip install torch1.12.1cpu torchvision0.13.1cpu -f https://download.pytorch.org/whl/torch_stable.html # 其他常用库 pip install scikit-image0.19.2 pip install tensorflow2.8.0 # 如果需要tensorflow2.3 项目目录结构保持清晰的目录结构有助于管理多个项目image-projects/ ├── data/ # 图像数据 │ ├── input/ # 原始图像 │ └── output/ # 处理结果 ├── utils/ # 工具函数 │ └── image_utils.py ├── project1/ # 项目1代码和文档 ├── project2/ # 项目2代码和文档 └── requirements.txt2.4 测试环境是否正常创建test_environment.py验证基础功能import cv2 import numpy as np from PIL import Image import matplotlib.pyplot as plt print(fOpenCV版本: {cv2.__version__}) print(fPIL版本: {Image.__version__}) # 创建测试图像 test_image np.random.randint(0, 255, (100, 100, 3), dtypenp.uint8) cv2.imwrite(data/output/test_image.jpg, test_image) print(环境测试完成)3. 从图像基础操作开始验证项目可行性无论你的项目列表包含什么内容都建议从最基本的图像读写开始。这是后续所有操作的基础也能帮你快速发现环境配置问题。3.1 图像读取与显示的不同方式import cv2 from PIL import Image import matplotlib.pyplot as plt import numpy as np def read_image_demo(image_path): 演示不同库读取图像的差异 # OpenCV读取BGR格式 img_cv2 cv2.imread(image_path) print(fOpenCV图像形状: {img_cv2.shape}) # (高度, 宽度, 通道数) # PIL读取RGB格式 img_pil Image.open(image_path) print(fPIL图像模式: {img_pil.mode}, 尺寸: {img_pil.size}) # (宽度, 高度) # 显示对比 fig, (ax1, ax2) plt.subplots(1, 2, figsize(10, 4)) # OpenCV显示需要转换颜色空间 img_cv2_rgb cv2.cvtColor(img_cv2, cv2.COLOR_BGR2RGB) ax1.imshow(img_cv2_rgb) ax1.set_title(OpenCV读取 (转RGB)) ax1.axis(off) ax2.imshow(img_pil) ax2.set_title(PIL读取) ax2.axis(off) plt.tight_layout() plt.savefig(data/output/read_comparison.jpg, dpi150, bbox_inchestight) plt.show() return img_cv2, img_pil # 使用示例 img_cv, img_pil read_image_demo(data/input/your_image.jpg)3.2 图像格式转换与保存def image_conversion_demo(img_cv2, img_pil): 演示图像格式转换 # OpenCV转PIL img_cv2_rgb cv2.cvtColor(img_cv2, cv2.COLOR_BGR2RGB) img_cv2_to_pil Image.fromarray(img_cv2_rgb) # PIL转OpenCV img_pil_to_cv2 cv2.cvtColor(np.array(img_pil), cv2.COLOR_RGB2BGR) # 保存不同格式 cv2.imwrite(data/output/opencv_save.jpg, img_cv2) img_pil.save(data/output/pil_save.png) # 保存为不同质量 img_pil.save(data/output/quality_90.jpg, quality90) img_pil.save(data/output/quality_30.jpg, quality30) print(格式转换和保存完成)3.3 基础图像处理操作def basic_operations_demo(img_cv2): 基础图像处理操作 # 1. 调整大小 resized cv2.resize(img_cv2, (300, 200)) # 指定宽高 # 2. 旋转 height, width img_cv2.shape[:2] rotation_matrix cv2.getRotationMatrix2D((width/2, height/2), 45, 1) # 旋转45度 rotated cv2.warpAffine(img_cv2, rotation_matrix, (width, height)) # 3. 裁剪 cropped img_cv2[50:200, 100:300] # y范围, x范围 # 4. 亮度调整 brightened cv2.convertScaleAbs(img_cv2, alpha1.2, beta20) # 增加亮度 # 显示结果 operations [resized, rotated, cropped, brightened] titles [调整大小, 旋转45度, 裁剪, 亮度增强] plt.figure(figsize(12, 8)) for i, (img, title) in enumerate(zip(operations, titles)): plt.subplot(2, 2, i1) # 转换颜色空间用于显示 if len(img.shape) 3: img_display cv2.cvtColor(img, cv2.COLOR_BGR2RGB) else: img_display img plt.imshow(img_display) plt.title(title) plt.axis(off) plt.tight_layout() plt.savefig(data/output/basic_operations.jpg, dpi150, bbox_inchestight) plt.show()4. 分类型实现图像项目核心功能根据第一节的项目类型分类这里给出每种类型的核心实现示例。你可以根据你的具体项目需求选择相应的代码框架。4.1 图像增强与滤波实现def image_filtering_demo(img_cv2): 图像滤波操作演示 # 转换为灰度图进行处理 gray cv2.cvtColor(img_cv2, cv2.COLOR_BGR2GRAY) # 1. 均值滤波 blur_mean cv2.blur(gray, (5, 5)) # 2. 高斯滤波 blur_gaussian cv2.GaussianBlur(gray, (5, 5), 0) # 3. 中值滤波对椒盐噪声效果好 # 先添加椒盐噪声 noisy gray.copy() salt_pepper_ratio 0.01 amount salt_pepper_ratio * gray.size # 添加椒噪声白点 coords [np.random.randint(0, i-1, int(amount)) for i in gray.shape] noisy[coords[0], coords[1]] 255 # 添加盐噪声黑点 coords [np.random.randint(0, i-1, int(amount)) for i in gray.shape] noisy[coords[0], coords[1]] 0 # 中值滤波去噪 denoised cv2.medianBlur(noisy, 5) # 4. 边缘检测 edges cv2.Canny(gray, 50, 150) # 显示结果 images [gray, blur_mean, blur_gaussian, noisy, denoised, edges] titles [原图灰度, 均值滤波, 高斯滤波, 椒盐噪声, 中值滤波去噪, 边缘检测] plt.figure(figsize(15, 8)) for i, (img, title) in enumerate(zip(images, titles)): plt.subplot(2, 3, i1) plt.imshow(img, cmapgray) plt.title(title) plt.axis(off) plt.tight_layout() plt.savefig(data/output/filtering_results.jpg, dpi150, bbox_inchestight) plt.show() def histogram_equalization_demo(img_cv2): 直方图均衡化增强对比度 gray cv2.cvtColor(img_cv2, cv2.COLOR_BGR2GRAY) # 全局直方图均衡化 equalized_global cv2.equalizeHist(gray) # CLAHE限制对比度自适应直方图均衡化 clahe cv2.createCLAHE(clipLimit2.0, tileGridSize(8, 8)) equalized_clahe clahe.apply(gray) # 显示结果和直方图 plt.figure(figsize(12, 8)) # 原图及直方图 plt.subplot(2, 3, 1) plt.imshow(gray, cmapgray) plt.title(原图灰度) plt.axis(off) plt.subplot(2, 3, 4) plt.hist(gray.ravel(), 256, [0, 256]) plt.title(原图直方图) # 全局均衡化结果 plt.subplot(2, 3, 2) plt.imshow(equalized_global, cmapgray) plt.title(全局均衡化) plt.axis(off) plt.subplot(2, 3, 5) plt.hist(equalized_global.ravel(), 256, [0, 256]) plt.title(全局均衡化直方图) # CLAHE结果 plt.subplot(2, 3, 3) plt.imshow(equalized_clahe, cmapgray) plt.title(CLAHE均衡化) plt.axis(off) plt.subplot(2, 3, 6) plt.hist(equalized_clahe.ravel(), 256, [0, 256]) plt.title(CLAHE直方图) plt.tight_layout() plt.savefig(data/output/histogram_equalization.jpg, dpi150, bbox_inchestight) plt.show()4.2 图像分割实现def image_segmentation_demo(img_cv2): 图像分割方法演示 gray cv2.cvtColor(img_cv2, cv2.COLOR_BGR2GRAY) # 1. 全局阈值分割 _, thresh_global cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY) # 2. 自适应阈值分割对光照不均的图像效果好 thresh_adaptive cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2) # 3. Otsu阈值分割自动确定最佳阈值 _, thresh_otsu cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY cv2.THRESH_OTSU) # 显示结果 images [gray, thresh_global, thresh_adaptive, thresh_otsu] titles [原图灰度, 全局阈值, 自适应阈值, Otsu阈值] plt.figure(figsize(12, 8)) for i, (img, title) in enumerate(zip(images, titles)): plt.subplot(2, 2, i1) plt.imshow(img, cmapgray) plt.title(title) plt.axis(off) plt.tight_layout() plt.savefig(data/output/segmentation_results.jpg, dpi150, bbox_inchestight) plt.show() def edge_based_segmentation_demo(img_cv2): 基于边缘的分割方法 gray cv2.cvtColor(img_cv2, cv2.COLOR_BGR2GRAY) # 边缘检测 edges cv2.Canny(gray, 50, 150) # 形态学操作闭合边缘间隙 kernel cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3)) closed_edges cv2.morphologyEx(edges, cv2.MORPH_CLOSE, kernel) # 查找轮廓 contours, _ cv2.findContours(closed_edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) # 在原图上绘制轮廓 result_img img_cv2.copy() cv2.drawContours(result_img, contours, -1, (0, 255, 0), 2) # 显示结果 plt.figure(figsize(12, 4)) plt.subplot(1, 3, 1) plt.imshow(cv2.cvtColor(img_cv2, cv2.COLOR_BGR2RGB)) plt.title(原图) plt.axis(off) plt.subplot(1, 3, 2) plt.imshow(closed_edges, cmapgray) plt.title(边缘检测闭合) plt.axis(off) plt.subplot(1, 3, 3) plt.imshow(cv2.cvtColor(result_img, cv2.COLOR_BGR2RGB)) plt.title(轮廓检测结果) plt.axis(off) plt.tight_layout() plt.savefig(data/output/edge_segmentation.jpg, dpi150, bbox_inchestight) plt.show() print(f检测到 {len(contours)} 个轮廓)4.3 特征提取与匹配实现def feature_detection_demo(img_cv2): 特征点检测演示 gray cv2.cvtColor(img_cv2, cv2.COLOR_BGR2GRAY) # 1. Harris角点检测 harris_img img_cv2.copy() harris_corners cv2.cornerHarris(gray, 2, 3, 0.04) harris_corners cv2.dilate(harris_corners, None) harris_img[harris_corners 0.01 * harris_corners.max()] [0, 0, 255] # 2. ORB特征检测 orb_img img_cv2.copy() orb cv2.ORB_create(nfeatures100) keypoints_orb, descriptors_orb orb.detectAndCompute(gray, None) orb_img cv2.drawKeypoints(orb_img, keypoints_orb, None, color(0, 255, 0)) # 3. SIFT特征检测需要opencv-contrib-python try: sift_img img_cv2.copy() sift cv2.SIFT_create() keypoints_sift, descriptors_sift sift.detectAndCompute(gray, None) sift_img cv2.drawKeypoints(sift_img, keypoints_sift, None, color(255, 0, 0)) sift_available True except: sift_img img_cv2.copy() cv2.putText(sift_img, SIFT not available, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2) sift_available False # 显示结果 plt.figure(figsize(15, 5)) plt.subplot(1, 3, 1) plt.imshow(cv2.cvtColor(harris_img, cv2.COLOR_BGR2RGB)) plt.title(fHarris角点检测) plt.axis(off) plt.subplot(1, 3, 2) plt.imshow(cv2.cvtColor(orb_img, cv2.COLOR_BGR2RGB)) plt.title(fORB特征点: {len(keypoints_orb)}个) plt.axis(off) plt.subplot(1, 3, 3) plt.imshow(cv2.cvtColor(sift_img, cv2.COLOR_BGR2RGB)) if sift_available: plt.title(fSIFT特征点: {len(keypoints_sift)}个) else: plt.title(SIFT需要opencv-contrib-python) plt.axis(off) plt.tight_layout() plt.savefig(data/output/feature_detection.jpg, dpi150, bbox_inchestight) plt.show() def feature_matching_demo(img1_path, img2_path): 特征匹配演示需要两张相关图像 img1 cv2.imread(img1_path) img2 cv2.imread(img2_path) gray1 cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY) gray2 cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY) # 使用ORB检测特征 orb cv2.ORB_create(nfeatures500) kp1, des1 orb.detectAndCompute(gray1, None) kp2, des2 orb.detectAndCompute(gray2, None) # 特征匹配 bf cv2.BFMatcher(cv2.NORM_HAMMING, crossCheckTrue) matches bf.match(des1, des2) matches sorted(matches, keylambda x: x.distance) # 绘制匹配结果 result_img cv2.drawMatches(img1, kp1, img2, kp2, matches[:50], None, flagscv2.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS) plt.figure(figsize(15, 8)) plt.imshow(cv2.cvtColor(result_img, cv2.COLOR_BGR2RGB)) plt.title(f特征匹配结果 (显示前50个最佳匹配)) plt.axis(off) plt.tight_layout() plt.savefig(data/output/feature_matching.jpg, dpi150, bbox_inchestight) plt.show() print(f找到 {len(matches)} 个匹配点)4.4 目标检测实现传统方法def template_matching_demo(img_cv2, template_path): 模板匹配目标检测 # 读取模板图像 template cv2.imread(template_path, 0) gray cv2.cvtColor(img_cv2, cv2.COLOR_BGR2GRAY) # 获取模板尺寸 w, h template.shape[::-1] # 多种匹配方法比较 methods [cv2.TM_CCOEFF, cv2.TM_CCOEFF_NORMED, cv2.TM_CCORR, cv2.TM_CCORR_NORMED, cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED] plt.figure(figsize(15, 10)) for i, method_name in enumerate(methods): method eval(method_name) # 应用模板匹配 result cv2.matchTemplate(gray, template, method) min_val, max_val, min_loc, max_loc cv2.minMaxLoc(result) # 根据方法类型确定最佳匹配位置 if method in [cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED]: top_left min_loc else: top_left max_loc bottom_right (top_left[0] w, top_left[1] h) # 绘制矩形框 result_img img_cv2.copy() cv2.rectangle(result_img, top_left, bottom_right, (0, 255, 0), 2) plt.subplot(2, 3, i1) plt.imshow(cv2.cvtColor(result_img, cv2.COLOR_BGR2RGB)) plt.title(method_name) plt.axis(off) plt.tight_layout() plt.savefig(data/output/template_matching.jpg, dpi150, bbox_inchestight) plt.show() def contour_based_detection_demo(img_cv2): 基于轮廓的目标检测 # 转换为HSV颜色空间进行颜色分割 hsv cv2.cvtColor(img_cv2, cv2.COLOR_BGR2HSV) # 定义颜色范围示例检测红色物体 lower_red1 np.array([0, 50, 50]) upper_red1 np.array([10, 255, 255]) lower_red2 np.array([170, 50, 50]) upper_red2 np.array([180, 255, 255]) # 创建红色掩膜 mask1 cv2.inRange(hsv, lower_red1, upper_red1) mask2 cv2.inRange(hsv, lower_red2, upper_red2) mask mask1 mask2 # 形态学操作去除噪声 kernel np.ones((5, 5), np.uint8) mask cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel) mask cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel) # 查找轮廓 contours, _ cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) # 在原图上绘制检测结果 result_img img_cv2.copy() for i, contour in enumerate(contours): # 过滤小轮廓 area cv2.contourArea(contour) if area 500: # 根据图像大小调整阈值 continue # 获取边界框 x, y, w, h cv2.boundingRect(contour) cv2.rectangle(result_img, (x, y), (xw, yh), (0, 255, 0), 2) # 添加标签 cv2.putText(result_img, fObj{i1}, (x, y-10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) # 显示结果 plt.figure(figsize(12, 4)) plt.subplot(1, 3, 1) plt.imshow(cv2.cvtColor(img_cv2, cv2.COLOR_BGR2RGB)) plt.title(原图) plt.axis(off) plt.subplot(1, 3, 2) plt.imshow(mask, cmapgray) plt.title(颜色掩膜) plt.axis(off) plt.subplot(1, 3, 3) plt.imshow(cv2.cvtColor(result_img, cv2.COLOR_BGR2RGB)) plt.title(f检测到 {len(contours)} 个目标) plt.axis(off) plt.tight_layout() plt.savefig(data/output/contour_detection.jpg, dpi150, bbox_inchestight) plt.show()5. 深度学习图像项目快速上手如果你的项目涉及深度学习这里给出一个简单的图像分类示例框架import torch import torch.nn as nn import torch.optim as optim from torch.utils.data import DataLoader, Dataset from torchvision import transforms, models from PIL import Image import os class SimpleCNN(nn.Module): 简单的CNN图像分类模型 def __init__(self, num_classes10): super(SimpleCNN, self).__init__() self.features nn.Sequential( nn.Conv2d(3, 32, kernel_size3, padding1), nn.ReLU(), nn.MaxPool2d(2), nn.Conv2d(32, 64, kernel_size3, padding1), nn.ReLU(), nn.MaxPool2d(2), nn.Conv2d(64, 128, kernel_size3, padding1), nn.ReLU(), nn.MaxPool2d(2), ) self.classifier nn.Sequential( nn.Dropout(0.5), nn.Linear(128 * 28 * 28, 512), # 假设输入图像为224x224 nn.ReLU(), nn.Dropout(0.5), nn.Linear(512, num_classes) ) def forward(self, x): x self.features(x) x x.view(x.size(0), -1) x self.classifier(x) return x class ImageDataset(Dataset): 自定义图像数据集 def __init__(self, image_dir, transformNone): self.image_dir image_dir self.transform transform self.images [] self.labels [] # 假设目录结构为: image_dir/class1/, image_dir/class2/, ... classes os.listdir(image_dir) self.class_to_idx {cls: i for i, cls in enumerate(classes)} for class_name in classes: class_dir os.path.join(image_dir, class_name) if os.path.isdir(class_dir): for img_name in os.listdir(class_dir): if img_name.lower().endswith((.png, .jpg, .jpeg)): self.images.append(os.path.join(class_dir, img_name)) self.labels.append(self.class_to_idx[class_name]) def __len__(self): return len(self.images) def __getitem__(self, idx): image_path self.images[idx] label self.labels[idx] image Image.open(image_path).convert(RGB) if self.transform: image self.transform(image) return image, label def train_simple_model(): 训练简单图像分类模型 # 数据预处理 transform transforms.Compose([ transforms.Resize((224, 224)), transforms.ToTensor(), transforms.Normalize(mean[0.485, 0.456, 0.406], std[0.229, 0.224, 0.225]) ]) # 创建数据集需要你准备实际数据 # dataset ImageDataset(data/train, transformtransform) # dataloader DataLoader(dataset, batch_size32, shuffleTrue) # 创建模型 model SimpleCNN(num_classes10) criterion nn.CrossEntropyLoss() optimizer optim.Adam(model.parameters(), lr0.001) print(模型结构:) print(model) print(\n训练框架已搭建完成需要准备实际数据即可开始训练) return model # 使用预训练模型进行迁移学习 def transfer_learning_example(): 迁移学习示例 # 加载预训练模型 model models.resnet18(pretrainedTrue) # 冻结特征提取层 for param in model.parameters(): param.requires_grad False # 修改最后的全连接层 num_features model.fc.in_features model.fc nn.Linear(num_features, 10) # 假设有10个类别 print(迁移学习模型准备完成) return model6. 项目结果验证与性能评估完成每个图像项目后都需要系统性地验证结果质量。6.1 图像质量评估指标def image_quality_metrics(original_img, processed_img): 计算图像质量评估指标 # 转换为灰度图计算指标 if len(original_img.shape) 3: original_gray cv2.cvtColor(original_img, cv2.COLOR_BGR2GRAY) processed_gray cv2.cvtColor(processed_img, cv2.COLOR_BGR2GRAY) else: original_gray original_img processed_gray processed_img # 均方误差 (MSE) mse np.mean((original_gray.astype(float) - processed_gray.astype(float)) ** 2) # 峰值信噪比 (PSNR) if mse 0: psnr float(inf) else: psnr 20 * np.log10(255.0 / np.sqrt(mse)) # 结构相似性指数 (SSIM) - 简化版本 def simple_ssim(img1, img2): C1 (0.01 * 255) ** 2 C2 (0.03 * 255) ** 2 img1 img1.astype(np.float64) img2 img2.astype(np.float64) kernel cv2.getGaussianKernel(11, 1.5) window np.outer(kernel, kernel.transpose()) mu1 cv2.filter2D(img1, -1, window)[5:-5, 5:-5] mu2 cv2.filter2D(img2, -1, window)[5:-5, 5:-5] mu1_sq mu1 ** 2 mu2_sq mu2 ** 2 mu1_mu2 mu1 * mu2 sigma1_sq cv2.filter2D(img1**2, -1, window)[5:-5, 5:-5] - mu1_sq sigma2_sq cv2.filter2D(img2**2, -1, window)[5:-5, 5:-5] - mu2_sq sigma12 cv2.filter2D(img1*img2, -1, window)[5:-5, 5:-5] - mu1_mu2 ssim_map ((2 * mu1_mu2 C1) * (2 * sigma12 C2)) / \ ((mu1_sq mu2_sq C1) * (sigma1_sq sigma2_sq C2)) return ssim_map.mean() ssim simple_ssim(original_gray, processed_gray) print(f图像质量评估指标:) print(fMSE (均方误差): {mse:.2f}) print(fPSNR (峰值信噪比): {psnr:.2f} dB) print(fSSIM (结构相似性): {ssim:.4f}) return {mse: mse, psnr: psnr, ssim: ssim} def processing_time_benchmark(processing_function, test_image, iterations10): 处理时间基准测试 times [] for i in range(iterations): start_time time.time() result processing_function(test_image) end_time time.time() times.append(end_time - start_time) avg_time np.mean(times) std_time np.std(times) print(f处理时间基准测试 ({iterations}次迭代):) print(f平均时间: {avg_time*1000:.2