Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- CRC100k/NCT-CRC-HE-100K/DEB/DEB-MWDTYIDM.png +3 -0
- CRC100k/NCT-CRC-HE-100K/DEB/DEB-MWEEFCDA.png +3 -0
- CRC100k/NCT-CRC-HE-100K/DEB/DEB-MWGKPPHY.png +3 -0
- CRC100k/NCT-CRC-HE-100K/DEB/DEB-MWKDFAMI.png +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058285.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058286.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058288.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058289.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058293.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058295.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058296.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058298.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058299.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058303.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058304.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058305.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058307.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058309.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058310.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058314.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058315.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058317.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058318.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058319.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058320.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058325.jpg +3 -0
- ISIC2019/ISIC_2019_Training_Input/ISIC_0058328.jpg +3 -0
- RUSCHN/extract_unique_questions.py +195 -0
- RUSCHN/ruschn_unique_questions_original.json +0 -0
- RadImageNet/radiology_ai/CT/Airspace_opacity/lung058523.png +3 -0
- RadImageNet/radiology_ai/CT/Airspace_opacity/lung058525.png +3 -0
- RadImageNet/radiology_ai/CT/Airspace_opacity/lung058526.png +3 -0
- RadImageNet/radiology_ai/CT/Airspace_opacity/lung058527.png +3 -0
- RadImageNet/radiology_ai/CT/Airspace_opacity/lung058528.png +3 -0
- RadImageNet/radiology_ai/CT/Airspace_opacity/lung058529.png +3 -0
- RadImageNet/radiology_ai/CT/Airspace_opacity/lung058530.png +3 -0
- RadImageNet/radiology_ai/CT/Airspace_opacity/lung058531.png +3 -0
- RadImageNet/radiology_ai/CT/Airspace_opacity/lung058532.png +3 -0
- RadImageNet/radiology_ai/CT/Airspace_opacity/lung058533.png +3 -0
- RadImageNet/radiology_ai/CT/Airspace_opacity/lung058534.png +3 -0
- RadImageNet/radiology_ai/CT/Airspace_opacity/lung058535.png +3 -0
- RadImageNet/radiology_ai/CT/Airspace_opacity/lung058536.png +3 -0
- RadImageNet/radiology_ai/MR/chondral_pathology/hip002863.png +3 -0
- RadImageNet/radiology_ai/MR/chondral_pathology/hip002864.png +3 -0
- RadImageNet/radiology_ai/MR/chondral_pathology/hip002865.png +3 -0
- RadImageNet/radiology_ai/MR/chondral_pathology/hip002866.png +3 -0
- RadImageNet/radiology_ai/MR/chondral_pathology/hip002867.png +3 -0
- RadImageNet/radiology_ai/MR/chondral_pathology/hip002868.png +3 -0
- RadImageNet/radiology_ai/MR/chondral_pathology/hip002869.png +3 -0
- RadImageNet/radiology_ai/MR/chondral_pathology/hip002870.png +3 -0
CRC100k/NCT-CRC-HE-100K/DEB/DEB-MWDTYIDM.png
ADDED
|
Git LFS Details
|
CRC100k/NCT-CRC-HE-100K/DEB/DEB-MWEEFCDA.png
ADDED
|
Git LFS Details
|
CRC100k/NCT-CRC-HE-100K/DEB/DEB-MWGKPPHY.png
ADDED
|
Git LFS Details
|
CRC100k/NCT-CRC-HE-100K/DEB/DEB-MWKDFAMI.png
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058285.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058286.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058288.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058289.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058293.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058295.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058296.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058298.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058299.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058303.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058304.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058305.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058307.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058309.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058310.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058314.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058315.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058317.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058318.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058319.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058320.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058325.jpg
ADDED
|
Git LFS Details
|
ISIC2019/ISIC_2019_Training_Input/ISIC_0058328.jpg
ADDED
|
Git LFS Details
|
RUSCHN/extract_unique_questions.py
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
import random
|
| 4 |
+
import csv
|
| 5 |
+
from typing import List, Dict
|
| 6 |
+
from PIL import Image
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def get_random_image_path(answer: str) -> str:
|
| 10 |
+
"""
|
| 11 |
+
Get a random image path from the appropriate subdirectory based on the answer.
|
| 12 |
+
Each answer type corresponds to a specific subdirectory in RUSCHN/images/.
|
| 13 |
+
For 'x_ray.', it searches in the main RUSCHN/images directory.
|
| 14 |
+
Images are located in numbered subdirectories (e.g., RUSCHN/images/DIP/1/).
|
| 15 |
+
Ensures that no image is reused from the original dataset.
|
| 16 |
+
"""
|
| 17 |
+
# Map answer to directory path
|
| 18 |
+
answer_to_dir = {
|
| 19 |
+
'Distal Interphalangeal': 'RUSCHN/images/DIP',
|
| 20 |
+
'First Distal Interphalangeal': 'RUSCHN/images/DIPFirst',
|
| 21 |
+
'First Metacarpophalangeal': 'RUSCHN/images/MCPFirst',
|
| 22 |
+
'First Proximal Interphalangeal': 'RUSCHN/images/PIPFirst',
|
| 23 |
+
'Metacarpophalangeal': 'RUSCHN/images/MCP',
|
| 24 |
+
'Middle Interphalangeal': 'RUSCHN/images/MIP',
|
| 25 |
+
'Proximal Interphalangeal': 'RUSCHN/images/PIP',
|
| 26 |
+
'Radius': 'RUSCHN/images/Radius',
|
| 27 |
+
'Ulna': 'RUSCHN/images/Ulna',
|
| 28 |
+
'x_ray.': 'RUSCHN/images'
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
if answer not in answer_to_dir:
|
| 32 |
+
raise ValueError(f"Unknown answer type: {answer}")
|
| 33 |
+
|
| 34 |
+
# Load existing image filenames from the original JSON file
|
| 35 |
+
with open('Original_open/RUS CHN.json', 'r') as f:
|
| 36 |
+
original_data = json.load(f)
|
| 37 |
+
|
| 38 |
+
# Create sets of both full paths and base filenames from original data
|
| 39 |
+
used_full_paths = {item['image_path'] for item in original_data}
|
| 40 |
+
used_filenames = {os.path.basename(item['image_path']).split('.')[0] for item in original_data}
|
| 41 |
+
|
| 42 |
+
# Get all images from the appropriate directory
|
| 43 |
+
image_dir = answer_to_dir[answer]
|
| 44 |
+
all_images = []
|
| 45 |
+
|
| 46 |
+
def collect_images_from_dir(directory):
|
| 47 |
+
"""Helper function to recursively collect all PNG files from a directory and its subdirectories."""
|
| 48 |
+
for item in os.listdir(directory):
|
| 49 |
+
item_path = os.path.join(directory, item)
|
| 50 |
+
if os.path.isdir(item_path):
|
| 51 |
+
collect_images_from_dir(item_path)
|
| 52 |
+
elif item.endswith('.png'):
|
| 53 |
+
# Get the relative path from the base image directory
|
| 54 |
+
rel_path = os.path.relpath(item_path, image_dir)
|
| 55 |
+
all_images.append(rel_path)
|
| 56 |
+
|
| 57 |
+
# Collect all images from the directory structure
|
| 58 |
+
collect_images_from_dir(image_dir)
|
| 59 |
+
|
| 60 |
+
# Filter out already used images
|
| 61 |
+
matching_images = []
|
| 62 |
+
for img in all_images:
|
| 63 |
+
base_name = os.path.basename(img).split('.')[0] # Remove .png extension
|
| 64 |
+
full_path = f"{image_dir}/{img}"
|
| 65 |
+
|
| 66 |
+
# Check both the base filename and full path to ensure uniqueness
|
| 67 |
+
if base_name not in used_filenames and full_path not in used_full_paths:
|
| 68 |
+
matching_images.append(img)
|
| 69 |
+
|
| 70 |
+
if not matching_images:
|
| 71 |
+
raise ValueError(f"No unused images found for answer: {answer}")
|
| 72 |
+
|
| 73 |
+
# Select a random image from matching ones
|
| 74 |
+
chosen_file = random.choice(matching_images)
|
| 75 |
+
return f"{image_dir}/{chosen_file}"
|
| 76 |
+
|
| 77 |
+
def extract_unique_questions(json_data: List[Dict]) -> Dict[str, Dict]:
|
| 78 |
+
"""
|
| 79 |
+
Extract unique questions from the JSON data where questions with different answers are considered different.
|
| 80 |
+
Saves the complete original question item for each unique question.
|
| 81 |
+
|
| 82 |
+
Args:
|
| 83 |
+
json_data (List[Dict]): List of dictionaries containing question data
|
| 84 |
+
|
| 85 |
+
Returns:
|
| 86 |
+
Dict[str, Dict]: Dictionary mapping unique questions to their complete original items
|
| 87 |
+
"""
|
| 88 |
+
unique_questions = {}
|
| 89 |
+
|
| 90 |
+
for item in json_data:
|
| 91 |
+
question = item['question']
|
| 92 |
+
answer = item['gt_answer']
|
| 93 |
+
|
| 94 |
+
# Create a key that combines question and answer to ensure uniqueness
|
| 95 |
+
key = f"{question}|{answer}"
|
| 96 |
+
|
| 97 |
+
if key not in unique_questions:
|
| 98 |
+
# Create a copy of the item to avoid modifying the original
|
| 99 |
+
new_item = item.copy()
|
| 100 |
+
# Replace the image path with a random one based on the answer
|
| 101 |
+
new_item['image_path'] = get_random_image_path(answer)
|
| 102 |
+
unique_questions[key] = new_item
|
| 103 |
+
|
| 104 |
+
return unique_questions
|
| 105 |
+
|
| 106 |
+
def extend_to_100_questions(unique_questions: Dict[str, Dict]) -> List[Dict]:
|
| 107 |
+
"""
|
| 108 |
+
Extend the number of questions to 100 by randomly duplicating existing questions.
|
| 109 |
+
|
| 110 |
+
Args:
|
| 111 |
+
unique_questions (Dict[str, Dict]): Dictionary of unique questions
|
| 112 |
+
|
| 113 |
+
Returns:
|
| 114 |
+
List[Dict]: List of 100 questions
|
| 115 |
+
"""
|
| 116 |
+
questions_list = list(unique_questions.values())
|
| 117 |
+
current_count = len(questions_list)
|
| 118 |
+
|
| 119 |
+
# If we already have more than 100 questions, just return the first 100
|
| 120 |
+
if current_count >= 50:
|
| 121 |
+
return questions_list#[:100]
|
| 122 |
+
|
| 123 |
+
# Calculate how many more questions we need
|
| 124 |
+
needed = 50 - current_count
|
| 125 |
+
|
| 126 |
+
# Randomly select questions to duplicate
|
| 127 |
+
for _ in range(needed):
|
| 128 |
+
# Select a random question
|
| 129 |
+
random_question = random.choice(questions_list)
|
| 130 |
+
# Create a copy of the question
|
| 131 |
+
new_question = random_question.copy()
|
| 132 |
+
# Generate a new random image path based on the answer
|
| 133 |
+
new_question['image_path'] = get_random_image_path(new_question['gt_answer'])
|
| 134 |
+
# Add to the list
|
| 135 |
+
questions_list.append(new_question)
|
| 136 |
+
|
| 137 |
+
return questions_list
|
| 138 |
+
|
| 139 |
+
def refill_question_ids(questions: List[Dict]) -> List[Dict]:
|
| 140 |
+
"""
|
| 141 |
+
Refill question_ids with sequential IDs.
|
| 142 |
+
|
| 143 |
+
Args:
|
| 144 |
+
questions (List[Dict]): List of questions
|
| 145 |
+
|
| 146 |
+
Returns:
|
| 147 |
+
List[Dict]: List of questions with sequential IDs
|
| 148 |
+
"""
|
| 149 |
+
for i, question in enumerate(questions):
|
| 150 |
+
# Format the ID with leading zeros to maintain 4 digits
|
| 151 |
+
question['question_id'] = f"PulmonaryChestMC_{i:04d}"
|
| 152 |
+
return questions
|
| 153 |
+
|
| 154 |
+
def main():
|
| 155 |
+
# Set random seed for reproducibility
|
| 156 |
+
random.seed(42)
|
| 157 |
+
|
| 158 |
+
# First convert all BMP images to png
|
| 159 |
+
# convert_bmp_to_png()
|
| 160 |
+
|
| 161 |
+
# Read the JSON file
|
| 162 |
+
with open('Original_open/RUS CHN.json', 'r') as f:
|
| 163 |
+
data = json.load(f)
|
| 164 |
+
|
| 165 |
+
# Print all unique answers
|
| 166 |
+
unique_answers = set(item['gt_answer'] for item in data)
|
| 167 |
+
print("\nUnique answers in the original file:")
|
| 168 |
+
for answer in sorted(unique_answers):
|
| 169 |
+
print(f"- {answer}")
|
| 170 |
+
print(f"\nTotal number of unique answers: {len(unique_answers)}")
|
| 171 |
+
|
| 172 |
+
# Extract unique questions
|
| 173 |
+
unique_questions = extract_unique_questions(data)
|
| 174 |
+
|
| 175 |
+
# Save the unique questions first
|
| 176 |
+
unique_questions_list = list(unique_questions.values())
|
| 177 |
+
with open('RUSCHN/ruschn_unique_questions_original.json', 'w') as f:
|
| 178 |
+
json.dump(unique_questions_list, f, indent=4)
|
| 179 |
+
print(f"\nOriginal unique questions have been saved to 'RUSCHN/ruschn_unique_questions_original.json'")
|
| 180 |
+
print(f"Number of unique questions: {len(unique_questions_list)}")
|
| 181 |
+
|
| 182 |
+
# Extend to 100 questions
|
| 183 |
+
extended_questions = extend_to_100_questions(unique_questions)
|
| 184 |
+
|
| 185 |
+
# Refill question IDs sequentially
|
| 186 |
+
final_questions = refill_question_ids(extended_questions)
|
| 187 |
+
|
| 188 |
+
# Save the extended questions to a new JSON file
|
| 189 |
+
with open('PulmonaryChestSZ/pulmonary_chest_sz_unique_questions.json', 'w') as f:
|
| 190 |
+
json.dump(final_questions, f, indent=4)
|
| 191 |
+
print(f"\nExtended questions have been saved to 'PulmonaryChestSZ/pulmonary_chest_sz_unique_questions.json'")
|
| 192 |
+
# print(f"Extended to {len(final_questions)} questions")
|
| 193 |
+
|
| 194 |
+
if __name__ == "__main__":
|
| 195 |
+
main()
|
RUSCHN/ruschn_unique_questions_original.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
RadImageNet/radiology_ai/CT/Airspace_opacity/lung058523.png
ADDED
|
Git LFS Details
|
RadImageNet/radiology_ai/CT/Airspace_opacity/lung058525.png
ADDED
|
Git LFS Details
|
RadImageNet/radiology_ai/CT/Airspace_opacity/lung058526.png
ADDED
|
Git LFS Details
|
RadImageNet/radiology_ai/CT/Airspace_opacity/lung058527.png
ADDED
|
Git LFS Details
|
RadImageNet/radiology_ai/CT/Airspace_opacity/lung058528.png
ADDED
|
Git LFS Details
|
RadImageNet/radiology_ai/CT/Airspace_opacity/lung058529.png
ADDED
|
Git LFS Details
|
RadImageNet/radiology_ai/CT/Airspace_opacity/lung058530.png
ADDED
|
Git LFS Details
|
RadImageNet/radiology_ai/CT/Airspace_opacity/lung058531.png
ADDED
|
Git LFS Details
|
RadImageNet/radiology_ai/CT/Airspace_opacity/lung058532.png
ADDED
|
Git LFS Details
|
RadImageNet/radiology_ai/CT/Airspace_opacity/lung058533.png
ADDED
|
Git LFS Details
|
RadImageNet/radiology_ai/CT/Airspace_opacity/lung058534.png
ADDED
|
Git LFS Details
|
RadImageNet/radiology_ai/CT/Airspace_opacity/lung058535.png
ADDED
|
Git LFS Details
|
RadImageNet/radiology_ai/CT/Airspace_opacity/lung058536.png
ADDED
|
Git LFS Details
|
RadImageNet/radiology_ai/MR/chondral_pathology/hip002863.png
ADDED
|
Git LFS Details
|
RadImageNet/radiology_ai/MR/chondral_pathology/hip002864.png
ADDED
|
Git LFS Details
|
RadImageNet/radiology_ai/MR/chondral_pathology/hip002865.png
ADDED
|
Git LFS Details
|
RadImageNet/radiology_ai/MR/chondral_pathology/hip002866.png
ADDED
|
Git LFS Details
|
RadImageNet/radiology_ai/MR/chondral_pathology/hip002867.png
ADDED
|
Git LFS Details
|
RadImageNet/radiology_ai/MR/chondral_pathology/hip002868.png
ADDED
|
Git LFS Details
|
RadImageNet/radiology_ai/MR/chondral_pathology/hip002869.png
ADDED
|
Git LFS Details
|
RadImageNet/radiology_ai/MR/chondral_pathology/hip002870.png
ADDED
|
Git LFS Details
|