File size: 2,010 Bytes
879577c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 9,
"id": "b4ce7b4b-3994-45ba-812e-a2bf53544df2",
"metadata": {},
"outputs": [],
"source": [
"import cv2\n",
"import numpy as np\n",
"import os\n",
"from sklearn.metrics import mean_squared_error\n",
"import pandas as pd\n",
"\n",
"def compare_depth_maps(dir1, dir2):\n",
" # 读取dir2中的图像并调整尺寸\n",
" img2 = cv2.imread(dir2, cv2.IMREAD_GRAYSCALE)\n",
" img2_resized = cv2.resize(img2, (512, 512))\n",
"\n",
" mse_list = []\n",
" for file in os.listdir(dir1):\n",
" if file.endswith(\".png\"): # 假设所有深度图都是.png格式\n",
" # 读取dir1中的图像\n",
" img1 = cv2.imread(os.path.join(dir1, file), cv2.IMREAD_GRAYSCALE)\n",
" # 计算MSE并添加到列表中\n",
" mse = mean_squared_error(img1, img2_resized)\n",
" mse_list.append([file, mse])\n",
"\n",
" # 将结果写入Excel\n",
" df = pd.DataFrame(mse_list, columns=['Image', 'MSE'])\n",
" df.to_excel(os.path.join(dir1, 'mse_results.xlsx'), index=False)\n",
"\n",
"# 使用函数\n",
"compare_depth_maps('D:\\\\SubDiffusion\\\\928\\\\lunwen\\\\f\\\\f-dp\\\\fake', 'D:\\\\SubDiffusion\\\\928\\\\lunwen\\\\f\\\\f-dp\\\\real\\\\f-4.png')\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cfef9116-928c-4aab-9b89-6ed2979170b8",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|