Example #1
0
    def averageCompleted(self, averaged_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(averaged_array,
                                    name=old_class.name.strip() +
                                    ' (Averaged)',
                                    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 self.replaceTabCheckBox.isChecked():
            new_class.name = old_class.name
            self.parent.imageTabDisplay.replaceTab(tab_id, new_class)
            self.parent.animationControl.setNFrames(new_class.n_frames)

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

        # Close the window
        self.close()
Example #2
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()
Example #3
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()
Example #4
0
    def applyCrop(self):

        # Get the final crop value
        crop_size = int(self.sizeEntry.text())

        # Crop the array
        array = centerCrop(self.image_class.image.source,
                           self.image_class.trajectory, self.path_id)
        new_array = cropImage(array, (crop_size, crop_size))

        # Prepare the new array
        new_name = self.image_class.name + ' (' + str(self.path_id) + ')'
        space_scale = self.image_class.scale.space_scale
        space_unit = self.image_class.scale.space_unit
        frame_rate = self.image_class.scale.frame_rate

        # Generate the class
        new_class = ImageCollection(new_array,
                                    name=new_name,
                                    space_scale=space_scale,
                                    space_unit=space_unit,
                                    frame_rate=frame_rate)

        # Open the new tab
        self.parent.imageTabDisplay.newTab(new_class)

        # Close the image
        self.close()
Example #5
0
    def substackTab(self, tab_id=0):

        # Get the user selection
        _frame_text = """Enter a range (e.g. 2-14), a range with increment
(e.g. 1-100-2) or a list (e.g. 7,9,25,27)"""
        selection, is_ok = qtw.QInputDialog.getText(self.parent,
                                                    'Substack Maker',
                                                    _frame_text,
                                                    text="")

        if is_ok:

            # Convert the input into a list of frames
            selected_frames = getSubstackSelection(selection)

            # Get the previous array
            old_array = self.displayedTabs[tab_id].image_class.image.source
            old_class = self.displayedTabs[tab_id].image_class

            # Make the new frame selection
            substack_array = makeSubstack(old_array, selected_frames)

            # Get the new class name
            old_name = old_class.name.strip() + " (substack)"
            new_name, is_ok = qtw.QInputDialog.getText(self,
                                                       'Copy Tab',
                                                       'Enter the new name:',
                                                       text=old_name)
            if not is_ok:
                new_name = old_name

            # Make a new class and replace the values
            new_class = ImageCollection(substack_array, name=new_name)
            new_class.scale = old_class.scale
            new_class.zoom = old_class.zoom
            new_class.contrast_limits = old_class.contrast_limits
            new_class.bitness = old_class.bitness

            # Prepare the image for display
            new_class.rescaleForDisplay()

            # Add the trajectory if needed
            if old_class.trajectory is not None:
                new_trajectory = substackTrajectory(old_class.trajectory,
                                                    selected_frames)
                new_class.trajectory = new_trajectory

            # Create the new tab
            self.newTab(new_class)
Example #6
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()
Example #7
0
    def cropImage(self):

        # Raise an error if there is no selection
        if self.selection_pointA is None or self.selection_pointB is None:
            errorMessage("No Selection",
                         "A selection is required to crop the image.")

        # Crop the image
        else:

            # Get the selection
            selection = qtc.QRect(self.selection_pointA, self.selection_pointB)
            origin = int(selection.x() / self.zoom), int(selection.y() /
                                                         self.zoom)
            dimensions = int(selection.width() / self.zoom), int(
                selection.height() / self.zoom)

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

            # Crop the array
            new_array = cropImage(old_class.image.source,
                                  dimensions,
                                  origin=origin)

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

            # Replace the array in the tab
            self.parent.imageTabDisplay.replaceTab(tab_id, new_class)

            # Close the image
            self.close()
Example #8
0
def loadImages(file_path,
               name='Untitled',
               open_range=None,
               crop=False,
               crop_size=152,
               correct_sign=False,
               space_scale=44.9,
               space_unit="micron",
               frame_rate=150):

    # Open the image array
    image_array = _open_image(file_path, open_range=open_range)

    # Load the array in the class
    image_instance = ImageCollection(image_array,
                                     name=name,
                                     crop=crop,
                                     crop_size=crop_size,
                                     correct_sign=correct_sign,
                                     space_scale=space_scale,
                                     space_unit=space_unit,
                                     frame_rate=frame_rate)
    return image_instance