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 setXRayEnvironment(): gvxr.createWindow() gvxr.setWindowSize(512, 512) #gvxr.usePointSource(); gvxr.setMonoChromatic(80, "keV", 1000) gvxr.setDetectorUpVector(0, 0, -1) gvxr.setDetectorNumberOfPixels(768, 1024) gvxr.setDetectorPixelSize(0.5, 0.5, "mm") # 5 dpi setXRayParameters(10.0, 100.0) gvxr.loadSceneGraph("./hand.dae", "m") 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)) gvxr.moveToCentre('root') gvxr.disableArtefactFiltering() gvxr.rotateNode('root', -90, 1, 0, 0)
def initEnvironment(): global g_reference_sinogram global g_reference_CT global g_normalised_reference_sinogram global g_normalised_reference_CT global reference_sinogram_entropy global reference_CT_entropy g_reference_CT = cropCenter(np.loadtxt("W_ML_20keV.tomo-original.txt"), detector_width_in_pixels, detector_width_in_pixels) g_reference_sinogram = radon(g_reference_CT, theta=theta, circle=True).T g_normalised_reference_sinogram = IM.normalise(g_reference_sinogram) g_normalised_reference_CT = IM.normalise(g_reference_CT) reference_CT_entropy = IM.getEntropy(g_reference_CT) reference_sinogram_entropy = IM.getEntropy(g_reference_sinogram) np.savetxt("normalised_sinogram_ref.txt", g_normalised_reference_sinogram) np.savetxt("normalised_CT_ref.txt", g_normalised_reference_CT) #np.savetxt("sinogram_ref.txt", g_reference_sinogram); #np.savetxt("CT_ref.txt", g_reference_CT); scipy.misc.toimage(g_normalised_reference_sinogram).save( 'sinogram_ref.jpg') scipy.misc.toimage(g_normalised_reference_CT).save('CT_ref.jpg') # Create an OpenGL context print("Create an OpenGL context") gvxr.createOpenGLContext() gvxr.setWindowSize(512, 512) # Create the X-ray simulator initXRaySimulator() gvxr.disableArtefactFiltering()
gvxr.setMonoChromatic(0.08, "MeV", 1000); # Set up the detector print("Set up the detector"); gvxr.setDetectorUpVector(0, 0, -1); gvxr.setDetectorNumberOfPixels(1024, 1536); gvxr.setDetectorPixelSize(0.5, 0.5, "mm"); setXRayParameters(ground_truth_SOD, ground_truth_SDD); # Load the data print("Load the data"); gvxr.loadSceneGraph("/home/ti/Documents/gvxr-python3-gui/hand.dae", "m"); gvxr.moveToCentre('root'); gvxr.disableArtefactFiltering(); # Compute groud truth x-ray image ground_truth_image = poserior_anterior(ground_truth_angles); plt.imsave("ground-truth.png", ground_truth_image); # Compute optimisation image = random_search(); plt.imsave("prediction.png", image); plt.subplot(1, 2, 1); plt.imshow(ground_truth_image); plt.subplot(1, 2, 2); plt.imshow(image); plt.show();
def createTarget(): global target target_SOD = 100 target_SDD = 140 target_angles_pa = [ 0, 20, 0, -10, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] target = [] target.append(target_SOD) target.append(target_SDD) for i in range(len(target_angles_pa)): target.append(target_angles_pa[i]) gvxr.createWindow() gvxr.setWindowSize(512, 512) #gvxr.usePointSource(); gvxr.setMonoChromatic(80, "keV", 1000) gvxr.setDetectorUpVector(0, 0, -1) gvxr.setDetectorNumberOfPixels(1536, 1536) gvxr.setDetectorPixelSize(0.5, 0.5, "mm") # 5 dpi setXRayParameters(target_SOD, target_SDD) gvxr.loadSceneGraph("./hand.dae", "m") 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)) gvxr.moveToCentre('root') gvxr.disableArtefactFiltering() target_image = bone_rotation(target_angles_pa) plt.imsave("./posterior-anterior/RMSE/target.png", target_image, cmap='Greys_r') return target_image, target
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)
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