def process_dataset(args, num_tries=3): """ pre process and registrate volume""" # pylint: disable= unused-argument moving_image_id = args[0] print(moving_image_id) conn = sqlite3.connect(util.DB_PATH) conn.text_factory = str cursor = conn.execute('''SELECT pid from Images where id = ?''', (moving_image_id,)) pid = cursor.fetchone()[0] cursor = conn.execute('''SELECT id from Images where pid = ? AND diag_pre_post = ?''', (pid, "pre")) db_temp = cursor.fetchone() pre_image_id = db_temp[0] cursor.close() 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
def _test_be(moving_image_id, reg): img = image_registration.img_data(moving_image_id, util.DATA_FOLDER, util.TEMP_FOLDER_PATH) img = image_registration.pre_process(img, False) resampled_file = img.pre_processed_filepath name = splitext(splitext(basename(resampled_file))[0])[0] + "_bet" img.pre_processed_filepath = util.TEMP_FOLDER_PATH + "/res/" +\ splitext(basename(resampled_file))[0] +\ '_bet.nii.gz' reg.inputs.fixed_image = resampled_file reg.inputs.fixed_image_mask = img.label_inv_filepath reg.inputs.output_transform_prefix = util.TEMP_FOLDER_PATH + name reg.inputs.output_warped_image = util.TEMP_FOLDER_PATH + name + '_betReg.nii' transform = util.TEMP_FOLDER_PATH + name + 'InverseComposite.h5' reg.run() img.init_transform = transform reg_volume = util.transform_volume(resampled_file, transform) mult = ants.MultiplyImages() mult.inputs.dimension = 3 mult.inputs.first_input = reg_volume mult.inputs.second_input = image_registration.TEMPLATE_MASK mult.inputs.output_product_image = img.pre_processed_filepath mult.run() util.generate_image(img.pre_processed_filepath, image_registration.TEMPLATE_VOLUME)
def process_dataset(args, num_tries=3): """ pre process and registrate volume""" # pylint: disable= unused-argument (moving_image_id, _, save_to_db, _) = args print(moving_image_id) conn = sqlite3.connect(util.DB_PATH) conn.text_factory = str cursor = conn.execute('''SELECT pid from Images where id = ?''', (moving_image_id, )) pid = cursor.fetchone()[0] cursor = conn.execute( '''SELECT id from Images where pid = ? AND diag_pre_post = ?''', (pid, "pre")) db_temp = cursor.fetchone() pre_image_id = db_temp[0] cursor.close() conn.close() 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) 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])