Exemplo n.º 1
0
    def setEnergy(self, event):
        global x_ray_image
        gvxr.setMonoChromatic(self.energy_var.get(), "MeV", 1);
        x_ray_image = gvxr.computeXRayImage();
        gvxr.displayScene()
        self.xray_vis.draw(x_ray_image);

        selection = "Energy = " + str((self.energy_var.get())) + ' MeV'
        self.energy_label.config(text = selection)
Exemplo n.º 2
0
    def rotationScene(self, widget):
        global x_ray_image;
        selection = "Angle = " + str(int(self.rotation_var.get())) + ' deg'
        self.angle_label.config(text = selection)

        gvxr.rotateScene(self.rotation_var.get() - self.last_angle, 0, -1, 0);
        self.last_angle = self.rotation_var.get();

        x_ray_image = gvxr.computeXRayImage();
        gvxr.displayScene()
        self.xray_vis.draw(x_ray_image);
Exemplo n.º 3
0
    def setSourceShape(self):
        if self.source_shape.get() == 0:
            print ("Use point source");
            gvxr.usePointSource();

        elif self.source_shape.get() == 1:
            print ("Use parallel beam");
            gvxr.useParallelBeam();

        x_ray_image = gvxr.computeXRayImage();
        gvxr.displayScene()
        self.xray_vis.draw(x_ray_image);
Exemplo n.º 4
0
    def artefactFilteringSelection(self):
        global x_ray_image;

        value = self.artefact_filtering_var.get();
        if value is 0:
            gvxr.disableArtefactFiltering();
        elif value is 1:
            gvxr.enableArtefactFilteringOnCPU();
        elif value is 2:
            gvxr.enableArtefactFilteringOnGPU();

        x_ray_image = gvxr.computeXRayImage();
        gvxr.displayScene()
        self.xray_vis.draw(x_ray_image);
    def setZRotation(self, event):
        global x_ray_image

        selection = "Rotation in Z = " + str(
            (self.z_rotation_value.get())) + ' degrees'
        self.z_rotation_label.config(text=selection)
        gvxr.rotateNode(
            self.selected_node,
            self.z_rotation_value.get() -
            self.rotation_dictionary[self.selected_node][2], 0, 0, 1)
        self.rotation_dictionary[
            self.selected_node][0] = self.z_rotation_value.get()
        x_ray_image = gvxr.computeXRayImage()
        gvxr.displayScene()
        self.xray_vis.draw(x_ray_image)
    def setReset(self):
        print("Reset roation of ", self.selected_node)
        self.x_rotation_value.set(0)
        self.y_rotation_value.set(0)
        self.z_rotation_value.set(0)

        self.setZRotation(0)
        self.setYRotation(0)
        self.setXRotation(0)

        gvxr.setNodeTransformationMatrix(
            self.selected_node,
            self.transformation_dictionary[self.selected_node])
        x_ray_image = gvxr.computeXRayImage()
        gvxr.displayScene()
        self.xray_vis.draw(x_ray_image)
Exemplo n.º 7
0
    def OnDoubleClick(self, event):
        self.OnSingleClick(event)
        text = self.tree.item(self.selected_item,"text");

        if text == "root":
            print ("Ignore root")
        elif text == "":
            print ("Ignore empty name")
        else:
            print("you clicked on ", text)

            material_selection = MaterialSelection.MaterialSelection(self.root, text, gvxr.getMaterialLabel(text), gvxr.getDensity(text));
            child_children = gvxr.getNumberOfChildren(text);

            if material_selection.cancel == False:
                global x_ray_image;

                # Element
                if material_selection.materialType.get() == 0:
                    gvxr.setElement(text, material_selection.element_name.get());
                    gvxr.setDensity(text, float(material_selection.density.get()), "g/cm3");
                # Mixture
                elif material_selection.materialType.get() == 1:
                    gvxr.setMixture(text, material_selection.mixture.get());
                    gvxr.setDensity(text, float(material_selection.density.get()), "g/cm3");
                # Compound
                elif material_selection.materialType.get() == 2:
                    gvxr.setCompound(text, material_selection.compound.get());
                    gvxr.setDensity(text, float(material_selection.density.get()), "g/cm3");
                # Hounsfield unit
                elif material_selection.materialType.get() == 3:
                    gvxr.setHU(text, material_selection.hounsfield_value.get());
                # Mass attenuation coefficient
                elif material_selection.materialType.get() == 4:
                    gvxr.setDensity(text, float(material_selection.density.get()), "g/cm3");
                    print("?");
                # Linear attenuation coefficient
                elif material_selection.materialType.get() == 5:
                    gvxr.setDensity(text, float(material_selection.density.get()), "g/cm3");
                    print("?");

                self.tree.item(self.selected_item, values=(str(child_children), gvxr.getMaterialLabel(text), str(gvxr.getDensity(text))))

                x_ray_image = gvxr.computeXRayImage();
                gvxr.displayScene()
                self.xray_vis.draw(x_ray_image);
