def showLoadDialog(self): """ This slot brings up the load dialog and retrieves the file name. If the file name is valid, it loads the image stack using the load method. """ fname = self.lasagna.showFileLoadDialog(fileFilter="LSM (*.lsm)") if fname is None: return color_order = preferences.readPreference('colorOrder') if os.path.isfile(fname): im = tifffile.imread(str(fname)) print("Found LSM stack with dimensions:") print(im.shape) for i in range(im.shape[2]): stack = im[0, :, i, :, :] obj_name = "layer_%d" % (i + 1) self.lasagna.addIngredient(objectName=obj_name, kind='imagestack', data=stack, fname=fname) self.lasagna.returnIngredientByName( obj_name).addToPlots() # Add item to all three 2D plots print("Adding '{}' layer".format(color_order[i])) self.lasagna.returnIngredientByName( obj_name).lut = color_order[i] self.lasagna.initialiseAxes() else: self.lasagna.statusBar.showMessage( "Unable to find {}".format(fname))
def chooseTransform_slot(self, fname_to_choose=False): """ Choose the transform file to use can optionally load a specific file name (used for de-bugging) """ if not fname_to_choose: file_filter = "Images (*.txt)" fname_to_choose = QtGui.QFileDialog.getOpenFileName( self, 'Choose transform', preferences.readPreference('lastLoadDir'), file_filter) fname_to_choose = str(fname_to_choose) if os.path.exists(fname_to_choose): self.transformPath = fname_to_choose else: self.transformPath = '' # TODO: make an alert box for this case print("that file does not exits") self.checkIfReadyToRun() preferences.preferenceWriter( 'lastLoadDir', lasagna.utils.path_utils.stripTrailingFileFromPath( fname_to_choose)) self.transformName_label.setText( fname_to_choose.split(os.path.sep)[-1])
def __init__(self, parent=None, data=None, fnameAbsPath="", enable=True, objectName=""): super(sparsepoints, self).__init__(parent, data, fnameAbsPath, enable, objectName, pgObject="ScatterPlotItem") # Choose symbols from preferences file. TODO: in future could increment through so successive ingredients have different symbols and colors self.symbol = preferences.readPreference("symbolOrder")[0] self.symbolSize = int(self.parent.markerSize_spinBox.value()) self.alpha = int(self.parent.markerAlpha_spinBox.value()) self.lineWidth = None # Not used right now self.build_model_for_list(objectName) self.model = self.parent.points_Model self.addToList() # Set the colour of the object based on how many items are already present # TODO: duplicate code with lines.py number_of_colors = 6 this_number = (self.parent.points_Model.rowCount() - 1) % number_of_colors # FIXME: rename cm_subsection = linspace(0, 1, number_of_colors) colors = [cm.jet(x) for x in cm_subsection] color = colors[this_number] self.color = [color[0] * 255, color[1] * 255, color[2] * 255]
def __init__(self, parent=None, data=None, fnameAbsPath="", enable=True, objectName=""): super(lines, self).__init__(parent, data, fnameAbsPath, enable, objectName, pgObject="PlotCurveItem") # Choose symbols from preferences file. # TODO: read symbols from GUI self.symbol = preferences.readPreference("symbolOrder")[0] self.symbolSize = int(self.parent.markerSize_spinBox.value()) self.alpha = int(self.parent.markerAlpha_spinBox.value()) self.lineWidth = int(self.parent.lineWidth_spinBox.value()) self.build_model_for_list(objectName) self.model = self.parent.points_Model self.addToList() # Set the colour of the object based on how many items are already present # TODO: duplicate code with sparsepoints.py number_of_colors = 6 this_number = (self.parent.points_Model.rowCount() - 1) % number_of_colors # FIXME: rename cm_subsection = linspace(0, 1, number_of_colors) colors = [cm.jet(x) for x in cm_subsection] color = colors[this_number] self.color = [color[0] * 255, color[1] * 255, color[2] * 255]
def __init__(self, thisPlotWidget, lasagna_serving, axisName='', minMax=(0, 1500), axisRatio=1, axisToPlot=0): """ thisPlotWidget - the PlotWidget to which we will add the axes minMax - the minimum and maximum values of the plotted image. axisRatio - the voxel size ratio along the x and y axes. 1 means square voxels. axisToPlot - the dimension along which we are slicing the data. """ # Create properties self.axisToPlot = axisToPlot # the axis in 3D space that this view correponds to self.axisName = axisName # We can link this projection to two others self.linkedXprojection = None self.linkedYprojection = None print("Creating axis at " + str(thisPlotWidget.objectName())) self.view = thisPlotWidget # This should target the axes to a particular plot widget if preferences.readPreference('hideZoomResetButtonOnImageAxes'): self.view.hideButtons() if preferences.readPreference('hideAxes'): self.view.hideAxis('left') self.view.hideAxis('bottom') self.view.setAspectLocked(True, axisRatio) # Loop through the ingredients list and add them to the ViewBox self.lasagna = lasagna_serving self.items = [ ] # a list of added plot items TODO: check if we really need this self.addItemsToPlotWidget(self.lasagna.ingredientList) # The currently plotted slice self.currentSlice = None # Link the progressLayer signal to a slot that will move through image layers as the wheel is turned self.view.getViewBox().progressLayer.connect(self.wheel_layer_slot)
def get_voxel_spacing(fname, fall_back_mode=False): """ Attempts to get the voxel spacing in all three dimensions. This allows us to set the axis ratios automatically. TODO: Currently this will only work for MHD files, but we may be able to swing something for TIFFs (e.g. by creating Icy-like metadata files) """ if fname.lower().endswith(".mhd"): return mhd_get_ratios(fname) if fname.lower().endswith(".nrrd") or fname.lower().endswith(".nrd"): return nrrd_get_ratios(fname) else: return preferences.readPreference("defaultAxisRatios") # defaults
def mhd_get_ratios(fname): """ Get relative axis ratios from MHD file defined by fname """ if not check_file_exists(fname, mhd_get_ratios): return try: # Attempt to use the vtk module to read the element spacing imp.find_module("vtk") import vtk imr = vtk.vtkMetaImageReader() imr.SetFileName(fname) imr.Update() im = imr.GetOutput() spacing = im.GetSpacing() except ImportError: # If the vtk module fails, we try to read the spacing using the built-in reader info = mhd_read_header_file(fname) if "elementspacing" in info: spacing = info["elementspacing"] else: print( "Failed to find spacing info in MHA file. Using default axis length values" ) return preferences.readPreference("defaultAxisRatios") # defaults if not spacing: print( "Failed to find spacing valid spacing info in MHA file. Using default axis length values" ) return preferences.readPreference("defaultAxisRatios") # defaults return spacing_to_ratio(spacing)
def loadOther_pushButton_slot(self, fnameToLoad=False): """ Load a user-selected atlas file but use the labels from the ARA in the drop-down box. Can optionally load a specific file name (used for de-bugging) """ if not fnameToLoad: file_filter = "Images (*.mhd *.mha *.tiff *.tif *.nrrd)" fnameToLoad = QtGui.QFileDialog.getOpenFileName( self, 'Open file', preferences.readPreference('lastLoadDir'), file_filter) fnameToLoad = str(fnameToLoad[0]) # tuple with filter as 2nd value # re-load labels selected_name = str( self.araName_comboBox.itemText( self.araName_comboBox.currentIndex())) paths = self.paths[selected_name] self.data['labels'] = self.loadLabels(paths['labels']) # load the selected atlas (without displaying it) self.data['atlas'] = image_stack_loader.load_stack(fnameToLoad) self.data['currentlyLoadedAtlasName'] = fnameToLoad.split( os.path.sep)[-1]
def get_fname(self): fnames = QtGui.QFileDialog.getOpenFileNames( self, 'Open file', preferences.readPreference('lastLoadDir'), self.fileFilter)[0] # getOpenFileNames returns a tuple of (file_list, filter). Ignore the filter self.FileListTextEdit.setText('\n'.join(fnames))