示例#1
0
    def callOpenRecentFile(self, path=None):

        # Check if the file/dir exist
        if os.path.isdir(path) or os.path.isfile(path):

            # Get the name of the file
            _, _image_name = os.path.split(path)

            # Get the recommandations
            image_recommendations = getImagesInfos(path)
            _do_crop = image_recommendations['do_crop'] and self.parent.config.crop_image
            _crop_size = self.parent.config.crop_size
            _do_sign_correction = image_recommendations['do_sign_correction'] and self.parent.config.correct_signed
            _open_range = None
            _wait_range = False

            # Open the progress bar window
            openWindow(self.parent, OpenImageProgressBarWindow, 'progress_bar', image_path=path, name=_image_name, crop=_do_crop, crop_size=_crop_size, correct_sign=_do_sign_correction, scheduler=self)

            # Add the path to the recent file list
            appendRecentFiles(path)

        # Raise an error if the file doesn't exist anymore
        else:
            errorMessage("No Selection","The selected file or folder doesn't exist.")

            # Remove the file from the list
            deleteRecentFiles(path)
示例#2
0
    def convertFolders(self):

        # Only process if the folder is not empty
        if self.directory is not None:

            # Get all the folders to save
            folders_to_save = []
            for i, crt_checkbox in enumerate(self.all_checkboxes):

                if crt_checkbox.isChecked():
                    folders_to_save.append(
                        os.path.join(self.directory, self.folders[i]))

            # Process the folders
            if len(folders_to_save) == 0:
                errorMessage(
                    "Empty selection",
                    "The current selection of folders to be converted is empty. Select at least one folder to proceed."
                )

            else:
                # Get the status of the checkbox
                delete_folders = self.deleteFoldersCheckbox.isChecked()

                # Process all the folders
                openWindow(self.parent,
                           ConvertFolderProgressBarWindow,
                           'progress_bar',
                           folder_list=folders_to_save,
                           delete_folders=delete_folders,
                           scheduler=self)
示例#3
0
    def callOpenImageWindow(self):

        # Autoload the image with recommendations
        if self.parent.config.autoload_images:

            # Load a single image
            if self.parent.config.single_images:
                imageFile, _ = qtw.QFileDialog.getOpenFileName(self.parent, "Open Image(s)...", "","Image Files (*.tif;*.tiff;*.png;*.bmp;*.gif);;All Files (*)")
            else:
                imageFile = qtw.QFileDialog.getExistingDirectory(self.parent, "Open Image(s)...")

            if imageFile:

                # Get the name of the file
                _, _image_name = os.path.split(imageFile)

                # Get the recommandations
                image_recommendations = getImagesInfos(imageFile)
                _do_crop = image_recommendations['do_crop'] and self.parent.config.crop_image
                _crop_size = self.parent.config.crop_size
                _do_sign_correction = image_recommendations['do_sign_correction'] and self.parent.config.correct_signed
                _open_range = None
                _wait_range = False

                # Open the progress bar window
                openWindow(self.parent, OpenImageProgressBarWindow, 'progress_bar', image_path=imageFile, name=_image_name, crop=_do_crop, crop_size=_crop_size, correct_sign=_do_sign_correction, scheduler=self)

                # Add the path to the recent file list
                appendRecentFiles(imageFile)

        # Load the advanced config window
        else:
            openWindow(self.parent, openImageWindow, 'open_image')
示例#4
0
    def processStack(self):

        # Save the current settings in the class
        self.saveSettings()

        # Ask the user to save the new settings as well if needed
        if self.trajectory_session.modified:

            # Prompt
            if warningProceedMessage(
                    'Save Tracker',
                    'Do you want to save the batch settings of the tracker in the memory?'
            ):
                editTrackerConfig(self.trajectory_session)

        # Retrieve the displayed stack
        tab_id = self.parent.imageTabDisplay.currentIndex()
        self.image_class = self.parent.imageTabDisplay.displayedTabs[
            tab_id].image_class

        # Open the progress bar window
        openWindow(self.parent,
                   TrackpyProgressBarWindow,
                   'progress_bar',
                   image_class=self.image_class,
                   trackpy_session=self.detection_session,
                   scheduler=self)