Exemplo n.º 8
0
def bone_rotation(angles, finger):
    '''
    @Params:
        Angles: list of rotating angles.

        finger: choice of "Root", "Thumb", "Index", "Middle", "Ring", "Little",
                "None" or "All"
    '''

    matrix_set = getLocalTransformationMatrixSet()

    if finger != 'None':
        updateLocalTransformationMatrixSet(angles, finger)

    x_ray_image = gvxr.computeXRayImage()
    image = np.array(x_ray_image)
    image = (image - image.mean()) / image.std()
    image[np.isnan(image)] = 0.
    image[image > 1E308] = 0.

    setLocalTransformationMatrixSet(matrix_set)

    return image
Exemplo n.º 9
0
def main(argv):
    global x_ray_image

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "-input",
        type=str,
        help=
        "Input file (see http://assimp.sourceforge.net/main_features_formats.html for a list of supported file formats)"
    )
    parser.add_argument(
        "-unit",
        type=str,
        help="Unit of length corresponding to the input",
        choices=["um", "mm", "cm", "dm", "m", "dam", "hm", "km"])

    args = parser.parse_args()
    if args.input and args.unit:
        # Create an OpenGL context
        print("Create an OpenGL context")
        gvxr.createWindow()
        gvxr.setWindowSize(512, 512)

        # Set up the beam
        print("Set up the beam")
        gvxr.setSourcePosition(100.0, 0.0, 0.0, "cm")
        gvxr.usePointSource()
        #gvxr.useParallelBeam();
        gvxr.setMonoChromatic(0.08, "MeV", 1)

        # Set up the detector
        print("Set up the detector")
        gvxr.setDetectorPosition(-40.0, 0.0, 0.0, "cm")
        gvxr.setDetectorUpVector(0, 0, -1)
        gvxr.setDetectorNumberOfPixels(1024, 1024)
        gvxr.setDetectorPixelSize(0.5, 0.5, "mm")

        # Load the data
        print("Load the data")

        gvxr.loadSceneGraph(args.input, args.unit)

        gvxr.disableArtefactFiltering()

        #gvxr.loadMeshFile("chest", "./HVPTest/chest2.obj", "mm");
        #gvxr.invertNormalVectors("armR");
        #gvxr.invertNormalVectors("chest");

        node_label_set = []
        node_label_set.append('root')

        # The list is not empty
        while (len(node_label_set)):

            # Get the last node
            last_node = node_label_set[-1]

            # Initialise the material properties
            #print("Set ", label, "'s Hounsfield unit");
            #gvxr.setHU(label, 1000)
            Z = gvxr.getElementAtomicNumber("H")
            gvxr.setElement(last_node, gvxr.getElementName(Z))

            # Change the node colour to a random colour
            gvxr.setColour(last_node, random.uniform(0, 1),
                           random.uniform(0, 1), random.uniform(0, 1), 1.0)

            # Remove it from the list
            node_label_set.pop()

            # Add its Children
            for i in range(gvxr.getNumberOfChildren(last_node)):
                node_label_set.append(gvxr.getChildLabel(last_node, i))
            '''
        for label in gvxr.getMeshLabelSet():
            print("Move ", label, " to the centre");
            #gvxr.moveToCentre(label);

            #print("Move the mesh to the center");
            #gvxr.moveToCenter(label);

            #gvxr.invertNormalVectors(label);
        '''
        #gvxr.moveToCentre();
        gvxr.moveToCentre('root')

        # Compute an X-ray image
        #print("Compute an X-ray image");
        #gvxr.disableArtefactFiltering();
        #gvxr.enableArtefactFilteringOnGPU();
        # Not working anymore gvxr.enableArtefactFilteringOnGPU();
        # Not working anymore gvxr.enableArtefactFilteringOnCPU();
        x_ray_image = np.array(gvxr.computeXRayImage())
        '''x_ray_image -= 0.0799;
        x_ray_image /= 0.08 - 0.0799;
        plt.ioff();
        plt.imshow(x_ray_image, cmap="gray");
        plt.show()
        '''
        #gvxr.setShiftFilter(-0.0786232874);
        #gvxr.setScaleFilter(726.368958);

        gvxr.displayScene()

        app = App.App(0.08)
