keypoint.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:AlphaLogo 作者: gigaflw 项目源码 文件源码
def _find_DoG_extrema(self, DoG):
        # TODO: sample ?
        ext = []
        for octave in DoG:
            _, rows, cols = octave.shape
            # assert octave.shape = (<layers>(=s+2), <rows>, <columns>)

            ##########################
            # time ?
            ##########################
            peeled = [octave[ind1, ind2, ind3] for ind1, ind2, ind3 in
                      product(*[[slice(1, -1), slice(2, None), slice(None, -2)]]*3)]
            center_block = peeled[0]  # octave[1:-1,1:-1,1:-1], the center part
            neighbor_blocks = peeled[1:]  # neighbors in 26 directions in 3-D DoG space with offset 1
            is_extreme = \
                np.bitwise_or(center_block > (np.max(neighbor_blocks, axis=0)),
                              center_block < (np.min(neighbor_blocks, axis=0)))
            # assert is_extreme.shape = (s, rows-2, columns-2)

            ext_coord = np.array(
                list(product(*[range(1, i-1) for i in octave.shape]))).reshape([x-2 for x in octave.shape]+[-1])
            assert ext_coord.shape[:-1] == is_extreme.shape

            ext_coord = ext_coord[is_extreme].astype(np.float)
            print("%d key point candidates found" % ext_coord.shape[0])
            # assert ext_coord.shape = (<number of key points>, 3)
            ext_coord /= [1, rows, cols]   # convert row, col coord to relative
            ext_coord[:, 0] = get_sigma_by_layer(ext_coord[:, 0])

            ext.extend(list(ext_coord))

            # filters
            # for layer, row, col in ext_coord:
            # nb = octave[layer-1:layer+2, row-1:row+2, col-1:col+2]  # 3x3x3 neighbor
            # x_hat, d_x_hat = self._fit_extremum(nb)
            # if
            # TODO: if x[i] > 0.5, do it recursivey
            # print(x_hat, d_x_hat)

        return ext
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号