示例#5
0
    def callReadMetadataWindow(self):

        # Get the metadata
        metadataFile, _ = qtw.QFileDialog.getOpenFileName(self.parent, "Open Metadata file...", "","Metadata Files (*.xml)")

        # Open the window if a file has been selected
        if metadataFile:
            openWindow(self.parent, readMetadataWindow, 'read_metadata', file_path=metadataFile)
示例#6
0
    def callDarkToBright(self):

        # Check if a tab is open
        if len( self.parent.imageTabDisplay.displayedTabs ) > 0:
            openWindow(self.parent, darkToBrightCorrectionWindow, 'dark_to_bright')

        else:
            errorMessageNoImage()
示例#7
0
    def imageStackOpened(self):

        # Add in a new tab
        self.parent.imageTabDisplay.newTab(self.image_class)

        # Do background correction if required
        if self.backgroundCorrectionCheckBox.isChecked():

            # Open the progress window
            openWindow(self.parent, ImageCorrectionProgressBarWindow,
                       'progress_bar')

            # Get the settings in memory
            do_median = self.parent.config.background_type == 'Median'
            do_division = self.parent.config.correction_type == 'Division'
            do_intensity_correction = self.parent.config.correct_intensity
            replace_tab = not self.parent.config.correct_newtab

            # Apply the background correction
            corrected_array = backgroundCorrection(
                self.image_class.image.source,
                median=do_median,
                divide=do_division)

            # Apply the intensity fluctuation correction - if required
            if do_intensity_correction:
                _intensity_correction_type = self.parent.config.intensity_correction_type.lower(
                )
                corrected_array = intensityCorrection(
                    corrected_array, correction=_intensity_correction_type)

            # Load the array in a file
            new_class = ImageCollection(corrected_array,
                                        name=self.image_class.name.strip() +
                                        ' (Corrected)',
                                        space_scale=self.parent.space_scale,
                                        space_unit=self.parent.space_unit,
                                        frame_rate=self.parent.frame_rate)

            # Update the current tab
            if replace_tab:
                # Get the current tab
                tab_id = self.parent.imageTabDisplay.currentIndex()

                # Update the tab
                new_class.name = self.image_class.name
                self.parent.imageTabDisplay.replaceTab(tab_id, new_class)

            # Create a new tab
            else:
                self.parent.imageTabDisplay.newTab(new_class)

            # Close the progress window
            self.parent.subWindows['progress_bar'].close()
            self.parent.application.processEvents()

        # Close the current window
        self.close()
示例#8
0
    def makeNewTracker(self):

        # Make a blank tracker
        blank_session = loadTrackerConfig('Default')
        blank_session = deepcopy(blank_session)

        # Open the window
        openWindow(self.parent,
                   TrackerSettingsWindow,
                   'tracker_settings',
                   detection_session=blank_session)
示例#9
0
    def processImage(self):

        # Retrieve the user selection
        do_division = self.correctionTypeComboBox.currentText() == 'Division'
        do_median = self.backgroundTypeComboBox.currentText() == 'Median'
        do_intensity_correction = self.correctFluctuationsCheckBox.isChecked()
        do_crop = self.cropCheckBox.isChecked()
        crop_size = int(self.cropSizeEntry.text())
        do_bit_correction = self.signCorrectionCheckBox.isChecked()
        replace_tab = self.replaceTabCheckBox.isChecked()

        # Crop the image - if required
        if do_crop:
            self.image_array = cropImage(self.image_array, (crop_size,crop_size))

        # Correct signed bits image - if required
        if do_bit_correction:
            self.image_array = correctSignedBits(self.image_array)

        # Open the progress window
        openWindow(self.parent, ImageCorrectionProgressBarWindow, 'progress_bar')

        # Apply the background correction
        self.image_array = backgroundCorrection(self.image_array, median=do_median, divide=do_division)

        # Apply the intensity fluctuation correction - if required
        if do_intensity_correction:
            self.image_array = intensityCorrection(self.image_array)

        # Get the current tab
        tab_id = self.parent.imageTabDisplay.currentIndex()
        old_class = self.parent.imageTabDisplay.displayedTabs[tab_id].image_class

        # Load the array in a file
        new_class = ImageCollection(self.image_array, name=old_class.name.strip()+' (Corrected)', space_scale=old_class.scale.space_scale, space_unit=old_class.scale.space_unit, frame_rate=old_class.scale.frame_rate)

        # Update the current tab
        if replace_tab:
            new_class.name = old_class.name
            self.parent.imageTabDisplay.replaceTab(tab_id, new_class)

        # Create a new tab
        else:
            self.parent.imageTabDisplay.newTab(new_class)

        # Close the progress window
        self.parent.subWindows['progress_bar'].close()
        self.parent.application.processEvents()

        # Close the window
        self.close()