Exemplo n.º 10
0
def computeSinogram():

    gvxr.disableArtefactFiltering()
    gvxr.enableArtefactFilteringOnGPU()

    # Compute an X-ray image
    #print("Compute sinogram");

    sinogram = np.zeros((number_of_projections, detector_width_in_pixels),
                        dtype=np.float)

    sinogram = np.array(
        gvxr.computeSinogram(0, 1, 0, 'mm', number_of_projections,
                             -angular_step))

    #gvxr.saveLastSinogram();
    #gvxr.saveLastLBuffer('saveLastLBuffer.mhd');
    #gvxr.saveLastCumulatedLBuffer('saveLastCumulatedLBuffer.mhd');

    return sinogram

    for angle_id in range(0, number_of_projections):
        gvxr.resetSceneTransformation()
        gvxr.rotateScene(-angular_step * angle_id, 0, 1, 0)

        #gvxr.displayScene();
        #print (str(angle_id), ":\t", str(angular_step * angle_id), " degrees");
        # Rotate the scene

        # Compute the X-ray projection and save the numpy image
        np_image = np.array(gvxr.computeXRayImage())

        # Display the 3D scene (no event loop)
        #gvxr.displayScene();

        # Append the sinogram
        sinogram[angle_id] = np_image[math.floor(detector_height_in_pixels /
                                                 2), :]

    total_energy = 0.0
    for i, j in energy_spectrum_in_keV:
        total_energy += i * j * gvxr.getUnitOfEnergy('keV')

    blur_the_sinogram = False
    if blur_the_sinogram:
        blurred_sinogram = np.zeros(sinogram.shape)

        t = np.arange(-20., 21., 1.)
        kernel = lsf(t * 41) / lsf(0)
        kernel /= kernel.sum()
        #plt.plot(t,kernel);
        #plt.show();

        for i in range(sinogram.shape[0]):
            blurred_sinogram[i] = np.convolve(sinogram[i], kernel, mode='same')

        blurred_sinogram = total_energy / blurred_sinogram
        blurred_sinogram = np.log(blurred_sinogram)
        blurred_sinogram /= (
            pixel_size_in_micrometer *
            gvxr.getUnitOfLength("um")) / gvxr.getUnitOfLength("cm")

        #np.savetxt("blurred_sinogram_gvxr.txt", blurred_sinogram);

        return blurred_sinogram

    # Convert in keV
    sinogram = total_energy / sinogram
    sinogram = np.log(sinogram)
    sinogram /= (pixel_size_in_micrometer *
                 gvxr.getUnitOfLength("um")) / gvxr.getUnitOfLength("cm")

    #np.savetxt("sinogram_gvxr.txt", sinogram);

    gvxr.saveLastLBuffer('saveLastLBuffer.mhd')
    gvxr.saveLastCumulatedLBuffer('saveLastCumulatedLBuffer.mhd')

    np_image = np.array(gvxr.computeLBuffer('Matrix'))
    np.savetxt("l_buffer.txt", np_image)

    return sinogram
