def get_points_on_spectrum(self): indices = self.mz_to_indices() indices_denom = np.empty((0)) if self.current_mz_denom > 0: indices_denom = self.mz_to_indices(True) if indices.any(): num = np.mean(image[..., indices.flatten()], axis=-1) if indices_denom.any(): denom = np.mean(image[..., indices_denom.flatten()], axis=-1) divided = np.zeros_like(num, dtype=np.float64) np.divide(num, denom, out=divided, where=denom != 0) num = divided vol = vedo.Volume(num) vol.spacing([1, 1, spacing]) vol.interpolation(1) self.vp.update(vol) if not self.is_text_editing: self.edit_mz.setText(str(round(self.current_mz, 4))) self.edit_mz_denom.setText(str(round(self.current_mz_denom, 4)))
# self.remove([self.points, self.spline]) # cpt = self.computeWorldPosition(evt.picked2d) # make this 2d-screen point 3d # self.cpoints.append(cpt) # self.points = vedo.Points(self.cpoints, r=8).c('black') # if len(self.cpoints) > 2: # self.spline = vedo.Line(self.cpoints, closed=True).lw(5).c('red5') # self.add([self.points, self.spline]) # def onKeyPress(self, evt): # if evt.keyPressed == 'z' and self.spline: # cut mesh with a ribbon-like surface # vedo.printc("Cutting the mesh please wait..", invert=True) # tol = self.mesh.diagonalSize()/2 # size of ribbon # pts = self.spline.points() # n = vedo.fitPlane(pts, signed=True).normal # compute normal vector to points # rib = vedo.Ribbon(pts - tol*n, pts + tol*n, closed=True) # self.mesh.cutWithMesh(rib) # self.remove([self.spline, self.points]).render() # self.cpoints, self.points, self.spline = [], None, None # def start(self, **kwargs): # return self.show(self.txt2d, self.mesh, **kwargs) # ###################################################################################### vedo.settings.useParallelProjection = True # to avoid perspective artifacts msh = vedo.Volume(vedo.datadir+'embryo.tif').isosurface().color('gold', 0.25) # Mesh plt = FreeHandCutPlotter(msh).addHoverLegend() #plt.init(some_list_of_initial_pts) #optional! plt.start(axes=1, bg2='lightblue').close()
# Sort lists for correct order f1_list = sorted(f1_files) f2_list = sorted(f2_files) # print(f1_list) # print(f2_list) index = 3 medium = pv.read(tmp_folder + 'porousMedium.vti') grains = medium.get_array('tag').reshape([nz, ny, nx]) grains = grains[:, :, n_slices_start:nx-n_slices_end] grains = grains[:,:,:] print(grains.shape) grains = vd.Volume(grains).isosurface(1) plt = vd.Plotter(axes=9, bg='w', bg2='w', size=(1200,900), offscreen=False) # Create a vedo plotter; axes=9 is just an outline plt += grains.c("gray").opacity(0.4) cam = dict(pos=(179, 313, 136), focalPoint=(45.0, 49.5, 44.0), viewup=(-0.163, -0.252, 0.954), distance=309, clippingRange=(158, 501)) plt.show(camera=cam, interactive=True) # .screenshot(f'animation_and_plotting/gif_images/test{index}.png', scale=4) plt.close() # exit() # for index in range(len(f1_list)): f1_mesh = pv.read(f1_list[index])
mz, I = imzml.getspectrum(0) spectra = imzmlio.get_full_spectra(imzml) max_x = max(imzml.coordinates, key=lambda item: item[0])[0] max_y = max(imzml.coordinates, key=lambda item: item[1])[1] max_z = max(imzml.coordinates, key=lambda item: item[2])[2] image = imzmlio.get_images_from_spectra(spectra, (max_x, max_y, max_z)) print(image.shape) if len(image.shape) == 3: shape_4D = image.shape[:-1] + (1, image.shape[-1]) image = np.reshape(image, shape_4D) image = np.transpose(image, (2, 1, 0, 3)) if is_memmap: os.makedirs(memmap_dir, exist_ok=True) np.save(memmap_image_filename, image) np.save(memmap_spectra_filename, spectra) vol = vedo.Volume(image[..., 0]) mean_spectra = sp.spectra_mean(spectra) else: vol = vedo.load(inputname) # load Volume vedo.printHistogram(vol, logscale=True) vol.spacing([1, 1, spacing]) vol.mode(0).color("jet").jittering(True) vol.interpolation(1) app = Qt.QApplication(sys.argv) window = MainWindow(inputname, vol, spectra[0, 0], mean_spectra) sys.exit(app.exec_())
import urllib, hdf5storage, scipy.ndimage, vedo # import libs # download image from the Digital Rocks Portal drp = 'https://www.digitalrocksportal.org/' url = drp + 'projects/374/images/309544/download/' urllib.request.urlretrieve(url, im_name := '374_01_00_256.mat') # read-in image bin_im = hdf5.storage.loadmat(im_name)['bin'] # obtain the Euclidean distance of the pore-space edist = scipy.ndimage.morphology.distance_transform_edt(bin_im == 0) # remove upper corner half_size = bin_im.shape[0] // 2 edist[-half_size:, -half_size:, :half_size] = 0 bin_im[-half_size:, -half_size:, :half_size] = -1 # plot using Vedo plot = vedo.Volume(edist).legosurface(vmin=1, vmax=5, cmap='turbo') plot += vedo.Volume(bin_im).legosurface(vmin=1, vmax=2).c('lightgray').opacity(0.05) vedo.plotter(plot)