-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0117_tortuosity-mean7.py
62 lines (49 loc) · 2.66 KB
/
0117_tortuosity-mean7.py
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
import os
import pandas as pd
from skimage import io
import util2
import numpy as np
import cv2
import tortuosity
parent_dir = "/raid/jupyter-charlielibear.md09-24f36/entropy/data/"
excel_path = "/raid/jupyter-charlielibear.md09-24f36/entropy/excel/patient_list.xlsx" # Replace with the path to your Excel file
# Read the Excel file with patient numbers
patient_df = pd.read_excel(excel_path)
print(patient_df.columns)
# Prepare the DataFrame for results
results_df = pd.DataFrame(index=patient_df.index)
# Copy the patient numbers to the results DataFrame
results_df['inactive'] = patient_df['inactive']
results_df['active'] = patient_df['active']
# Loop through each preprocessing method directory
for dirname in os.listdir(parent_dir):
# if dirname.startswith(".") or dirname == 'faz' or dirname == 'gabor_faz':
# continue
if dirname == "mean7" or dirname == 'gabor_mean7':
pre_dir = os.path.join(parent_dir, dirname)
print(f"Processing directory: {pre_dir}")
# Prepare columns for the current preprocessing method
results_df[f'inactive_{dirname}'] = np.nan
results_df[f'active_{dirname}'] = np.nan
# Loop through each patient number and status
for index, row in patient_df.iterrows():
for status in ['inactive', 'active']:
patient_number = row[status]
image_pattern = f"{patient_number}_*.jpg" # Replace with the actual pattern if needed
image_path = os.path.join(pre_dir, status, image_pattern)
# Find the image file that matches the pattern
for file in os.listdir(os.path.join(pre_dir, status)):
if file.startswith(str(patient_number) + "_"):
full_image_path = os.path.join(pre_dir, status, file)
print(f"Processing image: {full_image_path}")
# Read the image and calculate the entropy
img = cv2.imread(full_image_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
tor = tortuosity.calculate_bvt_from_image(img, 128)
# Store the entropy value in the DataFrame
results_df.at[index, f'{status}_{dirname}'] = tor
# break
# Calculate entropy difference or any other required calculation
# Example: results_df['entropy_difference'] = results_df['active_preprocessmethod'] - results_df['inactive_preprocessmethod']
# Save the results to an Excel file
results_df.to_excel('/raid/jupyter-charlielibear.md09-24f36/entropy/excel/mean7_tortuosity.xlsx')