Exemplo n.º 11
0
def poserior_anterior(angles):

    node_label_set = []
    node_label_set.append('root')

    # The list is not empty
    while (len(node_label_set)):

        # Get the last node
        node = node_label_set[-1]

        # Initialise the material properties
        Z = gvxr.getElementAtomicNumber("H")
        gvxr.setElement(node, gvxr.getElementName(Z))

        # Change the node colour to a random colour
        gvxr.setColour(node, random.uniform(0, 1), random.uniform(0, 1),
                       random.uniform(0, 1), 1.0)

        # Remove it from the list
        node_label_set.pop()

        # Add its Children
        for i in range(gvxr.getNumberOfChildren(node)):
            node_label_set.append(gvxr.getChildLabel(node, i))

        if node == 'root':

            gvxr.rotateNode(node, angles[0], 1, 0, 0)
            gvxr.rotateNode(node, angles[1], 0, 1, 0)

        if node == 'node-Thu_Meta':
            gvxr.rotateNode(node, angles[2], 1, 0, 0)
            gvxr.rotateNode(node, angles[3], 0, 1, 0)

        if node == 'node-Thu_Prox':
            gvxr.rotateNode(node, angles[4], 1, 0, 0)
            gvxr.rotateNode(node, angles[5], 0, 1, 0)

        if node == 'node-Thu_Dist':
            gvxr.rotateNode(node, angles[6], 1, 0, 0)
            gvxr.rotateNode(node, angles[7], 0, 1, 0)

        if node == 'node-Lit_Meta':
            gvxr.rotateNode(node, angles[8], 1, 0, 0)
            gvxr.rotateNode(node, angles[9], 0, 1, 0)

        if node == 'node-Lit_Prox':
            gvxr.rotateNode(node, angles[10], 1, 0, 0)
            gvxr.rotateNode(node, angles[11], 0, 1, 0)

        if node == 'node-Lit_Midd':
            gvxr.rotateNode(node, angles[12], 1, 0, 0)
            gvxr.rotateNode(node, angles[13], 0, 1, 0)

        if node == 'node-Lit_Dist':
            gvxr.rotateNode(node, angles[14], 1, 0, 0)
            gvxr.rotateNode(node, angles[15], 0, 1, 0)

        if node == 'node-Thi_Meta':
            gvxr.rotateNode(node, angles[16], 1, 0, 0)
            gvxr.rotateNode(node, angles[17], 0, 1, 0)

        if node == 'node-Thi_Prox':
            gvxr.rotateNode(node, angles[18], 1, 0, 0)
            gvxr.rotateNode(node, angles[19], 0, 1, 0)

        if node == 'node-Thi_Midd':
            gvxr.rotateNode(node, angles[20], 1, 0, 0)
            gvxr.rotateNode(node, angles[21], 0, 1, 0)

        if node == 'node-Thi_Dist':
            gvxr.rotateNode(node, angles[22], 1, 0, 0)
            gvxr.rotateNode(node, angles[23], 0, 1, 0)

        if node == 'node-Mid_Meta':
            gvxr.rotateNode(node, angles[24], 1, 0, 0)
            gvxr.rotateNode(node, angles[25], 0, 1, 0)

        if node == 'node-Mid_Prox':
            gvxr.rotateNode(node, angles[26], 1, 0, 0)
            gvxr.rotateNode(node, angles[27], 0, 1, 0)

        if node == 'node-Mid_Midd':
            gvxr.rotateNode(node, angles[28], 1, 0, 0)
            gvxr.rotateNode(node, angles[29], 0, 1, 0)

        if node == 'node-Mid_Dist':
            gvxr.rotateNode(node, angles[30], 1, 0, 0)
            gvxr.rotateNode(node, angles[31], 0, 1, 0)

        if node == 'node-Ind_Meta':
            gvxr.rotateNode(node, angles[32], 1, 0, 0)
            gvxr.rotateNode(node, angles[33], 0, 1, 0)

        if node == 'node-Ind_Prox':
            gvxr.rotateNode(node, angles[34], 1, 0, 0)
            gvxr.rotateNode(node, angles[35], 0, 1, 0)

        if node == 'node-Ind_Midd':
            gvxr.rotateNode(node, angles[36], 1, 0, 0)
            gvxr.rotateNode(node, angles[37], 0, 1, 0)

        if node == 'node-Ind_Dist':
            gvxr.rotateNode(node, angles[0], 1, 0, 0)
            gvxr.rotateNode(node, angles[0], 0, 1, 0)

    x_ray_image = gvxr.computeXRayImage()
    image = np.array(x_ray_image)

    return image
Exemplo n.º 12
0
# Read results and visualise predicted 3D hand
parser = argparse.ArgumentParser()

parser.add_argument("--results_csv", help="Result csv files")
args = parser.parse_args()

setXRayEnvironment()

number_of_distances = 2
number_of_angles = 22
input_csv = pd.read_csv(args.results_csv, usecols=['Parameters'])

prediction = dataFrameToFloat(input_csv['Parameters'][0])

SOD = prediction[0] * prediction[1]
SDD = prediction[1]
setXRayParameters(SOD, SDD)

angles = []

for a in range(number_of_angles):
    angles.append(prediction[a + number_of_distances])

updateLocalTransformationMatrixSet(angles, 'All')

gvxr.computeXRayImage()

gvxr.displayScene()
gvxr.renderLoop()
Exemplo n.º 13
0
#gvxr.useParallelBeam();
gvxr.setMonoChromatic(0.08, "MeV", 1000)

# Set up the detector
print("Set up the detector")
gvxr.setDetectorPosition(centre[0], centre[1], centre[2] + 10.0, "cm")
gvxr.setDetectorUpVector(0, -1, 0)
gvxr.setDetectorNumberOfPixels(640, 320)
gvxr.setDetectorPixelSize(0.125, 0.125, "mm")

# Compute an X-ray image
print("Compute an X-ray image")
gvxr.disableArtefactFiltering()
# Not working anymore gvxr.enableArtefactFilteringOnGPU();
# Not working anymore gvxr.enableArtefactFilteringOnCPU();
x_ray_image = gvxr.computeXRayImage()

# Save the last image into a file
print("Save the last image into a file")
gvxr.saveLastXRayImage()
gvxr.saveLastLBuffer()

# Display the image with Matplotlib
if use_matplotlib:
    plt.imshow(x_ray_image, cmap="gray")
    plt.colorbar(orientation='horizontal')
    plt.title("Using a linear colour scale")

    plt.subplot(132)
    plt.imshow(x_ray_image, norm=LogNorm(), cmap="gray")
    plt.colorbar(orientation='horizontal')