Example #1
0
    def __init__(self, *args, **kwargs):
        clickpoints.Addon.__init__(self, *args, **kwargs)
        # set the title and layout
        self.setWindowTitle("Fine Contrast Adjust - ClickPoints")
        self.layout = QtWidgets.QVBoxLayout(self)

        # add a plot widget
        self.plot = MatplotlibWidget(self)
        self.layout.addWidget(self.plot)
        self.layout.addWidget(NavigationToolbar(self.plot, self))

        self.hist_plot, = self.plot.axes.plot([], [])
        self.vline1, = self.plot.axes.plot([], [], color="r")
        self.vline2, = self.plot.axes.plot([], [], color="m")

        self.slider = QtWidgets.QSlider()
        self.slider.setOrientation(QtCore.Qt.Horizontal)
        self.layout.addWidget(self.slider)
        self.slider.valueChanged.connect(self.setValue)

        self.slider2 = QtWidgets.QSlider()
        self.slider2.setOrientation(QtCore.Qt.Horizontal)
        self.layout.addWidget(self.slider2)
        self.slider2.valueChanged.connect(self.setValue2)
Example #2
0
    def __init__(self, *args, **kwargs):
        clickpoints.Addon.__init__(self, *args, **kwargs)
        # set the title and layout
        self.setWindowTitle("Kymograph - ClickPoints")
        self.layout = QtWidgets.QVBoxLayout(self)

        # add some options
        # the frame number for the kymograph
        self.addOption(key="frames",
                       display_name="Frames",
                       default=50,
                       value_type="int",
                       tooltip="How many images to use for the kymograph.")
        self.input_count = AddQSpinBox(self.layout,
                                       "Frames:",
                                       value=self.getOption("frames"),
                                       float=False)
        self.linkOption("frames", self.input_count)

        # the with in pixel of each line
        self.addOption(key="width",
                       display_name="Width",
                       default=1,
                       value_type="int",
                       tooltip="The width of the slice to cut from the image.")
        self.input_width = AddQSpinBox(self.layout,
                                       "Width:",
                                       value=self.getOption("width"),
                                       float=False)
        self.linkOption("width", self.input_width)

        # the length scaling
        self.addOption(key="scaleLength",
                       display_name="Scale Length",
                       default=1,
                       value_type="float",
                       tooltip="What is distance a pixel represents.")
        self.input_scale1 = AddQSpinBox(self.layout,
                                        "Scale Length:",
                                        value=self.getOption("scaleLength"),
                                        float=True)
        self.linkOption("scaleLength", self.input_scale1)

        # the time scaling
        self.addOption(
            key="scaleTime",
            display_name="Scale Time",
            default=1,
            value_type="float",
            tooltip="What is the time difference between two images.")
        self.input_scale2 = AddQSpinBox(self.layout,
                                        "Scale Time:",
                                        value=self.getOption("scaleTime"),
                                        float=True)
        self.linkOption("scaleTime", self.input_scale2)

        # the colormap
        self.addOption(key="colormap",
                       display_name="Colormap",
                       default="None",
                       value_type="string",
                       tooltip="The colormap to use for the kymograph.")
        maps = ["None"]
        maps.extend(plt.colormaps())
        self.input_colormap = AddQComboBox(
            self.layout,
            "Colormap:",
            selectedValue=self.getOption("colormap"),
            values=maps)
        self.input_colormap.setEditable(True)
        self.linkOption("colormap", self.input_colormap)

        # the table listing the line objects
        self.tableWidget = QtWidgets.QTableWidget(0, 1, self)
        self.layout.addWidget(self.tableWidget)
        self.row_headers = ["Line Length"]
        self.tableWidget.setHorizontalHeaderLabels(self.row_headers)
        self.tableWidget.setMinimumHeight(180)
        self.setMinimumWidth(500)
        self.tableWidget.setCurrentCell(0, 0)
        self.tableWidget.cellClicked.connect(self.cellSelected)

        # add kymograph types
        self.my_type = self.db.setMarkerType("kymograph",
                                             "#ef7fff",
                                             self.db.TYPE_Line,
                                             text="#$marker_id")
        self.my_type2 = self.db.setMarkerType("kymograph_end", "#df00ff",
                                              self.db.TYPE_Normal)
        self.cp.reloadTypes()

        # add a plot widget
        self.plot = MatplotlibWidget(self)
        self.layout.addWidget(self.plot)
        self.layout.addWidget(NavigationToolbar(self.plot, self))
        self.plot.figure.canvas.mpl_connect('button_press_event',
                                            self.button_press_callback)

        # add export buttons
        layout = QtWidgets.QHBoxLayout()
        self.button_export = QtWidgets.QPushButton("Export")
        self.button_export.clicked.connect(self.export)
        layout.addWidget(self.button_export)
        self.button_export2 = QtWidgets.QPushButton("Export All")
        self.button_export2.clicked.connect(self.export2)
        layout.addWidget(self.button_export2)
        self.layout.addLayout(layout)

        # add a progress bar
        self.progressbar = QtWidgets.QProgressBar()
        self.layout.addWidget(self.progressbar)

        # connect slots
        self.signal_update_plot.connect(self.updatePlotImageEvent)
        self.signal_plot_finished.connect(self.plotFinishedEvent)

        # initialize the table
        self.updateTable()
        self.selected = None
