Ejemplo n.º 1
0
obj3D_2 = {
    'Obj': Objects3D.CUBOID,
    'C0': 1.00,
    'x0': 0.1,
    'y0': 0.2,
    'z0': 0.0,
    'a': 0.15,
    'b': 0.35,
    'c': 0.6,
    'phi1': -60.0
}

print("Building 3D object using TomoPhantom software")
myObjects = [obj3D_1, obj3D_2]  # dictionary of objects
Object3D = TomoP3D.Object(N3D_size, myObjects)

sliceSel = int(0.5 * N3D_size)
#plt.gray()
plt.figure()
plt.subplot(131)
plt.imshow(Object3D[sliceSel, :, :], vmin=0, vmax=1)
plt.title('3D Object, axial view')

plt.subplot(132)
plt.imshow(Object3D[:, sliceSel, :], vmin=0, vmax=1)
plt.title('3D Object, coronal view')

plt.subplot(133)
plt.imshow(Object3D[:, :, sliceSel], vmin=0, vmax=1)
plt.title('3D Object, sagittal view')
Ejemplo n.º 2
0
N3D_size = 256

obj3D = {
    'Obj': Objects3D.GAUSSIAN,
    'C0': 1.00,
    'x0': -0.25,
    'y0': 0.1,
    'z0': 0.0,
    'a': 0.2,
    'b': 0.35,
    'c': 0.7,
    'phi1': 30.0,
    'phi2': 60.0,
    'phi3': -25.0
}

Object3D = TomoP3D.Object(N3D_size, [obj3D])

sliceSel = int(0.5 * N3D_size)
#plt.gray()
plt.figure(7)
plt.subplot(121)
plt.imshow(Object3D[sliceSel, :, :], vmin=0, vmax=1)
plt.title('3D Phantom, axial view')

