kernel.py 文件源码

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

项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码
def center_aniano(self):

        """
        This function ...
        :return:
        """

        # Debugging
        log.debug("Centering the kernel ...")

        # FROM CONVOLVE_IMAGE.PRO (G. Aniano)

        center_x = int(0.5 * (self.xsize - 1))
        center_y = int(0.5 * (self.ysize - 1))

        # get_maximun,image,x_max,y_max

        x_max, y_max = self.get_maximum()

        # ; determine the needed shifts
        shift_x = center_x - x_max
        shift_y = center_y - y_max

        # ; make the shift if nonzero
        if (shift_x != 0) or (shift_y != 0):

            # Debugging
            log.debug("Shifting the kernel center by (" + str(shift_x) + ", " + str(shift_y) + " pixels ...")

            self._data = shift(self._data, [shift_x,shift_y])

            # Y
            self._data[:abs(shift_y),:] = 0.0
            self._data[self.ysize-1-abs(shift_y):self.ysize,:] = 0.0

            # X
            self._data[:,:abs(shift_x)] = 0.0
            self._data[:,self.xsize-1-abs(shift_x):] = 0.0

        # CHECK

        # Calculate shift again
        x_max, y_max = self.get_maximum()
        new_shift_x = center_x - x_max
        new_shift_y = center_y - y_max

        # Raise exception if there is still a shift
        if (new_shift_x != 0) or (new_shift_y != 0): raise RuntimeError("Something went wrong during the kernel centering: "
                                                                "new shift x = " + str(new_shift_x) + ", new shift y = "
                                                                + str(new_shift_y) + " (previous shift x = " + str(shift_x)
                                                                        + ", previous shift y = " + str(shift_y))

    # -----------------------------------------------------------------
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号