Example #1
0
# load config
with open(args.config) as f:
    config = yaml.safe_load(f)
data_list = config['list']
loader_config = config['loader']

loader_name = loader_config.pop('name')
data_loader = DataLoader(loader_name, **loader_config)
if data_list is not None:
    data_loader.set_data_list(data_list)

box = {
    'corner1': np.ones(3) * np.Inf,
    'corner2': np.zeros(3),
}
for data_idx in tqdm(data_loader.data_list):
    indices = np.where(data_loader.get_label(data_idx) > 0)
    corner1 = np.array([min(idx) for idx in indices])
    corner2 = np.array([max(idx) for idx in indices])
    box['corner1'] = np.minimum(box['corner1'], corner1)
    box['corner2'] = np.maximum(box['corner2'], corner2)
box['center'] = (box['corner2'] + box['corner1']) / 2
box['size'] = box['corner2'] - box['corner1']
for key in box:
    box[key] = box[key].tolist()
print('Bounding box:', box)
with open(args.output, 'w') as f:
    json.dump(box, f, indent=2)
print('has been saved to', args.output)
Example #2
0
    help='loader config'
)
args = parser.parse_args()

with open(args.loader_config) as f:
    loader_config = yaml.safe_load(f)

loader_name = loader_config.pop('name')
data_loader = DataLoader(loader_name, **loader_config)

assert len(data_loader.data_list) > 0
idx = data_loader.data_list[0]

images = [
    data_loader.get_image(idx),
    data_loader.get_label(idx)
]

idx_containing_ROI = np.where(images[1] != 0)[2][0]

fig, axes = plt.subplots(
    1,
    len(images),
    constrained_layout=True,
    figsize=(10, 5)
)

if len(images) == 1:
    axes = [axes]

images_slicer = ImagesSlicer(axes, images, idx=idx_containing_ROI)
#!/usr/bin/env python3

from MIDP import DataLoader
import argparse
import yaml
from tqdm import tqdm

parser = argparse.ArgumentParser()
parser.add_argument('--loader-config', required=True, help='loader config')
parser.add_argument('--output-dir', default='output', help='output dir')
args = parser.parse_args()

with open(args.loader_config) as f:
    loader_config = yaml.safe_load(f)

loader_name = loader_config.pop('name')
data_loader = DataLoader(loader_name, **loader_config)

for data_idx in tqdm(data_loader.data_list):
    label = data_loader.get_label(data_idx)
    data_loader.save_prediction(data_idx, label, args.output_dir)