示例#10
0
    def callBrightnessCorrection(self):

        # Check if a tab is open
        if len( self.parent.imageTabDisplay.displayedTabs ) > 0:

            # Get the current tab
            tab_id = self.parent.imageTabDisplay.currentIndex()
            crt_class = self.parent.imageTabDisplay.displayedTabs[tab_id].image_class

            # Open the window
            openWindow(self.parent, contrastCorrectionWindow, 'contrast_correction', image_class=crt_class)

        else:
            errorMessageNoImage()
示例#11
0
    def callSaveSingleFrame(self):

        # Check if a tab is open
        if len( self.parent.imageTabDisplay.displayedTabs ) > 0:

            # Get the current tab
            tab_id = self.parent.imageTabDisplay.currentIndex()
            crt_class = self.parent.imageTabDisplay.displayedTabs[tab_id].image_class

            # Open the save window
            openWindow(self.parent, saveSingleImageWindow, 'save_single', image_class=crt_class)

        else:
            errorMessageNoImage()
示例#12
0
    def editTracker(self, tracker_id=0):

        # Get the name of the tracker
        tracker_name = self.tracker_list[tracker_id]

        # Load the selected tracker
        tracker_session = loadTrackerConfig(tracker_name)
        tracker_session = deepcopy(tracker_session)

        # Open the window
        openWindow(self.parent,
                   TrackerSettingsWindow,
                   'tracker_settings',
                   detection_session=tracker_session)
示例#13
0
    def processParticleDetection(self):

        # Update the selection
        self.updateDetectionSession()

        # Process the whole stack
        if self.image_class.n_frames > 1:
            openWindow(self.parent,
                       stackDetectionSubWindow,
                       'particle_stack',
                       detection_session=self.trajectory_session)

        # Process a single frame
        else:

            # Get the current frame
            crt_frame = self.image_class.image.source[self.image_class.frame]
            crt_positions = self.detection_session.locate(crt_frame)

            # Format the trajectory
            crt_trajectory = generateTrajectory(crt_positions)

            # Save the trajectory in the class
            tab_id = self.parent.imageTabDisplay.currentIndex()
            self.parent.imageTabDisplay.displayedTabs[
                tab_id].image_class.trajectory = crt_trajectory

            # Close the window
            self.close()

            # Open the dock
            _open_dock = True
            if "tracking" in self.parent.docks.keys():
                if self.parent.docks["tracking"] is not None:
                    _open_dock = False

            if _open_dock:
                self.parent.docks["tracking"] = TrajectoryControlsPanel(
                    "Trajectory Controller", self.parent)
                self.parent.addDockWidget(qtc.Qt.RightDockWidgetArea,
                                          self.parent.docks["tracking"])

                # Set the size and attach the dock
                self.parent.docks["tracking"].setFloating(True)
                self.parent.docks["tracking"].detectLocationChange()
                self.parent.docks["tracking"].setFloating(False)

            # Refresh the display
            self.parent.imageTabDisplay.displayedTabs[tab_id].refreshPathList()
            self.parent.imageTabDisplay.displayedTabs[tab_id].displayImage()
示例#14
0
    def callCropCurrentImage(self):

        # Check if a tab is open
        if len( self.parent.imageTabDisplay.displayedTabs ) > 0:

            # Get the current tab
            tab_id = self.parent.imageTabDisplay.currentIndex()
            crt_class = self.parent.imageTabDisplay.displayedTabs[tab_id].image_class

            # Open the window
            openWindow(self.parent, imageCropWindow, 'crop_image', image_class=crt_class)

        else:
            errorMessageNoImage()
