Beispiel #1
0
def transform_drrs(checkpoint_dir,
                   drr_path,
                   patient_name,
                   model='mrcnn',
                   data_mode='shifted'):
    assert data_mode in ['standard', 'decorrelated']
    assert model in ['frcnn', 'mrcnn', 'siammask']

    load_path = drr_path + patient_name + '/DRRs/' + data_mode + '/'

    G_sr = get_sr_G([1, None, None, 1])
    G_dx = get_dx_G([1, 512, 512, 1], u_net_blocks=1, refine=False, name='g1')

    G_sr.load_weights(os.path.join(checkpoint_dir, 'g_sr.h5'))
    G_dx.load_weights(os.path.join(checkpoint_dir, 'g1_dx.h5'))
    G_sr.eval()
    G_dx.eval()

    for i in range(0, 1):
        # load data
        drr_dir = load_path + str(10 * i) + '-' + str(10 * (i + 1)) + '/'
        imgs_name = data_mode + '_drr_imgs'
        imgs = dtn.load_data(drr_dir + imgs_name + '.hdf5', imgs_name)

        c = 1 / np.log(1 + np.max(imgs, axis=(1, 2)))
        imgs = np.log(imgs + 1)
        imgs = np.multiply(c[..., np.newaxis, np.newaxis], imgs)
        imgs = (imgs - np.min(imgs)) / (np.max(imgs) - np.min(imgs))
        imgs = imgs * 2 - 1

        imgs = imgs[:, 128:-128, 256:-256]

        imgs_srgan = []
        imgs_cygan = []
        imgs_srcygan = []
        for j in range(imgs.shape[0]):
            print(j)
            sr_img = G_sr(imgs[j:j + 1][..., np.newaxis]).numpy()
            imgs_srgan.append(sr_img[..., 0])
        imgs_srgan = np.concatenate(imgs_srgan, axis=0)

        for j in range(imgs.shape[0]):
            print(j)
            dx_img = G_dx(imgs[j:j + 1][..., np.newaxis]).numpy()
            sr_dx_img = G_dx(imgs_srgan[j:j + 1][..., np.newaxis]).numpy()
            imgs_cygan.append(dx_img[..., 0])
            imgs_srcygan.append(sr_dx_img[..., 0])

        imgs_cygan = np.concatenate(imgs_cygan, axis=0)
        imgs_srcygan = np.concatenate(imgs_srcygan, axis=0)

        dtn.save_data(drr_dir, imgs_name + '_srgans', imgs_srgan)
        dtn.save_data(drr_dir, imgs_name + '_cygans', imgs_cygan)
        dtn.save_data(drr_dir, imgs_name + '_srcygans', imgs_srcygan)

        print(i)
Beispiel #2
0
    if crop > 0:
        if crop % 2 == 0:
            a_min = a_min + crop // 2
            a_max = a_max - crop // 2
        else:
            a_min = a_min + crop // 2 + 1
            a_max = a_max - crop // 2

    return a_min, a_max


# LOAD DATA

load_data_path = 'D:/MasterAIThesis/h5py_data/vumc patient data/'
patient_name = 'patient2'
imgs = dtn.load_data(
    load_data_path + patient_name + '/original_data/' + 'imgs.hdf5', 'imgs')
labs = dtn.load_data(
    load_data_path + patient_name + '/original_data/' + 'labs.hdf5', 'labs')

filename = load_data_path + patient_name + '/original_data/phase_0'
with h5py.File(filename, 'r') as f:
    body = np.array(f['BODY'], dtype='uint8')

imgs_r = imgs[..., :-16]
labs_r = labs[..., :-16]
body = body[..., :-16]

imgs_r = resize_all(imgs, 0.5)
labs_r = resize_all(labs, 0.5)
body_r = ct_resize(body, 0.8)
Beispiel #3
0
# GET DATASET
p_dict = ppd.prepare_p_dict(data_directory, roi_tags, not_roi_tags)
h5py_data_directory = 'D:/MasterAIThesis/h5py_data/vumc phantom data/'
dtn.create_cases(p_dict, h5py_data_directory)

