Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- VolPy GUI interface is used to correct outputs of Mask R-CNN or annotate new datasets.
- VolPy GUI uses summary images and ROIs as the input. It outputs binary masks for the trace denoising
- and spike extraction step of VolPy.
- @author: @caichangjia
- """
- # These imports apparently must come before importing pyqtgraph on some platforms
- import PySide6
- from PySide6 import QtWidgets
- from PySide6.QtWidgets import QApplication
- from PySide6.QtGui import QShortcut
- import numpy as np
- import os
- from pathlib import Path
- import pyqtgraph as pg
- from pyqtgraph import FileDialog
- from pyqtgraph.Qt import QtGui
- from pyqtgraph.parametertree import Parameter, ParameterTree
- import random
- from skimage.draw import polygon
- import sys
- os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = os.fspath(
- Path(PySide6.__file__).resolve().parent / "Qt5" / "plugins")
- def release(event):
- pass
- def move(event):
- pass
- def add():
- pass
- def remove():
- pass
- def show_all():
- pass
- def clear():
- pass
- def show_neuron():
- pass
- def load():
- pass
- def load_rois():
- pass
- def save():
- pass
- def change(param, changes):
- pass
- def down():
- pass
- def up():
- pass
- def adjust_contrast(img, min_value, max_value):
- pass
- def overlay(all_ROIs):
- pass
- if __name__ == "__main__":
- ## Always start by initializing Qt (only once per application)
- app = QApplication(sys.argv)
- ## Define a top-level widget to hold everything
- w = QtWidgets.QWidget()
- ## Create some widgets to be placed inside
- hist = pg.HistogramLUTItem() # Contrast/color control
- win = pg.GraphicsLayoutWidget()
- win.setMaximumWidth(300)
- win.setMinimumWidth(200)
- win.addItem(hist)
- p1 = pg.PlotWidget()
- neuron_action = ParameterTree()
- neuron_list = QtWidgets.QListWidget()
- ## Create a grid layout to manage the widgets size and position
- layout = QtWidgets.QGridLayout()
- w.setLayout(layout)
- ## Add widgets to the layout in their proper positions
- layout.addWidget(win, 0, 1)
- layout.addWidget(p1, 0, 2)
- layout.addWidget(neuron_action, 0, 3)
- layout.addWidget(neuron_list, 0, 4)
- img = pg.ImageItem()
- p1.addItem(img)
- hist.setImageItem(img)
- # Add actions
- params_action = [{'name': 'LOAD DATA', 'type':'action'},
- {'name': 'LOAD ROIS', 'type':'action'},
- {'name': 'SAVE', 'type':'action'},
- {'name': 'ADD', 'type': 'action'},
- {'name': 'REMOVE', 'type': 'action'},
- {'name': 'SHOW ALL', 'type': 'action'},
- {'name': 'CLEAR', 'type': 'action'},
- {'name': 'IMAGES', 'type': 'list', 'values': ['MEAN','CORR']},
- {'name': 'DISPLAY', 'type': 'list', 'values': ['CONTOUR','SPATIAL FOOTPRINTS']},
- {'name': 'MODE', 'type': 'list', 'values': ['POLYGON','CELL MAGIC WAND', 'CHOOSE NEURONS']},
- {'name': 'MAGIC WAND PARAMS', 'type': 'group', 'children': [{'name': 'MIN RADIUS', 'type': 'int', 'value': 4},
- {'name': 'MAX RADIUS', 'type': 'int', 'value': 10},
- {'name': 'ROUGHNESS', 'type': 'int', 'value': 1}]}]
- pars_action = Parameter.create(name='params_action', type='group', children=params_action)
- neuron_action.setParameters(pars_action, showTop=False)
- neuron_action.setWindowTitle('Parameter Action')
- mode = pars_action.getValues()['MODE'][0]
- # Add event
- #p1.mousePressEvent = mouseClickEvent
- p1.mouseReleaseEvent = release
- p1.mouseMoveEvent = move
- pars_action.param('ADD').sigActivated.connect(add)
- pars_action.param('REMOVE').sigActivated.connect(remove)
- pars_action.param('SHOW ALL').sigActivated.connect(show_all)
- pars_action.param('CLEAR').sigActivated.connect(clear)
- pars_action.param('LOAD DATA').sigActivated.connect(load)
- pars_action.param('LOAD ROIS').sigActivated.connect(load_rois)
- pars_action.param('SAVE').sigActivated.connect(save)
- pars_action.sigTreeStateChanged.connect(change)
- shortcut_down = QShortcut(QtGui.QKeySequence("down"), w)
- shortcut_down.activated.connect(down)
- shortcut_up = QShortcut(QtGui.QKeySequence("up"), w)
- shortcut_up.activated.connect(up)
- neuron_list.itemClicked.connect(show_neuron)
- # Create dictionary for saving
- F = FileDialog()
- all_pts = {}
- all_centers = {}
- all_ROIs = {}
- pts = []
- pen = pg.mkPen(color=(255, 255, 0), width=4)#, style=Qt.DashDotLine)
- ## Display the widget as a new window
- w.show()
- ## Start the Qt event loop
- app.exec()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement