Dear Niels van Nistelrooij,
Thank you very much for your inquiry. We simply add columns and rows of zeros so that you can easily apply unpadding with the provided image height and widths in the tables. In the DENTEX repository, you can find a list of dictionaries containing the widths and heights, along with the file names and image IDs in the process.py
file within the docker image codes. Below is the function we used to add the paddings:
def create_mha_from_rgb_images(images, output_path):
# Find the dimensions of the largest image
max_height = max(img.shape[0] for img in images)
max_width = max(img.shape[1] for img in images)
# Create an empty 3D array to hold the RGB images
stacked_image = np.zeros((max_height, max_width, len(images), 3), dtype=np.uint8)
# Copy each RGB image into the corresponding layer of the 3D array
for i, img in enumerate(images):
# Zero-pad the image if necessary
padded_img = np.pad(img, ((0, max_height - img.shape[0]), (0, max_width - img.shape[1]), (0, 0)), mode='constant')
# Assign the padded image to the appropriate layer
stacked_image[:, :, i, :] = padded_img
# Convert the array to SimpleITK image format
sitk_image = sitk.GetImageFromArray(stacked_image)
# Set the pixel type and origin
sitk_image.SetOrigin((0.0, 0.0, 0.0))
# Save the image as .mha file
sitk.WriteImage(sitk_image, output_path)
Ideally, the model should not predict bounding boxes (or segmentation masks in your case) in the zero-padding regions. Therefore, unpadding may not be necessary. In fact, we did not perform unpadding in the baseline model docker, and it appears to work fine.
Sincerely,
Sezgin