|
| 1 | +# CALCULATING ITA |
| 2 | + |
| 3 | +from derm_ita import get_ita |
| 4 | +from PIL import Image |
| 5 | +from derm_ita import get_kinyanjui_type |
| 6 | + |
| 7 | + |
| 8 | +# Folder containing images |
| 9 | +folder_path = 'train' |
| 10 | + |
| 11 | +# Initialize a list to store ITA values |
| 12 | +ita_dict = {'image_name': [], 'ITA': [], 'skin_tone': []} |
| 13 | + |
| 14 | +# Loop through all images in the folder |
| 15 | +for filename in os.listdir(folder_path): |
| 16 | + if filename.endswith('.jpg') or filename.endswith('.jpeg'): |
| 17 | + # Load the image |
| 18 | + image_path = os.path.join(folder_path, filename) |
| 19 | + #image = cv2.imread(image_path) |
| 20 | + |
| 21 | + # Calculate ITA |
| 22 | + ita = get_ita(image=Image.open(image_path)) |
| 23 | + |
| 24 | + |
| 25 | + kinyanjui_type = get_kinyanjui_type(ita) |
| 26 | + # Store image name and ITA value |
| 27 | + ita_dict['image_name'].append(filename.split('.jpg')[0]) |
| 28 | + ita_dict['ITA'].append(ita) |
| 29 | + ita_dict['skin_tone'].append(kinyanjui_type) |
| 30 | + |
| 31 | +# Create a DataFrame from the dictionary |
| 32 | +df_ITA = pd.DataFrame(ita_dict) |
| 33 | + |
| 34 | +print(df_ITA) |
| 35 | +df_ITA.to_csv('skin_tone.csv', index=False) |
| 36 | + |
| 37 | +# Append ITA values to existing DataFrame |
| 38 | +#existing_df = pd.merge(df, df_ITA, on='image_name', how='left').fillna(0) |
| 39 | + |
| 40 | +# Save the DataFrame to a CSV file |
| 41 | +#existing_df.to_csv('train_ITA_lib.csv', index=False) |
0 commit comments