Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoyi-wu authored Feb 23, 2024
1 parent b084c33 commit 98143b1
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Dataset/dataset/dicom_to_png_for_VinDR_sampled_using_mammo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
import cv2
import csv
import json
import imageio

import pandas as pd
import numpy as np
from tqdm import tqdm

import matplotlib.pyplot as plt
from pydicom import dcmread

def dcm_to_png(dcm_path,save_png_path):
ds = dcmread(dcm_path)
arr = ds.pixel_array
img_array = arr.copy()
cv2.normalize(arr, img_array, 0, 255, cv2.NORM_MINMAX)
img_array = np.array(img_array,dtype='uint8')
# img_array = cv2.resize(img_array, (512,512), interpolation = cv2.INTER_LINEAR)
imageio.imwrite(save_png_path,img_array)

def preprocess_csv(csv_path,data_dir,save_data_dir):
data_info = pd.read_csv(csv_path)
patient_file_list = data_info.iloc[:,0]
img_file_list = data_info.iloc[:,2]
for idx in tqdm(range(len(img_file_list))):
patient_file = patient_file_list[idx]
img_file = img_file_list[idx]
img_path = os.path.join(data_dir,str(patient_file),str(img_file)+'.dicom')
os.makedirs(os.path.join(save_data_dir,str(patient_file)), exist_ok=True)
save_img_path = os.path.join(save_data_dir,str(patient_file),str(img_file)+'.png')
dcm_to_png(img_path,save_img_path)


csv_path = './DATA/VinDr/VinDr-Mammo/1.0.0/breast-level_annotations.csv'
data_dir = './DATA/VinDr/VinDr-Mammo/1.0.0/images'
save_data_dir = './DATA/VinDr/VinDr-Mammo/process/images'
os.makedirs(save_data_dir, exist_ok=True)
preprocess_csv(csv_path,data_dir,save_data_dir)

0 comments on commit 98143b1

Please sign in to comment.