OpenKBP - 2020 AAPM Grand Challenge Forum

Go back to competition Back to thread list Post in this thread

> How to Visualise CT image from given datasets?

Is there any way to visualise images from given datasets?. is there any way to create more patients datasets?. is there any way to convert .CSV file into dicom format?

Posted by: anilrai @ April 16, 2020, 1:39 p.m.

We do not have any tools for visualization, but you can use the imshow function from the matplotlib.pyplot library to visualizes a slice from a dose distribution.

We will not be increasing or modifying the datasets in this competition.

Unfortunately we can only provide the CSV data, however, the provided data loader in our code repository will load the CSV files as 128x128x128 tensors in Python. We hope that the tensor format is close to the required format for most existing pipelines, but we also understand that many pipelines start with DICOM files.

Posted by: OpenKBP @ April 16, 2020, 2:05 p.m.

a demo code or files for explaining how to convert CT images to these csv files may be helpful for us.

Posted by: Mingqing @ April 17, 2020, 7:27 a.m.

You can lift the code from /provided_code/network_functions.py line 180 - 184 to save your own CT images. The code is designed for saving dose images, but it should be straightforward to adapt it for CT images. I provide and example below

# Prepare the dose to save
from provided_code.general_functions import sparse_vector_function
import pandas as pd

dose_pred_gy = np.squeeze(ct_image) # TODO: insert your CT image (tensor style)
dose_to_save = sparse_vector_function(dose_pred_gy)
dose_df = pd.DataFrame(data=dose_to_save['data'].squeeze(), index=dose_to_save['indices'].squeeze(),
columns=['data'])
dose_df.to_csv('{}/{}.csv'.format(directory_name, pat_id)) # TODO: insert the directory you'd like to save CT to, and the patient ID

Posted by: OpenKBP @ April 17, 2020, 1:38 p.m.

Also, on the topic of visualization here is some code for visualizing data using matplot lib. The CSVs are used to populate numpy arrays in the provided_code/data_loader.py on lines 183-199. I hope this is helpful!

# Import functions
from provided_code.general_functions import get_paths, load_file
import numpy as np
import matplotlib.pyplot as plt

# Load file
path_to_load = '/Users/aaronbabier/Academics/OpenKBP/CodaLab Template/train-validation-data/train-pats/pt_26/ct.csv'
loaded_ct = load_file(path_to_load) # TODO: insert the path to the CT image you'd like to load

# Load CT image as a 128x128x128 tensor
ct_img = np.zeros((128, 128, 128))
np.put(ct_img, loaded_ct['indices'], loaded_ct['data'])

# Convert to a black and white image (this step is very crude, and optional)
colour_mapping = plt.get_cmap('Greys')
ct_img_norm = ct_img / np.percentile(ct_img, 99.5) # Normalize the CT image to be between 0 and a number "close to one"
ct_img_clipped = np.clip(ct_img_norm, 0, 1) # clip all elements of CT to be between 0 and 1
ct_img = colour_mapping(ct_img_clipped)

# Visualize a slice
plt.imshow(ct_img[:, :, 64])
plt.savefig('ct_img.png')

Posted by: OpenKBP @ April 17, 2020, 1:39 p.m.
Post in this thread