File size: 1,848 Bytes
911c613
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# ------------------------------------------------------------ #
#
# file : utils/learning/patch/reconstruction.py
# author : CM
# Function to reconstruct image from patch
#
# ------------------------------------------------------------

import numpy as np

# ----- Image Reconstruction -----
# Recreate the image from patchs
def fullPatchsToImage(image,patchs):
    i = 0
    for x in range(0,image.shape[0], patchs.shape[1]):
        for y in range(0, image.shape[1], patchs.shape[2]):
            for z in range(0,image.shape[2], patchs.shape[3]):
                image[x:x+patchs.shape[1],y:y+patchs.shape[2],z:z+patchs.shape[3]] = patchs[i,:,:,:,0]
                i = i+1
    return image

def fullPatchsPlusToImage(image,patchs, dx, dy, dz):
    div = np.zeros(image.shape)
    one = np.ones((patchs.shape[1],patchs.shape[2],patchs.shape[3]))

    i = 0
    for x in range(0,image.shape[0]-dx, dx):
        for y in range(0, image.shape[1]-dy, dy):
            for z in range(0,image.shape[2]-dz, dz):
                div[x:x+patchs.shape[1],y:y+patchs.shape[2],z:z+patchs.shape[3]] += one
                image[x:x+patchs.shape[1],y:y+patchs.shape[2],z:z+patchs.shape[3]] = patchs[i,:,:,:,0]
                i = i+1

    image = image/div

    return image

def dolzReconstruction(image,patchs):
    output = np.copy(image)

    count = 0

    print("image shape", image.shape)
    print("patchs shape", patchs.shape)

    # todo : change 16 with patch shape

    for x in range(0,image.shape[0], 16):
        for y in range(0, image.shape[1], 16):
            for z in range(0,image.shape[2], 16):
                patch = np.argmax(patchs[count], axis=1)
                patch = patch.reshape(16, 16, 16)
                output[x:x+patch.shape[0],y:y+patch.shape[1],z:z+patch.shape[2]] = patch
                count += 1

    return output