예제 #1
0
def generate_pairs(path_pattern_imgs, path_pattern_lnds, mode):
    """ generate the registration pairs as reference and moving images

    :param str path_pattern_imgs: path to the images and image name pattern
    :param str path_pattern_lnds: path to the landmarks and its name pattern
    :param str mode: one of OPTIONS_COMBINE
    :return: DF
    """
    list_imgs = sorted(glob.glob(path_pattern_imgs))
    list_lnds = sorted(glob.glob(path_pattern_lnds))
    assert len(list_imgs) == len(list_lnds), \
        'the list of loaded images (%i) and landmarks (%i) is different length' \
        % (len(list_imgs), len(list_lnds))
    assert len(list_imgs) >= 2, 'the minimum is 2 elements'
    logging.info('combining list %i files with "%s"', len(list_imgs), mode)

    pairs = [(0, i) for i in range(1, len(list_imgs))]
    if mode == 'each2all':
        pairs += [(i, j) for i in range(1, len(list_imgs))
                  for j in range(i + 1, len(list_imgs))]

    reg_pairs = []
    for i, j in pairs:
        rec = dict(
            zip(ImRegBenchmark.COVER_COLUMNS,
                (list_imgs[i], list_imgs[j], list_lnds[i], list_lnds[j])))
        img_size, img_diag = image_sizes(rec[ImRegBenchmark.COL_IMAGE_REF])
        rec.update({
            ImRegBenchmark.COL_IMAGE_SIZE: img_size,
            ImRegBenchmark.COL_IMAGE_DIAGONAL: img_diag,
        })
        reg_pairs.append(rec)

    df_overview = pd.DataFrame(reg_pairs)
    return df_overview
예제 #2
0
파일: bm_DROP.py 프로젝트: phiwei/BIRL
    def _prepare_img_registration(self, item):
        """ converting the input images to gra-scale and MHD format

        :param dict dict item: dictionary with regist. params
        :return dict: the same or updated registration info
        """
        logging.debug('.. converting images to MHD')
        path_im_ref, path_im_move, _, _ = self._get_paths(item)
        path_reg_dir = self._get_path_reg_dir(item)

        diags = [
            image_sizes(p_img)[1] for p_img in (path_im_ref, path_im_move)
        ]
        item['scaling'] = max(1, max(diags) / float(self.MAX_IMAGE_DIAGONAL))

        t_start = time.time()
        for path_img, col in [(path_im_ref, self.COL_IMAGE_REF),
                              (path_im_move, self.COL_IMAGE_MOVE)]:
            item[col + self.COL_IMAGE_EXT_TEMP] = \
                convert_image_to_mhd(path_img, path_out_dir=path_reg_dir, overwrite=False,
                                     to_gray=True, scaling=item.get('scaling', 1.))
        item[self.COL_TIME_CONVERT] = time.time() - t_start

        # def __wrap_convert_mhd(path_img, col):
        #     path_img = convert_image_to_mhd(path_img, to_gray=True, overwrite=False)
        #     return path_img, col
        #
        # for path_img, col in iterate_mproc_map(__wrap_convert_mhd, convert_queue):
        #     item[col + COL_IMAGE_EXT_TEMP] = path_img

        return item
예제 #3
0
def generate_reg_pairs(rp_imgs,
                       rp_lnds,
                       pairs,
                       public,
                       path_images=DATASET_IMAGES):
    """ format a registration pair as dictionaries/rows in cover table for a set

    :param list(str) rp_imgs: relative paths to images
    :param rp_lnds: relative paths to related landmarks
    :param list(tuple(int,int)) pairs: pairing among images/landmarks
    :param list(bool) public: marks whether the particular pair is training or evaluation
    :param str path_images: path to the dataset folder
    :return list(dict): registration pairs
    """
    reg_pairs = []
    for k, (i, j) in enumerate(pairs):
        img_size, img_diag = image_sizes(
            update_path(rp_imgs[i], pre_path=path_images))
        reg_pairs.append({
            ImRegBenchmark.COL_IMAGE_REF:
            rp_imgs[i],
            ImRegBenchmark.COL_IMAGE_MOVE:
            rp_imgs[j],
            ImRegBenchmark.COL_POINTS_REF:
            rp_lnds[i],
            ImRegBenchmark.COL_POINTS_MOVE:
            rp_lnds[j],
            ImRegBenchmark.COL_STATUS:
            VAL_STATUS_TRAIN if public[k] else VAL_STATUS_TEST,
            ImRegBenchmark.COL_IMAGE_SIZE:
            img_size,
            ImRegBenchmark.COL_IMAGE_DIAGONAL:
            img_diag,
        })
    return reg_pairs
예제 #4
0
    def _image_diag(cls, item, path_img_ref=None):
        """ get the image diagonal from several sources
            1. diagonal exists in the table
            2. image size exist in the table
            3. reference image exists

        :param dict|DF item: one row from the table
        :param str path_img_ref: optional path to the reference image
        :return float|None: image diagonal
        """
        img_diag = dict(item).get(cls.COL_IMAGE_DIAGONAL)
        if not img_diag and path_img_ref and os.path.isfile(path_img_ref):
            _, img_diag = image_sizes(path_img_ref)
        return img_diag