base_name = "phase_"
dataset = load_dataset(h5py_data_directory, base_name)

save_dir = 'D:/MasterAIThesis/h5py_data/vumc phantom data/'
ppd.generate_patient_data(save_dir, dataset)



# LOAD DATA
load_data_path = 'D:/MasterAIThesis/h5py_data/vumc phantom data/phantom3/original_data/'
imgs = dtn.load_data(load_data_path + 'imgs.hdf5', 'imgs')
labs = dtn.load_data(load_data_path + 'labs.hdf5', 'labs')

save_data_path = 'D:/MasterAIThesis/h5py_data/vumc phantom data/phantom3/deformed_data/0-10/'
dtn.save_data(save_data_path, 'deformed_imgs', imgs)
dtn.save_data(save_data_path, 'deformed_labs', labs)


# LOAD MODEL

deformed_imgs = dtn.load_data(load_data_path + 'deformed_imgs.hdf5', 'deformed_imgs')
deformed_labs = dtn.load_data(load_data_path + 'deformed_labs.hdf5', 'deformed_labs')

shifted_imgs = dtn.load_data(load_data_path + 'shifted_imgs.hdf5', 'shifted_imgs')
shifted_labs = dtn.load_data(load_data_path + 'shifted_labs.hdf5', 'shifted_labs')
        FEATURES_SHAPE = [17, 17]
    


# SET UP CONFIG
config = TumorConfig()

data_path = 'D:/MasterAIThesis/h5py_data/vumc patient data/'
patient_name = 'patient2'
model = 'siammask'
data_mode = 'decorrelated'
drr_data_path = data_path + patient_name + '/models/'+ model + '/' + data_mode +'/dataset/'
# Directory to save logs and trained model
LOG_DIR =  data_path + patient_name + '/models/' + model + '/' + data_mode +'/logs/'

test_imgs = dtn.load_data(drr_data_path + 'test_imgs.hdf5', 'test_imgs')
test_labs = dtn.load_data(drr_data_path + 'test_labs.hdf5', 'test_labs')
for i in range(test_labs.shape[0]):
    for j in range(test_labs.shape[1]):
        test_labs[i, j] = fit_ellipse(test_labs[i, j])
        
test_imgs = (test_imgs+1)/2.



model = modellib.SiamMask(mode="inference", config=config,
                                      model_dir=LOG_DIR)

model.keras_model.summary()

weights_path = model.find_last()
    # load data
    f = h5py.File(data_path, "r")
    data = f[data_name][:]
    f.close()
    return data


xrays, drrs = [], []

drr_angles = np.arange(91, 451, 1)
data_path = 'D:/MasterAIThesis/h5py_data/vumc patient data/'
patient_name = 'patient1'
xray_data_path = data_path + patient_name + '/X_rays/'

# LOAD XRAYS
xrays1 = dtn.load_data(xray_data_path + 'tumor2.h5', 'img')
xrays1 = xrays1.astype('float32')
angles1 = dtn.load_data(xray_data_path + 'patient1_x_rays.h5', 'rot')
xrays2 = dtn.load_data(xray_data_path + 'tumor1.h5', 'img')
xrays2 = xrays2.astype('float32')
angles2 = dtn.load_data(xray_data_path + 'tumor1.h5', 'rot')

# LOAD DRRS
drr_data_path = data_path + patient_name + '/DRRs/'
drrs1 = load_data(drr_data_path + 'standard/0-10/' + 'standard_drr_imgs.hdf5',
                  'standard_drr_imgs')
drrs2 = load_data(drr_data_path + 'standard/10-20/' + 'standard_drr_imgs.hdf5',
                  'standard_drr_imgs')

indices = []
for a in drr_angles: