def process_data_hdf5():
    contour_paths = [tr_contour_path, val_contour_path, onl_contour_path]
    image_paths = [tr_img_path, val_img_path, onl_img_path]
    all_data = []

    for contour_path, img_path in zip(contour_paths, image_paths):
        train_ctrs = get_all_contours(contour_path)
        imgs,labels = process_contours(train_ctrs, img_path)
        all_data.append([imgs,labels])

    # add in manually segmented images, labels in {0,1}
    aug_contour_path = os.path.join(c.data_manual, 'manual_contours', 'contours')
    aug_image_path = os.path.join(c.data_manual, 'manual_contours', 'images')
    for cfn in [fn_ for fn_ in os.listdir(aug_contour_path) if fn_ in 'jpg']:
        if 'auto' in cfn:
            continue
        dcm_img = cv2.imread(os.path.join(aug_image_path, cfn), 0)
        dcm_img = cv2.resize(dcm_img, (img_size, img_size)).reshape(1, 1, img_size, img_size)
        contour_img = cv2.imread(os.path.join(aug_contour_path, cfn), 0)
        contour_img = cv2.resize(contour_img, (img_size, img_size))
        _,contour_img = cv2.threshold(contour_img, 127, 255,cv2.THRESH_BINARY_INV)
        contour_img = contour_img.reshape(1, 1, img_size, img_size) / 255
        all_data.append([dcm_img, contour_img])

    ##add in no contour images!!
    with open(os.path.join(c.data_manual, 'nocontour_tencia.csv')) as f:
        label = np.zeros((1,1,img_size,img_size), dtype=np.uint8);
        for l in f:
            row = [int(x) for x in l.split(',')];
            case = row[0];
            s = row[1::2];
            t = row[2::2];
            assert(len(s)==len(t));
            dset = du.CNN_Dataset(case, img_size=img_size)
            n = len(s);
            print("add case {} no contour imgs".format(case))
            for i in range(n):
                img = dset.images[s[i],t[i],0].reshape(1,1,img_size,img_size)
                all_data.append([img,label])

    np.random.shuffle(all_data)

    all_imgs = np.concatenate([a[0] for a in all_data], axis=0)
    all_labels = np.concatenate([a[1] for a in all_data], axis=0)

    n = all_imgs.shape[0]
    fn = os.path.join(c.data_intermediate, 'scd_seg_{}.hdf5'.format(img_size))
    if os.path.exists(fn):
        os.remove(fn)
    u.save_hd5py({'images': all_imgs, 'labels': all_labels}, fn, 5)
dataset/ETHPy150Open woshialex/diagnose-heart/CNN_B/sunnybrook.py/process_data_hdf5/swapped operands of `in`