Example #3
0
    def __init__(self, *args, **kwargs):
        clickpoints.Addon.__init__(self, *args, **kwargs)

        # qthread and signals for update cell detection and loading ellipse at add on launch
        self.thread = Worker(run_function=None)
        self.thread.thread_started.connect(self.start_pbar)
        self.thread.thread_finished.connect(self.finish_pbar)
        self.thread.thread_progress.connect(self.update_pbar)

        self.stop = False
        self.plot_data = np.array([[], []])
        self.unet = None
        self.layout = QtWidgets.QVBoxLayout(self)

        # Setting up marker Types
        self.marker_type_cell1 = self.db.setMarkerType("cell", "#0a2eff",
                                                       self.db.TYPE_Ellipse)
        self.marker_type_cell2 = self.db.setMarkerType("cell new", "#Fa2eff",
                                                       self.db.TYPE_Ellipse)
        self.cp.reloadTypes()

        # finding and setting path to store network probability map
        self.prob_folder = os.environ["CLICKPOINTS_TMP"]
        self.prob_path = self.db.setPath(self.prob_folder)
        self.prob_layer = self.db.setLayer("prob_map")

        clickpoints.Addon.__init__(self, *args, **kwargs)

        # set the title and layout
        self.setWindowTitle("DeformationCytometer - ClickPoints")
        self.layout = QtWidgets.QVBoxLayout(self)

        # weight file selection
        self.weight_selection = SetFile(store_path,
                                        filetype="weight file (*.h5)")
        self.weight_selection.fileSeleted.connect(self.initUnet)
        self.layout.addLayout(self.weight_selection)

        # update segmentation
        # in range of frames
        seg_layout = QtWidgets.QHBoxLayout()
        self.update_detection_button = QtWidgets.QPushButton(
            "update cell detection")
        self.update_detection_button.setToolTip(
            tooltip_strings["update cell detection"])
        self.update_detection_button.clicked.connect(
            partial(self.start_threaded, self.detect_all))
        seg_layout.addWidget(self.update_detection_button, stretch=5)
        # on single frame
        self.update_single_detection_button = QtWidgets.QPushButton(
            "single detection")
        self.update_single_detection_button.setToolTip(
            tooltip_strings["single detection"])
        self.update_single_detection_button.clicked.connect(self.detect_single)
        seg_layout.addWidget(self.update_single_detection_button, stretch=1)
        self.layout.addLayout(seg_layout)

        # regularity and solidity thresholds
        validator = QtGui.QDoubleValidator(0, 100, 3)
        filter_layout = QtWidgets.QHBoxLayout()
        reg_label = QtWidgets.QLabel("irregularity")
        filter_layout.addWidget(reg_label)
        self.reg_box = QtWidgets.QLineEdit("1.06")
        self.reg_box.setToolTip(tooltip_strings["irregularity"])
        self.reg_box.setValidator(validator)
        filter_layout.addWidget(self.reg_box,
                                stretch=1)  # TODO implement text edited method
        sol_label = QtWidgets.QLabel("solidity")
        filter_layout.addWidget(sol_label)
        self.sol_box = QtWidgets.QLineEdit("0.96")
        self.sol_box.setToolTip(tooltip_strings["solidity"])
        self.sol_box.setValidator(validator)
        filter_layout.addWidget(self.sol_box, stretch=1)
        rmin_label = QtWidgets.QLabel("min radius [µm]")
        filter_layout.addWidget(rmin_label)
        self.rmin_box = QtWidgets.QLineEdit("6")
        self.rmin_box.setToolTip(tooltip_strings["min radius"])
        self.rmin_box.setValidator(validator)
        filter_layout.addWidget(self.rmin_box, stretch=1)
        filter_layout.addStretch(stretch=4)
        self.layout.addLayout(filter_layout)

        # plotting buttons
        layout = QtWidgets.QHBoxLayout()
        self.button_stressstrain = QtWidgets.QPushButton("stress-strain")
        self.button_stressstrain.clicked.connect(self.plot_stress_strain)
        self.button_stressstrain.setToolTip(tooltip_strings["stress-strain"])
        layout.addWidget(self.button_stressstrain)
        self.button_kpos = QtWidgets.QPushButton("k-pos")
        self.button_kpos.clicked.connect(self.plot_k_pos)
        self.button_kpos.setToolTip(tooltip_strings["k-pos"])
        layout.addWidget(self.button_kpos)
        self.button_reg_sol = QtWidgets.QPushButton("regularity-solidity")
        self.button_reg_sol.clicked.connect(self.plot_irreg)
        self.button_reg_sol.setToolTip(tooltip_strings["regularity-solidity"])
        layout.addWidget(self.button_reg_sol)
        self.button_kHist = QtWidgets.QPushButton("k histogram")
        self.button_kHist.clicked.connect(self.plot_kHist)
        self.button_kHist.setToolTip(tooltip_strings["k histogram"])
        layout.addWidget(self.button_kHist)
        self.button_alphaHist = QtWidgets.QPushButton("alpha histogram")
        self.button_alphaHist.clicked.connect(self.plot_alphaHist)
        self.button_alphaHist.setToolTip(tooltip_strings["alpha histogram"])
        layout.addWidget(self.button_alphaHist)
        self.button_kalpha = QtWidgets.QPushButton("k-alpha")
        self.button_kalpha.clicked.connect(self.plot_k_alpha)
        self.button_kalpha.setToolTip(tooltip_strings["k-alpha"])
        layout.addWidget(self.button_kalpha)
        # button to switch between display of loaded and newly generated data
        frame = QtWidgets.QFrame()  # horizontal separating line
        frame.setFrameShape(QtWidgets.QFrame.VLine)
        frame.setLineWidth(3)
        layout.addWidget(frame)
        self.switch_data_button = QtWidgets.QPushButton(
            self.disp_text_existing)
        self.switch_data_button.clicked.connect(self.switch_display_data)
        self.switch_data_button.setToolTip(
            tooltip_strings[self.disp_text_existing])
        layout.addWidget(self.switch_data_button)
        self.layout.addLayout(layout)

        # matplotlib widgets to draw plots
        self.plot = MatplotlibWidget(self)
        self.plot_data = np.array([[], []])
        self.layout.addWidget(self.plot)
        self.layout.addWidget(NavigationToolbar(self.plot, self))
        self.plot.figure.canvas.mpl_connect('button_press_event',
                                            self.button_press_callback)

        # progress bar
        self.progressbar = QtWidgets.QProgressBar()
        self.layout.addWidget(self.progressbar)
        # progressbar lable
        pbar_info_layout = QtWidgets.QHBoxLayout()
        self.pbarLable = QtWidgets.QLabel("")
        pbar_info_layout.addWidget(self.pbarLable, stretch=1)
        pbar_info_layout.addStretch(stretch=2)
        # button to stop thread execution
        self.stop_button = QtWidgets.QPushButton("stop")
        self.stop_button.clicked.connect(self.quit_thread)
        self.stop_button.setToolTip(tooltip_strings["stop"])
        pbar_info_layout.addWidget(self.stop_button, stretch=1)
        self.layout.addLayout(pbar_info_layout)

        # setting paths for data, config and image
        # identifying the full path to the video. If an existing ClickPoints database is opened, the path if
        # is likely relative to the database location.
        self.filename = self.db.getImage(0).get_full_filename()
        if not os.path.isabs(self.filename):
            self.filename = str(
                Path(self.db._database_filename).parent.joinpath(
                    Path(self.filename)))

        self.config_file = self.constructFileNames("_config.txt")
        self.result_file = self.constructFileNames("_result.txt")
        self.addon_result_file = self.constructFileNames("_addon_result.txt")
        self.addon_evaluated_file = self.constructFileNames(
            "_addon_evaluated.csv")
        self.addon_config_file = self.constructFileNames("_addon_config.txt")
        self.vidcap = imageio.get_reader(self.filename)

        # reading in config an data
        self.data_all_existing = pd.DataFrame()
        self.data_mean_existing = pd.DataFrame()
        self.data_all_new = pd.DataFrame()
        self.data_mean_new = pd.DataFrame()
        if self.config_file.exists() and self.result_file.exists():
            self.config = getConfig(self.config_file)
            # ToDo: replace with a flag// also maybe some sort of "reculation" feature
            # Trying to get regularity and solidity from the config
            if "irregularity" in self.config.keys(
            ) and "solidity" in self.config.keys():
                solidity_threshold = self.config["solidity"]
                irregularity_threshold = self.config["irregularity"]
            else:
                solidity_threshold = self.sol_threshold
                irregularity_threshold = self.reg_threshold
            # reading unfiltered data (from results.txt) and data from evaluated.csv
            # unfiltered data (self.data_all_existing) is used to display regularity and solidity scatter plot
            # everything else is from evaluated.csv (self.data_mean_existing)
            self.data_all_existing, self.data_mean_existing = self.load_data(
                self.result_file, solidity_threshold, irregularity_threshold)
        else:  # get a default config if no config is found
            self.config = getConfig(default_config_path)

        ## loading data from previous addon action
        if self.addon_result_file.exists():
            self.data_all_new, self.data_mean_new = self.load_data(
                self.addon_result_file, self.sol_threshold, self.reg_threshold)
            self.start_threaded(
                partial(self.display_ellipses,
                        type=self.marker_type_cell2,
                        data=self.data_all_new))
        # create an addon config file
        # presence of this file allows easy implementation of the load_data and tank threading pipelines when
        # calculating new data
        if not self.addon_config_file.exists():
            shutil.copy(self.config_file, self.addon_config_file)

        self.plot_data_frame = self.data_all
        # initialize plot
        self.plot_stress_strain()

        # Displaying the loaded cells. This is in separate thread as it takes up to 20 seconds.
        self.db.deleteEllipses(type=self.marker_type_cell1)
        self.db.deleteEllipses(type=self.marker_type_cell2)
        self.start_threaded(
            partial(self.display_ellipses,
                    type=self.marker_type_cell1,
                    data=self.data_all_existing))

        print("loading finished")
