コード例 #1
0
# pylint: disable= invalid-name
if __name__ == "__main__":  # if 'unity' in hostname or 'compute' in hostname:
    HOSTNAME = os.uname()[1]
    if 'unity' in HOSTNAME or 'compute' in HOSTNAME:
        path = "/work/danieli/GBM_survival/"
    else:
        os.nice(19)
        path = "GBM_" + "{:%m_%d_%Y}".format(datetime.datetime.now()) + "/"

    util.setup(path)

    #image_ids, survival_days = util.get_image_id_and_survival_days(study_id="GBM_survival_time", registration_date_upper_lim="2018-10-29")
    #image_ids = [10]
    #image_ids = [10, 19, 35, 371, 71, 83,98, 103, 106, 116, 231, 392, 458]
    #image_ids = [10, 19, 71, 83, 98, 103, 106, 116, 231, 392, 458]
    #image_ids = range(454,465)
    #image_ids = [413, 386, 398, 406, 416, 420, 419, 392, 412, 408, 405, 407]
    image_ids = [75, 465, 125, 126, 183, 377, 220]
    #image_ids = [413]

    util.LOGGER.info(str(image_ids) + " " + str(len(image_ids)))
    image_registration.get_transforms(
        image_ids,
        #reg_type=image_registration.RIGID,
        #save_to_db=True,
        #reg_type_be=image_registration.SIMILARITY)
        reg_type=image_registration.SYN,
        reg_type_be=image_registration.SIMILARITY,
        save_to_db=True)
コード例 #2
0

def find_images():
    """ Find images for registration """
    conn = sqlite3.connect(util.DB_PATH)
    conn.text_factory = str
    cursor = conn.execute('''SELECT pid from Patient''')
    ids = []
    for row in cursor:
        cursor2 = conn.execute('''SELECT id from Images where pid = ?''', (row[0], ))
        for _id in cursor2:
            ids.append(_id[0])
        cursor2.close()

    cursor.close()
    conn.close()
    print(ids)
    return ids


# pylint: disable= invalid-name
if __name__ == "__main__":
    os.nice(19)
    util.setup("GBM/")

    moving_datasets_ids = find_images()

    data_transforms = image_registration.get_transforms(moving_datasets_ids, image_registration.SYN)

#    image_registration.save_transform_to_database(data_transforms)
コード例 #3
0
        path = "MM_TEMP_" + "{:%m_%d_%Y}_BE2".format(
            datetime.datetime.now()) + "/"

    util.setup(path, "MolekylareMarkorer")
    #
    # util.prepare_template(datasets.fetch_icbm152_2009(data_dir="./").get("t2"), util.TEMPLATE_MASK, True)
    # moving_datasets_ids = find_images_from_pid([164])
    # print(moving_datasets_ids, len(moving_datasets_ids))
    # data_transforms = image_registration.get_transforms(moving_datasets_ids,
    #                                                     image_registration.AFFINE,
    #                                                     save_to_db=True)

    util.prepare_template(
        datasets.fetch_icbm152_2009(data_dir="./").get("t2"),
        util.TEMPLATE_MASK, True)
    moving_datasets_ids = find_images_from_pid([125, 2101])
    print(moving_datasets_ids, len(moving_datasets_ids))
    data_transforms = image_registration.get_transforms(
        moving_datasets_ids, image_registration.AFFINE, save_to_db=True)

    # moving_datasets_ids = find_images_from_pid([172])
    # print(moving_datasets_ids, len(moving_datasets_ids))
    # data_transforms = image_registration.get_transforms(moving_datasets_ids,
    #                                                     image_registration.RIGID,
    #                                                     save_to_db=True)

    # print(moving_datasets_ids_affine, len(moving_datasets_ids_affine))
    # data_transforms = image_registration.get_transforms(moving_datasets_ids_affine,
    #                                                     image_registration.RIGID,
    #                                                     save_to_db=True, be_method=0)
