def read_image_to_register(registername, is_imzml, to_flip, moving): mz = None if is_imzml: imzml = imzmlio.open_imzml(registername) current_s = 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] array = imzmlio.get_images_from_spectra(current_s, (max_x, max_y, max_z)).T register = sitk.GetImageFromArray(array) mz, _ = imzml.getspectrum(0) else: register = sitk.ReadImage(registername, sitk.sitkFloat32) if to_flip: dim = register.GetDimension() flip = (True, False) + ((False, ) if dim > 2 else ()) register = sitk.Flip(register, flip) dim = register.GetDimension() register.SetSpacing([1 for i in range(dim)]) identity = np.identity(dim).tolist() flat_list = [item for sublist in identity for item in sublist] direction = tuple(flat_list) register.SetDirection(flat_list) return register, mz
def read_imzml(inputname): imzml = imzmlio.open_imzml(inputname) 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)) mzs, intensities = imzml.getspectrum(0) return spectra, image
parser.add_argument("-i", "--input", help="Input 3D imzml") parser.add_argument("-o", "--output", help="Output directory for 2D imzml") args = parser.parse_args() inputname = args.input outname = args.output imzml = imzmlio.open_imzml(inputname) 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)) coordinates = imzml.coordinates print("Parsing all spectra") intensities, new_coords = imzmlio.get_spectra_from_images(image) previous_index = 0 array_coords = np.array(new_coords) array_intensities = np.array(intensities) split_intensities, split_coords = [], [] print("Splitting") for i in range(max_z): indices = np.where(array_coords.T[2] == i + 1) current_intensities = list(map(list, array_intensities[indices])) current_coordinates = array_coords[indices]
plt.axis("off") plt.savefig(current_name, transparent=True, bbox_inches='tight', pad_inches=0, dpi=150) plt.close() ## Open imzML ## This is a MS image where peaks are selected imzml = io.open_imzml("data/wheat/msi.imzML") spectra = io.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] msi_images = io.get_images_from_spectra(spectra, shape=(max_x, max_y)) ## Open MRI image mri_itk_image = sitk.ReadImage("data/wheat/mri.png") mri_image = sitk.GetArrayFromImage(mri_itk_image) ## Curvature values obtained by the VCM estimator ## of Lachaud et al. available in DGtal: ## More at https://dgtal.org/doc/stable/moduleVCM.html ## here, parameters r=4, R=5 for VCM computation ## The actual script used is available at https://github.com/fgrelard/MyDGtalContrib/blob/master/curvature.sh ## Requires DGtal library compilation curvature_mri = np.loadtxt("data/wheat/mri_curvature.txt") curvature_msi_coherence = np.loadtxt("data/wheat/msi_coherence_curvature.txt") curvature_msi_chaos = np.loadtxt("data/wheat/msi_chaos_curvature.txt") points_mri = np.loadtxt("data/wheat/mri_curvature_points.sdp",