File size: 1,672 Bytes
ecf08bc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
from skimage import io
import cv2
import matplotlib.pyplot as plt
import numpy as np
from batchgenerators.utilities.file_and_folder_operations import *
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-data_path",
help="percentage of the dataset used for training validation and test")
args = parser.parse_args()
data_path = args.data_path
output_path = join(data_path, 'boundaries_dilated_5')
train_data_path = join(data_path, 'boundaries', 'train')
test_data_path = join(data_path,'boundaries', 'test')
train_output_path = join(output_path, 'train')
test_output_path = join(output_path, 'test')
maybe_mkdir_p(output_path)
maybe_mkdir_p(train_output_path)
maybe_mkdir_p(test_output_path)
kernel = np.ones((5, 5), 'uint8')
# Train
for train_file in os.listdir(train_data_path):
print(train_file)
# load image
file_path = join(train_data_path, train_file)
front = io.imread(file_path)
# dilate boundary
boundary_dil = cv2.dilate(front, kernel)
# store image
output_file_path = join(train_output_path, train_file)
io.imsave(output_file_path, boundary_dil)
# Test
for test_file in os.listdir(test_data_path):
print(test_file)
# load image
file_path = join(test_data_path, test_file)
front = io.imread(file_path)
# dilate front
boundary_dil = cv2.dilate(front, kernel)
# store image
output_file_path = join(test_output_path, test_file)
io.imsave(output_file_path, boundary_dil) |