コード例 #4
0
    post_img.fixed_image = pre_image_id

    pre_img = image_registration.pre_process(pre_img, False)
    post_img = image_registration.pre_process(post_img, False)
    img = image_registration.registration(post_img,
                                          pre_img.pre_processed_filepath,
                                          image_registration.RIGID)
    print("\n\n\n\n -- Total run time: ")
    print(datetime.datetime.now() - start_time)
    img.fixed_image = pre_image_id

    if save_to_db:
        image_registration.save_transform_to_database([img])


if __name__ == "__main__":
    os.nice(19)
    HOSTNAME = os.uname()[1]
    if 'unity' in HOSTNAME or 'compute' in HOSTNAME:
        path = "/work/danieli/LGG_POST/"
    else:
        path = "LGG_POST_" + "{:%m_%d_%Y}".format(
            datetime.datetime.now()) + "/"

    util.setup(path)

    post_images = find_images()
    image_registration.get_transforms(post_images,
                                      process_dataset_func=process_dataset,
                                      save_to_db=True)
コード例 #5
0
    if 'unity' in HOSTNAME or 'compute' in HOSTNAME:
        path = "/work/danieli/GBM_survival/"
    else:
        os.nice(19)
        path = "GBM_" + "{:%m_%d_%Y}".format(datetime.datetime.now()) + "/"

    util.setup(path)

    (image_ids, survival_days) = util.get_image_id_and_survival_days(exclude_pid=[186], glioma_grades=[4])

    if len(sys.argv) > 2:
        # from mpi4py import MPI
        # comm = MPI.COMM_WORLD
        # split = comm.Get_rank()
        # num_of_splits = comm.Get_size()

        num_of_splits = int(sys.argv[1])
        split = int(sys.argv[2])

        length = int(len(image_ids) / num_of_splits)
        start_idx = length * (split - 1)
        if split < num_of_splits:
            image_ids = image_ids[start_idx:(start_idx+length)]
        else:
            image_ids = image_ids[start_idx:]

    util.LOGGER.info(str(image_ids) + " " + str(len(image_ids)))
    image_registration.get_transforms(image_ids,
                                      image_registration.RIGID,
                                      save_to_db=True)
コード例 #6
0
            registration_date = cursor3.fetchone()[0]
            cursor3.close()
            if registration_date:
                continue
            ids.append(_id)

        cursor2.close()

    cursor.close()
    conn.close()
    return ids


# pylint: disable= invalid-name
if __name__ == "__main__":
    os.nice(17)
    HOSTNAME = os.uname()[1]
    if 'unity' in HOSTNAME or 'compute' in HOSTNAME:
        path = "/work/danieli/tumor_reg/"
    else:
        path = "tumor_reg_" + "{:%m_%d_%Y}".format(datetime.datetime.now()) + "/"

    util.setup(path)

    moving_datasets_ids = find_images()
    print(moving_datasets_ids, len(moving_datasets_ids))
    image_registration.get_transforms(moving_datasets_ids,
                                      image_registration.SYN,
                                      save_to_db=True)

def find_images():
    """ Find images for registration """
    conn = sqlite3.connect(util.DB_PATH)
    conn.text_factory = str
    cursor = conn.execute('''SELECT pid from Patient''')
    ids = []
    for row in cursor:
        cursor2 = conn.execute('''SELECT id from Images where pid = ? AND diag_pre_post = ?''',
                               (row[0], "pre"))
        for _id in cursor2:
            ids.append(_id[0])
        cursor2.close()

    cursor.close()
    conn.close()
    return ids


# pylint: disable= invalid-name
if __name__ == "__main__":
    os.nice(19)
    util.setup("LGG_PRE/")

    pre_images = find_images()

    data_transforms = image_registration.get_transforms(pre_images, image_registration.SYN)

#    image_registration.save_transform_to_database(data_transforms)
    conn.close()

    import datetime
    start_time = datetime.datetime.now()
    pre_img = img_data(pre_image_id, util.DATA_FOLDER, util.TEMP_FOLDER_PATH)
    post_img = img_data(moving_image_id, util.DATA_FOLDER, util.TEMP_FOLDER_PATH)

    pre_img = image_registration.pre_process(pre_img, False)
    post_img = image_registration.pre_process(post_img, False)
    img = image_registration.registration(post_img, pre_img.pre_processed_filepath,
                                          image_registration.RIGID)
    print("\n\n\n\n -- Total run time: ")
    print(datetime.datetime.now() - start_time)

    img.fixed_image = pre_image_id

    return img


