MyImage_class.py 文件源码

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

项目:DenoiseAverage 作者: Pella86 项目源码 文件源码
def rotate(self, deg, center = (0,0)):
        ''' rotates the image by set degree'''
        #where c is the cosine of the angle, s is the sine of the angle and
        #x0, y0 are used to correctly translate the rotated image.

        # size of source image
        src_dimsx = self.data.shape[0]
        src_dimsy = self.data.shape[1]

        # get the radians and calculate sin and cos
        rad = np.deg2rad(deg)
        c = np.cos(rad)
        s = np.sin(rad)

        # calculate center of image
        cx = center[0] + src_dimsx/2
        cy = center[1] + src_dimsy/2

        # factor that moves the index to the center
        x0 = cx - c*cx - s*cx
        y0 = cy - c*cy + s*cy

        # initialize destination image
        dest = MyImage(self.data.shape)
        for y in range(src_dimsy):
            for x in range(src_dimsx):
                # get the source indexes
                src_x = int(c*x + s*y + x0)
                src_y = int(-s*x + c*y + y0)
                if src_y > 0 and src_y < src_dimsy and src_x > 0 and src_x < src_dimsx:
                    #paste the value in the destination image
                    dest.data[x][y] = self.data[src_x][src_y]

        self.data = dest.data
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号