import os
import re
import pandas as pd
measure_dir = (
r"\\gabor\Project\内科\舌診\TIAS\開発\カラーチャート\TCC2025-01\退色調査3 マットフォト" + "\\"
)
target_lab_csv = (
r"\\gabor\Project\内科\舌診\TIAS\開発\カラーチャート\TCC2025-01\色調整\Target_Lab.csv"
)
tcc_lab = []
def read_data():
"""Read data files and check for required columns."""
global tcc_lab
kinds = ["tcc1", "tcc2", "tcc3", "tcc4", "tcc5", "tcc6"]
for i in range(24):
tcc_lab.append([])
target_lab = pd.read_csv(target_lab_csv, encoding="utf-8", header=None)
files = []
for kind in kinds:
csv_files = [
f for f in os.listdir(measure_dir) if f.endswith(".csv") and f.startswith(kind)
]
csv_files.sort(reverse=True)
files.append(csv_files[0]) # Get the latest file for each kind
for file in files:
file_path = os.path.join(measure_dir, file)
print(f"Reading {file}")
df = pd.read_csv(file_path, encoding="utf-8")
required_columns = {"no", "L*", "a*", "b*"}
if not required_columns.issubset(df.columns):
print(f"Error: Missing required columns in {file_path}")
exit(1)
for index, row in df.iterrows():
no = int(row["no"])
L = float(row["L*"])
a = float(row["a*"])
b = float(row["b*"])
tcc_lab[no - 1].append((L, a, b))
for index, row in target_lab.iterrows():
print(f"CC{index + 1:02d} Target Lab: L={row[0]}, a={row[1]}, b={row[2]}")
for i in range(len(tcc_lab[index])):
L, a, b = tcc_lab[index][i]
print(
f" Measured in {kinds[i]}: L={L}, a={a}, b={b} "
f"(ΔE*={((L - row[0]) ** 2 + (a - row[1]) ** 2 + (b - row[2]) ** 2) ** 0.5:.2f})"
)
# print(tcc_lab)
if __name__ == "__main__":
read_data()