示例#15
0
    def getProperties(self):

        # Open the progress window
        openWindow(self.parent, ProcessSignalsProgressBarWindow,
                   'progress_bar')

        # Start the processing
        self.image_class.trajectory.signals = readSignals(
            self.image_class.image.source, self.image_class.trajectory)

        # Close the progress window
        self.parent.subWindows['progress_bar'].close()
        self.parent.application.processEvents()

        # Update the display
        self.populateTable()
示例#16
0
    def callSetScaleWindow(self):

        # Check if a tab is open
        if len(self.parent.imageTabDisplay.displayedTabs) > 0:

            # Get the current tab
            tab_id = self.parent.imageTabDisplay.currentIndex()
            crt_class = self.parent.imageTabDisplay.displayedTabs[
                tab_id].image_class

            # Call the window
            openWindow(self.parent,
                       SetScaleWindow,
                       'set_scale',
                       image_class=crt_class)

        else:
            errorMessageNoImage()
示例#17
0
    def callParticleDetectionWindow(self):

        # Check if a tab is open
        if len(self.parent.imageTabDisplay.displayedTabs) > 0:

            # Get the current tab
            tab_id = self.parent.imageTabDisplay.currentIndex()
            crt_class = self.parent.imageTabDisplay.displayedTabs[
                tab_id].image_class

            # Call the window
            openWindow(self.parent,
                       particleDetectionWindow,
                       'particle_analysis',
                       image_class=crt_class)

        else:
            errorMessageNoImage()
示例#18
0
    def callSeekMetadataWindow(self):

        # Get the metadata
        metadataFolder = qtw.QFileDialog.getExistingDirectory(self.parent, "Search in folder...")

        # Open the window if a folder has been selected
        if metadataFolder:

            # List all files
            data_files = [ x for x in Path(metadataFolder).rglob('*.xml') ]

            # Raise an error if no files could be found
            if len(data_files) == 0:
                pass # NOTE: Add error message here

            # Open the file
            else:
                openWindow(self.parent, seekMetadataPopup, 'seek_metadata_popup', files_list=data_files)
示例#19
0
    def correctFluctuations(self):

        # Get the settings
        correction_type = self.correctionSelectionBox.currentText().lower()

        # Check the fluctuations values
        do_correction = True
        if self.variations_value < 0.01:
            do_correction = warningProceedMessage(
                'Low intensity fluctuations',
                'The measured intensity fluctuations are below 0.01% of the mean intensity. Performing a correction might not improve the quality of the signal. Proceed anyway?'
            )

        # Do the correction if accepted
        if do_correction:

            # Open the progress window
            openWindow(self.parent, ImageCorrectionProgressBarWindow,
                       'progress_bar')

            self.image_array = intensityCorrection(self.image_array,
                                                   correction=correction_type)

            # Get the current tab
            tab_id = self.parent.imageTabDisplay.currentIndex()
            use_name = self.parent.imageTabDisplay.displayedTabs[
                tab_id].image_class.name

            # Load the array in a file
            new_class = ImageCollection(self.image_array,
                                        name=use_name,
                                        space_scale=self.parent.space_scale,
                                        space_unit=self.parent.space_unit,
                                        frame_rate=self.parent.frame_rate)

            # Refresh the tab
            self.parent.imageTabDisplay.replaceTab(tab_id, new_class)

            # Close the progress window
            self.parent.subWindows['progress_bar'].close()
            self.parent.application.processEvents()

        # Close the window
        self.close()
示例#20
0
    def callIntensityFluctuations(self):

        # Check if a tab is open
        if len( self.parent.imageTabDisplay.displayedTabs ) > 0:

            # Get the current tab
            tab_id = self.parent.imageTabDisplay.currentIndex()
            crt_class = self.parent.imageTabDisplay.displayedTabs[tab_id].image_class
            n_frames = crt_class.n_frames

            # Check if there is more than one image in the stack
            if n_frames > 1:
                openWindow(self.parent, fluctuationCorrectionWindow, 'fluctuations_correction', image_array=crt_class.image.source)

            else:
                errorMessageNoStack()

        else:
            errorMessageNoImage()