plt.subplot(122)
plt.imshow(Object3D[:, sliceSel, :], vmin=0, vmax=1)
plt.title('3D Phantom, coronal view')
plt.show()
#%%
Ejemplo n.º 3
0
        'Obj': Objects3D.ELLIPSOID,
        'C0': 1.00,
        'x0': -0.5,
        'y0': -0.5,
        'z0': z_coord_steps[i],
        'a': 0.18,
        'b': 0.07,
        'c': 0.13,
        'phi1': 0.0,
        'phi2': 0.0,
        'phi3': 0.0
    }

    myObjects = [obj3D1, obj3D2, obj3D3, obj3D4]  # dictionary of objects

    object3D = TomoP3D.Object(ObjSize, myObjects)
    """
    sliceSel = 200
    #plt.gray()
    plt.figure() 
    plt.subplot(121)
    plt.imshow(Object3D[sliceSel,:,:],vmin=0, vmax=1)
    plt.title('3D Phantom, axial view')
    
    plt.subplot(122)
    plt.imshow(Object3D[:,sliceSel,:],vmin=0, vmax=1)
    plt.title('3D Phantom, coronal view')
    plt.show()
    """
    # obtain projections using ASTRA-toolbox
    Atools = AstraTools3D(DetRows, DetColumns, angles_rad,
print("append", end1 - start)
while (nop.append_for(np.random.uniform(low=-1, high=1, size=3)) < M):
    pass
end2 = time.time()
print("append_for", end2 - end1)

#%%
gaussians = [{
    'Obj': tp3.Objects3D.PARABOLOID,
    'C0': 1.,
    'x0': float(nop.apoints[loc][0]),
    'y0': float(nop.apoints[loc][1]),
    'z0': float(nop.apoints[loc][2]),
    'a': .2,
    'b': .1,
    'c': .15,
    'phi1': np.random.uniform(low=0, high=360),
    'phi2': np.random.uniform(low=0, high=360),
    'phi3': np.random.uniform(low=0, high=360)
} for loc in range(len(nop.apoints))]

vol = tp3.Object(128, gaussians)
plt.imshow(vol[0])
plt.show()

writer = vtk.vtkMetaImageWriter()
conv = Converter.numpy2vtkImporter(vol)
conv.Update()
writer.SetInputData(conv.GetOutput())
writer.SetFileName("dvc_phantom0.mha")
writer.Write()
Ejemplo n.º 5
0
phi_max = 180.0
phi1 = random.uniform(phi_min, phi_max)

el3 = {
    'Obj': Objects3D.CUBOID,
    'C0': C_0,
    'x0': x0_rand,
    'y0': y0_rand,
    'z0': z0_rand,
    'a': a_el3,
    'b': b_el3,
    'c': c_el3,
    'phi1': phi1
}

GROUND_TRUTH = TomoP3D.Object(N_size, [el1, el2, el3])

GROUND_TRUTH[GROUND_TRUTH > 0.7] = 0.43336788
GROUND_TRUTH[(GROUND_TRUTH > 0.0) & (GROUND_TRUTH < 0.29999998)] = 0.43336788

sliceSel = (int)(N_size / 2)
plt.figure()
plt.subplot(131)
plt.imshow(GROUND_TRUTH[sliceSel, :, :])
plt.title('Ideal Phantom1')
plt.subplot(132)
plt.imshow(GROUND_TRUTH[:, sliceSel, :])
plt.title('Ideal Phantom2')
plt.subplot(133)
plt.imshow(GROUND_TRUTH[:, :, sliceSel])
plt.title('Ideal Phantom3')
Ejemplo n.º 6
0
def foam3D(x0min, x0max, y0min, y0max, z0min, z0max, c0min, c0max, ab_min,
           ab_max, N_size, tot_objects, object_type):
    import numpy as np
    import math
    import random
    #3D functions
    from tomophantom import TomoP3D
    from tomophantom.TomoP3D import Objects3D
    attemptsNo = 2000
    # objects accepted: 'ellipsoid', 'paraboloid', 'gaussian', 'mix'
    mix_objects = False
    if (object_type == 'ellipsoid'):
        object_type = Objects3D.ELLIPSOID
    elif (object_type == 'paraboloid'):
        object_type = Objects3D.PARABOLOID
    elif (object_type == 'gaussian'):
        object_type = Objects3D.GAUSSIAN
    elif (object_type == 'mix'):
        mix_objects = True
    else:
        raise TypeError(
            'object_type can be only ellipse, parabola, gaussian or mix')
    X0 = np.float32(np.zeros(tot_objects))
    Y0 = np.float32(np.zeros(tot_objects))
    Z0 = np.float32(np.zeros(tot_objects))
    AB = np.float32(np.zeros(tot_objects))
    C0_var = np.float32(np.zeros(tot_objects))
    for i in range(0, tot_objects):
        (x0, y0, z0, c0, ab) = rand_init3D(x0min, x0max, y0min, y0max, z0min,
                                           z0max, c0min, c0max, ab_min, ab_max)
        if (i > 0):
            breakj = False
            for j in range(0, attemptsNo):
                if breakj:
                    (x0, y0, z0, c0,
                     ab) = rand_init3D(x0min, x0max, y0min, y0max, z0min,
                                       z0max, c0min, c0max, ab_min, ab_max)
                    breakj = False
                else:
                    for l in range(
                            0, i
                    ):  # checks consistency with previously created objects
                        dist = math.sqrt((X0[l] - x0)**2 + (Y0[l] - y0)**2 +
                                         (Z0[l] - z0)**2)
                        if (dist < (ab + AB[l])) or ((abs(x0) + ab)**2 +
                                                     (abs(y0) + ab)**2 +
                                                     (abs(z0) + ab)**2 > 1.0):
                            breakj = True
                            break
                    if (breakj == False
                        ):  # re-initialise if doesn't fit the criteria
                        X0[i] = x0
                        Y0[i] = y0
                        Z0[i] = z0
                        AB[i] = ab
                        C0_var[i] = c0
                        break
        if (AB[i] == 0.0):
            X0[i] = x0
            Y0[i] = y0
            AB[i] = 0.0001
            C0_var[i] = c0

    myObjects = []  # dictionary of objects
    for obj in range(0, len(X0)):
        if (mix_objects == True):
            rand_obj = random.randint(0, 2)
            if (rand_obj == 0):
                object_type = Objects3D.ELLIPSOID
            if (rand_obj == 1):
                object_type = Objects3D.PARABOLOID
            if (rand_obj == 2):
                object_type = Objects3D.GAUSSIAN
        curr_obj = {
            'Obj': object_type,
            'C0': C0_var[obj],
            'x0': X0[obj],
            'y0': Y0[obj],
            'z0': Z0[obj],
            'a': AB[obj],
            'b': AB[obj],
            'c': AB[obj],
            'phi1': 0.0
        }
        myObjects.append(curr_obj)
    Object3D = TomoP3D.Object(N_size, myObjects)
    return (Object3D, myObjects)