# pylint: disable= invalid-name
if __name__ == "__main__":
    os.nice(19)
    util.setup("LGG_POST/")

    post_images = find_images()
    data_transforms = image_registration.get_transforms(post_images,
                                                        process_dataset_func=process_dataset,
                                                        save_to_db=True)

#    image_registration.save_transform_to_database(data_transforms)
コード例 #9
0
    cursor = conn.execute('''SELECT pid from Patient''')
    ids = []
    for row in cursor:
        pid = row[0]
        if pid not in pids_with_qol:
            continue
        cursor2 = conn.execute('''SELECT id from Images where pid = ? AND diag_pre_post = ?''',
                               (pid, "pre"))

        for _id in cursor2:
            ids.append(_id[0])
        cursor2.close()

    cursor.close()
    conn.close()
    return ids


# pylint: disable= invalid-name
if __name__ == "__main__":
    os.nice(17)
    util.setup("GBM_LGG_TEMP_" + "{:%m_%d_%Y}_BE2".format(datetime.datetime.now()) + "/")

    moving_datasets_ids = find_images()
    print(moving_datasets_ids, len(moving_datasets_ids))
    data_transforms = image_registration.get_transforms(moving_datasets_ids,
                                                        image_registration.RIGID,
                                                        save_to_db=True)

    # image_registration.save_transform_to_database(data_transforms)
コード例 #10
0
        split = int(sys.argv[2])

        length = int(len(moving_datasets_ids) / num_of_splits)
        start_idx = length * (split - 1)
        if split < num_of_splits:
            moving_datasets_ids = moving_datasets_ids[start_idx:(start_idx +
                                                                 length)]
        else:
            moving_datasets_ids = moving_datasets_ids[start_idx:]

    util.LOGGER.info(
        str(moving_datasets_ids) + " " + str(len(moving_datasets_ids)))
    image_registration.BET_FRAC = 0.2
    image_registration.get_transforms(
        moving_datasets_ids,
        reg_type=image_registration.COMPOSITEAFFINE,
        reg_type_be=image_registration.COMPOSITEAFFINE,
        save_to_db=True)

    # moving_datasets_ids = find_images([1052, 1167, 1, 31, 35, 192, 201, 388, 397, 463, 508, 530, 563, 709, 866, 927, 941, 981, 1020])
    # #excluded: 1061, 709
    # print(moving_datasets_ids)
    # image_registration.get_transforms(moving_datasets_ids,
    #                                   image_registration.AFFINE,
    #                                   reg_type_be=image_registration.COMPOSITEAFFINE,
    #                                   save_to_db=True)

# 192, 201, 35, 463. 709, 1020
# 1, 35, 105, 192, 201, 463, 508, 530, 563, 709, 866, 1020, 1061,  image_registration.BET_FRAC = 0.1
# 1, 35,      192, 201, 463, 508, 530, 709, 866, 1020, 1061,  image_registration.BET_FRAC = 0.3
# 508, 866,
コード例 #11
0

def find_images():
    """ Find images for registration """
    conn = sqlite3.connect(util.DB_PATH)
    conn.text_factory = str
    cursor = conn.execute('''SELECT pid from Patient''')
    ids = []
    for row in cursor:
        cursor2 = conn.execute(
            '''SELECT id from Images where pid = ? AND diag_pre_post = ?''',
            (row[0], "pre"))
        for _id in cursor2:
            ids.append(_id[0])
        cursor2.close()

    cursor.close()
    conn.close()
    return ids


# pylint: disable= invalid-name
if __name__ == "__main__":
    os.nice(19)
    util.setup("LGG_PRE/")

    pre_images = find_images()
    image_registration.get_transforms(pre_images,
                                      image_registration.SYN,
                                      save_to_db=True)