Example #4
0
    def __init__(self, *args, **kwargs):
        clickpoints.Addon.__init__(self, *args, **kwargs)

        # set the title and layout
        self.setWindowTitle("Fluorescence Diffusion - ClickPoints")
        self.layout = QtWidgets.QVBoxLayout(self)

        self.addOption(key="delta_t",
                       display_name="Delta t",
                       default=2,
                       value_type="float")
        self.addOption(key="color_channel",
                       display_name="Color Channel",
                       default=1,
                       value_type="int")
        self.addOption(key="output_folder",
                       display_name="Output Folder",
                       default="output",
                       value_type="string")

        # create a line type "connect"
        if not self.db.getMarkerType("connect"):
            self.db.setMarkerType("connect", [0, 255, 255], self.db.TYPE_Line)
            self.cp.reloadTypes()

        self.layout_intensity = QtWidgets.QHBoxLayout()
        self.layout.addLayout(self.layout_intensity)

        self.layout_intensity1 = QtWidgets.QVBoxLayout()
        self.layout_intensity.addLayout(self.layout_intensity1)

        self.input_delta_t = AddQSpinBox(self.layout_intensity1,
                                         "Delta T:",
                                         value=self.getOption("delta_t"),
                                         float=True)
        self.input_delta_t.setSuffix(" s")
        self.linkOption("delta_t", self.input_delta_t)

        self.input_color = AddQSpinBox(self.layout_intensity1,
                                       "Color Channel:",
                                       value=self.getOption("color_channel"),
                                       float=False)
        self.linkOption("color_channel", self.input_color)

        self.button_update = QtWidgets.QPushButton("Calculate Intensities")
        self.layout_intensity1.addWidget(self.button_update)
        self.button_update.clicked.connect(self.updateIntensities)

        # the table listing the line objects
        self.tableWidget = QtWidgets.QTableWidget(0, 1, self)
        self.layout_intensity1.addWidget(self.tableWidget)

        self.layout_intensity_plot = QtWidgets.QVBoxLayout()
        self.layout_intensity.addLayout(self.layout_intensity_plot)
        self.plot_intensity = MatplotlibWidget(self)
        self.layout_intensity_plot.addWidget(self.plot_intensity)
        self.layout_intensity_plot.addWidget(
            NavigationToolbar(self.plot_intensity, self))

        self.layout.addWidget(AddHLine())

        self.layout_diffusion = QtWidgets.QHBoxLayout()
        self.layout.addLayout(self.layout_diffusion)

        self.layout_diffusion1 = QtWidgets.QVBoxLayout()
        self.layout_diffusion.addLayout(self.layout_diffusion1)

        self.button_calculate = QtWidgets.QPushButton("Calculate Diffusion")
        self.layout_diffusion1.addWidget(self.button_calculate)
        self.button_calculate.clicked.connect(self.calculateDiffusion)

        # the table listing the line objects
        self.tableWidget2 = QtWidgets.QTableWidget(0, 1, self)
        self.layout_diffusion1.addWidget(self.tableWidget2)

        self.layout_diffusion_plot = QtWidgets.QVBoxLayout()
        self.layout_diffusion.addLayout(self.layout_diffusion_plot)
        self.plot_diffusion = MatplotlibWidget(self)
        self.layout_diffusion_plot.addWidget(self.plot_diffusion)
        self.layout_diffusion_plot.addWidget(
            NavigationToolbar(self.plot_diffusion, self))

        # add a progress bar
        self.progressbar = QtWidgets.QProgressBar()
        self.layout.addWidget(self.progressbar)

        self.diffusionConstants = []
