|
import os |
|
import json |
|
|
|
def process_json_file(file_path): |
|
|
|
with open(file_path, 'r') as file: |
|
data = json.load(file) |
|
|
|
|
|
desired_keys = ["PatientAge", "PatientSex", "Manufacturer", "RescaleIntercept", "RescaleSlope"] |
|
cleaned_data = {key: data[key] for key in desired_keys if key in data} |
|
|
|
|
|
with open(file_path, 'w') as file: |
|
json.dump(cleaned_data, file, indent=4) |
|
|
|
def scan_folder(folder_path): |
|
for root, dirs, files in os.walk(folder_path): |
|
for file in files: |
|
if file.endswith('.json'): |
|
file_path = os.path.join(root, file) |
|
process_json_file(file_path) |
|
|
|
|
|
folder_path = 'ctvit-transformer' |
|
scan_folder(folder_path) |
|
|