示例#21
0
    def callFrameAveraging(self):

        # Check if a tab is open
        if len( self.parent.imageTabDisplay.displayedTabs ) > 0:

            # Get the current tab
            tab_id = self.parent.imageTabDisplay.currentIndex()
            crt_class = self.parent.imageTabDisplay.displayedTabs[tab_id].image_class
            n_frames = crt_class.n_frames

            # Check if there is more than one image in the stack
            if n_frames > 1:
                openWindow(self.parent, frameAveragingWindow, 'frame_average', image_array=crt_class.image.source)

            else:
                errorMessageNoStack()

        else:
            errorMessageNoImage()
示例#22
0
    def readAndLoadFiles(self):

        # Replace the display
        self.changeToProgressBar()
        self.parent.application.processEvents()

        # Get the type of file to read
        file_type = self.dataTypeComboBox.currentText()
        file_type = self.type_dict[file_type]

        # Process all the files
        selected_files = {}
        for i, file_path in enumerate(self.all_files):

            # Read the file
            try:
                current_type, current_content = readMetadataFile(file_path)

                # Add to the list
                if current_type == file_type:
                    selected_files[file_path] = current_content
            except:
                pass

            # Update the status of the progress bar
            self.updateProgressBar(i + 1)
            self.parent.application.processEvents()

        # Open the new window
        if len(list(selected_files.keys())) == 0:
            pass  # NOTE: Add error message here

        else:
            openWindow(self.parent,
                       seekMetadataWindow,
                       'seek_metadata',
                       metadata_type=file_type,
                       file_contents=selected_files)

        # Close the window
        self.close()
示例#23
0
    def callCenterCropWindow(self):

        # Check if a tab is open
        if len(self.parent.imageTabDisplay.displayedTabs) > 0:

            # Get the current tab
            tab_id = self.parent.imageTabDisplay.currentIndex()
            crt_class = self.parent.imageTabDisplay.displayedTabs[
                tab_id].image_class

            # Check if there is a trajectory
            if crt_class.trajectory is not None:

                # Get the selection from the dock
                if self.parent.docks["tracking"] is not None:
                    _path_id = self.parent.docks[
                        "tracking"].pathSelectionEntry.comboBox.currentText()
                else:
                    _path_id = 'All'

                # Prompt the user if a specific path is not selected
                is_ok = True
                if _path_id == 'All':
                    path_list = crt_class.trajectory.listTracks().astype(str)
                    _path_id, is_ok = qtw.QInputDialog.getItem(
                        self.parent, 'Path Selection', 'Path to Center on:',
                        path_list, 0, False)

                if is_ok:
                    openWindow(self.parent,
                               cropCenterWindow,
                               'crop_center',
                               image_class=crt_class,
                               path_id=int(_path_id))

            else:
                errorMessageNoTrajectory()

        else:
            errorMessageNoImage()
示例#24
0
    def getImageFromPath(self):

        # Get the name of the file
        _, image_name = os.path.split(self.image_path)

        # Get the correction to apply
        _do_crop = self.cropCheckBox.isChecked()
        _crop_size = int(self.cropSizeEntry.text())
        _do_sign_correction = self.signCorrectionCheckBox.isChecked()
        _start, _end = self.frameRangeSelection.getRange()
        _open_range = _start - 1, _end

        # Check the crop size
        _proceed = True
        if _do_crop:
            if _crop_size > np.amin(
                [self.image_infos['size'][0], self.image_infos['size'][1]]):
                errorMessage(
                    'Cropping Error',
                    'The requested crop size is greater than the image size.')
                _proceed = False

        # Load the image
        if _proceed:
            self.image_class = None

            # Open the progress bar window
            openWindow(self.parent,
                       OpenImageProgressBarWindow,
                       'progress_bar',
                       image_path=self.image_path,
                       name=image_name,
                       open_range=_open_range,
                       crop=_do_crop,
                       crop_size=_crop_size,
                       correct_sign=_do_sign_correction,
                       scheduler=self)

            # Add the image to the list of recent items
            appendRecentFiles(self.image_path)