Example #5
0
    def __init__(self, *args, **kwargs):
        clickpoints.Addon.__init__(self, *args, **kwargs)

        self.layout = QtWidgets.QVBoxLayout(self)

        # Check if the marker type is present
        self.marker_type_cell = self.db.setMarkerType("cell", "#0a2eff",
                                                      self.db.TYPE_Ellipse)
        self.marker_type_cell2 = self.db.setMarkerType("cell2", "#Fa2eff",
                                                       self.db.TYPE_Ellipse)
        self.cp.reloadTypes()

        self.loadData()

        clickpoints.Addon.__init__(self, *args, **kwargs)
        # set the title and layout
        self.setWindowTitle("DeformationCytometer - ClickPoints")
        self.layout = QtWidgets.QVBoxLayout(self)

        # add export buttons
        layout = QtWidgets.QHBoxLayout()
        self.button_stressstrain = QtWidgets.QPushButton("stress-strain")
        self.button_stressstrain.clicked.connect(self.plot_stress_strain)
        layout.addWidget(self.button_stressstrain)

        self.button_stressy = QtWidgets.QPushButton("y-strain")
        self.button_stressy.clicked.connect(self.plot_y_strain)
        layout.addWidget(self.button_stressy)

        self.button_y_angle = QtWidgets.QPushButton("y-angle")
        self.button_y_angle.clicked.connect(self.plot_y_angle)
        layout.addWidget(self.button_y_angle)

        self.layout.addLayout(layout)

        # add a plot widget
        self.plot = MatplotlibWidget(self)
        self.layout.addWidget(self.plot)
        self.layout.addWidget(NavigationToolbar(self.plot, self))
        self.plot.figure.canvas.mpl_connect('button_press_event',
                                            self.button_press_callback)

        # add a progress bar
        self.progressbar = QtWidgets.QProgressBar()
        self.layout.addWidget(self.progressbar)

        # connect slots
        # self.signal_update_plot.connect(self.updatePlotImageEvent)
        # self.signal_plot_finished.connect(self.plotFinishedEvent)

        # initialize the table
        # self.updateTable()
        # self.selected = None

        filename = self.db.getImage(0).get_full_filename()
        print(filename.replace(".tif", "_config.txt"))
        self.config = getConfig(filename.replace(".tif", "_config.txt"))
        self.data = getData(filename.replace(".tif", "_result.txt"))

        getVelocity(self.data, self.config)

        try:
            correctCenter(self.data, self.config)
        except ValueError:
            pass

        self.data = self.data.groupby(['cell_id']).mean()

        self.data = filterCells(self.data, self.config)
        self.data.reset_index(drop=True, inplace=True)

        getStressStrain(self.data, self.config)