Beispiel #1
0
def to_img(input: torch.Tensor, mode: str, colormap=True, normalize=True):
    if (mode == "2D"):
        img = input[0].clone().detach()
        if (normalize):
            img -= img.min()
            img *= (1 / img.max() + 1e-6)
        if (colormap and img.shape[0] == 1):
            img = cm.coolwarm(img[0].cpu().numpy())
            #img = np.transpose(img, (2, 0, 1))
            img = (255 * img).astype(np.uint8)
        else:
            img *= 255
            img = img.permute(1, 2, 0).cpu().numpy().astype(np.uint8)
    elif (mode == "3D"):
        img = input[0, :, :, :, int(input.shape[4] / 2)].clone()
        if (normalize):
            img -= img.min()
            img *= (1 / img.max() + 1e-6)
        if (colormap and img.shape[0] == 1):
            img = cm.coolwarm(img[0].cpu().numpy())
            #img = np.transpose(img, (2, 0, 1))
            img = (255 * img).astype(np.uint8)
        else:
            img *= 255
            img = img.permute(1, 2, 0).cpu().numpy().astype(np.uint8)
    #print(img.shape)
    return img
Beispiel #2
0
def toImg(vectorField, renorm_channels = False):
    vf = vectorField.copy()
    if(len(vf.shape) == 3):
        if(vf.shape[0] == 1):
            return cm.coolwarm(vf[0]).swapaxes(0,2).swapaxes(1,2)
        elif(vf.shape[0] == 2):
            vf += 1
            vf *= 0.5
            vf = vf.clip(0, 1)
            z = np.zeros([1, vf.shape[1], vf.shape[2]])
            vf = np.concatenate([vf, z])
            return vf
        elif(vf.shape[0] == 3):
            if(renorm_channels):
                for j in range(vf.shape[0]):
                    vf[j] -= vf[j].min()
                    vf[j] *= (1 / vf[j].max())
            return vf
    elif(len(vf.shape) == 4):
        return toImg(vf[:,:,:,0], renorm_channels)
Beispiel #3
0
from matplotlib.pyplot import cm

#Plotting
figure=plt.figure()
axes = figure.add_axes([0.1,0.1,1.2,1.2])
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)

# Data
G=1
J=1
tau=np.array([0.1, 1, 2, 5, 10, 50, 100, 500]);
N = 500 #number of points
L = np.linspace(0,100, N)

color=iter(cm.coolwarm(np.linspace(0,1,np.size(tau))))

for i in range(0,np.size(tau)):     
    c=next(color)
    n= J / G * np.exp(-L/G/tau[i])
    axes.plot(L,n, marker=' ' , c=c)    
    
plt.title('n(L) vs. residence time', fontsize=18);
axes.set_xlabel('$L$', fontsize=18);
axes.set_ylabel('$n$',fontsize=18);

#########################################################
# Plotting
figure=plt.figure()
axes = figure.add_axes([0.1,0.1,1.2,1.2])
plt.xticks(fontsize=14)