示例#25
0
    def callSignalAnalysisWindow(self):

        # Check if a tab is open
        if len(self.parent.imageTabDisplay.displayedTabs) > 0:

            # Get the current tab
            tab_id = self.parent.imageTabDisplay.currentIndex()
            crt_class = self.parent.imageTabDisplay.displayedTabs[
                tab_id].image_class

            # Check if there is a trajectory
            if crt_class.trajectory is not None:
                openWindow(self.parent,
                           analyseSignalWindow,
                           'measure_signals',
                           image_class=crt_class)

            else:
                errorMessageNoTrajectory()

        else:
            errorMessageNoImage()
示例#26
0
    def processAveraging(self):

        # Get the averaging parameters
        avg_type = self.averagingTypeComboBox.currentText()
        n_frames = int(self.numberFrameEntry.text())
        include_partial = self.partialDataCheckBox.isChecked()

        # Convert the average type
        type_conversion = {
            "Standard Average": 'block',
            "Running Average": 'running',
        }
        avg_type = type_conversion[avg_type]

        # Open the progress bar window
        openWindow(self.parent,
                   AverageImageProgressBarWindow,
                   'progress_bar',
                   image_class=self.image_array,
                   window=n_frames,
                   average_type=avg_type,
                   include_partial=include_partial,
                   scheduler=self)
示例#27
0
    def callSaveStack(self):

        # Check if a tab is open
        if len(self.parent.imageTabDisplay.displayedTabs) > 0:

            # Get the current tab
            tab_id = self.parent.imageTabDisplay.currentIndex()
            crt_class = self.parent.imageTabDisplay.displayedTabs[
                tab_id].image_class
            n_frames = crt_class.n_frames

            # Check if there is more than one image in the stack
            if n_frames > 1:
                openWindow(self.parent,
                           saveImageStackWindow,
                           'save_frame',
                           image_class=crt_class)

            else:
                errorMessageNoStack()

        else:
            errorMessageNoImage()
示例#28
0
 def callConvertFolderWindow(self):
     openWindow(self.parent, convertStackWindow, 'convert_stacks')
示例#29
0
 def callTrackerManagerWindow(self):
     openWindow(self.parent, TrackerManagerWindow, 'tracker_manager')
示例#30
0
    def processAveraging(self):

        # Get the information
        path_id = int( self.pathSelectionBox.currentText() )
        average_type = self.averagingTypeComboBox.currentText()
        min_avg, max_avg = self.frameRangeSelection.getRange()

        # Get the position to process
        crt_position = self.image_class.trajectory.positions
        crt_position = crt_position[crt_position['particle'] == path_id]
        _all_frames = crt_position['frame'].unique()
        object_position = crt_position[crt_position['frame'] == np.amin(_all_frames)]
        object_position = object_position[['y','x']].to_numpy()
        object_position = object_position[0]

        # Get the type of average
        type_conversion = {
        "Standard Average":'block',
        "Running Average":'running',
        }
        average_type = type_conversion[average_type]

        # Initialise the variables
        all_n_avg = []
        all_contrast = []
        all_noise = []
        all_snr = []

        # Open the progress window
        openWindow(self.parent, AnalyseAveragingProgressBarWindow, 'progress_bar')

        # Do the loop
        n_avg = (max_avg-min_avg)+1
        for i, n_frames in enumerate( range(min_avg, max_avg+1) ):

            # Update the progress bar
            self.parent.subWindows['progress_bar'].updateProgress(i+1, n_avg)
            self.parent.application.processEvents()

            print( str(i+1)+'/'+str(n_avg) )

            # Do the current averaging
            crt_average = averageStack(self.image_class.image.source, n_frames, average_type=average_type, include_partial=False, quiet=True)
            crt_frame = crt_average[0:2]

            # Measure the signal
            crt_profile = readSingle(crt_frame, object_position)

            # Save the values
            all_n_avg.append( n_frames )
            all_contrast.append( crt_profile['contrast'][0] )
            all_noise.append( crt_profile['noise'][0] )
            all_snr.append( crt_profile['snr'][0] )

        # Close the progress window
        self.parent.subWindows['progress_bar'].close()
        self.parent.application.processEvents()

        # Save in the memory
        self.averaging_result = {
        'averaged frames':all_n_avg,
        'contrast':all_contrast,
        'noise':all_noise,
        'snr':all_snr,
        }

        # Display the results
        self.plotFluctuations()

        # Update the display
        self.saveButton.setEnabled( True )