从12通道小图像到3通道大图像张量流分配值

时间:2018-12-06 20:11:13

标签: python tensorflow

我有一个12通道的小图像,其值必须分配给3通道的大图像(请找到下面的代码)。

大图像的高度=小图像的高度* 2

大图像的宽度=小图像的宽度* 2

我已经在numpy库中编写了一个对我来说很好的函数。我想知道如何使用张量流实现相同的功能。还想知道是否有api的功能与我在tensorflow中的功能相同。

def reconstruct_image(image):
    image=np.array(image)
    M=image.shape[0]
    N=image.shape[1]
    img = np.zeros((M* 2, N* 2,3))

    # For red channel
    img[0:2*M:2,0:2*N:2,0]=image[:,:,0]
    img[0:2*M:2,1:2*N:2,0]=image[:,:,1]
    img[1:2*M:2,0:2*N:2,0]=image[:,:,2]
    img[1:2*M:2,1:2*N:2,0]=image[:,:,3]
    #For green channel
    img[0:2*M:2, 0:2*N:2,1] = image[:,:,4]
    img[0:2*M:2, 1:2*N:2,1] = image[:,:,5]
    img[1:2*M:2, 0:2*N:2,1] = image[:,:,6]
    img[1:2*M:2, 1:2*N:2,1] = image[:,:,7]
    img[0:2*M:2, 0:2*N:2,2] = image[:,:,8]
    #For blue channel
    img[0:2*M:2, 1:2*N:2,2] = image[:,:,9]
    img[1:2*M:2, 0:2*N:2,2] = image[:,:,10]
    img[1:2*M:2, 1:2*N:2,2] = image[:,:,11]

    return img

感谢任何提示或帮助。

谢谢。

0 个答案:

没有答案