utils.py 文件源码

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

项目:Defect-Prediction 作者: Jorba123 项目源码 文件源码
def translate_image(image, translationMatrix):
    """ Translates the image given a translation matrix."""

    # which image shape? (ConvNet (3, w, h) vs. Normal (w, h, 3)
    reshape = False
    prevShape = image.shape
    if image.shape[0] == 3 or image.shape[0] == 1:
        reshape = True
        if image.shape[0] == image.shape[1] or (image.shape[0] == 1 and image.shape[1] == 3): # grayscale 1L, 1L, h, w OR color 1L, 3L, h, w
            reshapeVector = (image.shape[2], image.shape[3], image.shape[1])         
        else:                      
            reshapeVector = (image.shape[1], image.shape[2], image.shape[0])                    # single row color or grayscale 1L/3L, h, w
        image = image.reshape(reshapeVector)

    h, w = image.shape[0], image.shape[1]
    image = cv.warpAffine(image, translationMatrix, (w, h))

    if reshape:        
        image = image.reshape(prevShape)
    return image
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号