Advertisement
dachte

example.py

Jan 23rd, 2025
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.70 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. VolPy GUI interface is used to correct outputs of Mask R-CNN or annotate new datasets.
  5. VolPy GUI uses summary images and ROIs as the input. It outputs binary masks for the trace denoising
  6. and spike extraction step of VolPy.
  7. @author: @caichangjia
  8. """
  9.  
  10. # These imports apparently must come before importing pyqtgraph on some platforms
  11. import PySide6
  12. from PySide6 import QtWidgets
  13. from PySide6.QtWidgets import QApplication
  14. from PySide6.QtGui import QShortcut
  15.  
  16. import numpy as np
  17. import os
  18. from pathlib import Path
  19. import pyqtgraph as pg
  20. from pyqtgraph import FileDialog
  21. from pyqtgraph.Qt import QtGui
  22. from pyqtgraph.parametertree import Parameter, ParameterTree
  23. import random
  24. from skimage.draw import polygon
  25. import sys
  26.  
  27. os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = os.fspath(
  28.     Path(PySide6.__file__).resolve().parent / "Qt5" / "plugins")
  29.  
  30.  
  31. def release(event):
  32.     pass
  33.  
  34. def move(event):
  35.     pass
  36.  
  37. def add():
  38.     pass
  39.  
  40. def remove():
  41.     pass
  42.  
  43. def show_all():
  44.     pass
  45.  
  46. def clear():
  47.     pass
  48.  
  49. def show_neuron():
  50.     pass
  51.  
  52. def load():
  53.     pass
  54.  
  55. def load_rois():
  56.     pass
  57.  
  58. def save():
  59.     pass
  60.  
  61. def change(param, changes):
  62.     pass
  63.  
  64. def down():
  65.     pass
  66.  
  67. def up():
  68.     pass
  69.  
  70. def adjust_contrast(img, min_value, max_value):
  71.     pass
  72.  
  73. def overlay(all_ROIs):
  74.     pass
  75.  
  76. if __name__ == "__main__":    
  77.     ## Always start by initializing Qt (only once per application)
  78.     app = QApplication(sys.argv)
  79.  
  80.     ## Define a top-level widget to hold everything
  81.     w = QtWidgets.QWidget()
  82.  
  83.     ## Create some widgets to be placed inside
  84.     hist = pg.HistogramLUTItem()  # Contrast/color control
  85.     win = pg.GraphicsLayoutWidget()
  86.     win.setMaximumWidth(300)
  87.     win.setMinimumWidth(200)
  88.     win.addItem(hist)
  89.     p1 = pg.PlotWidget()
  90.     neuron_action = ParameterTree()
  91.     neuron_list = QtWidgets.QListWidget()
  92.  
  93.     ## Create a grid layout to manage the widgets size and position
  94.     layout = QtWidgets.QGridLayout()
  95.     w.setLayout(layout)
  96.  
  97.     ## Add widgets to the layout in their proper positions
  98.     layout.addWidget(win, 0, 1)  
  99.     layout.addWidget(p1, 0, 2)  
  100.     layout.addWidget(neuron_action, 0, 3)  
  101.     layout.addWidget(neuron_list, 0, 4)  
  102.     img = pg.ImageItem()
  103.     p1.addItem(img)
  104.     hist.setImageItem(img)
  105.  
  106.     # Add actions    
  107.     params_action = [{'name': 'LOAD DATA', 'type':'action'},
  108.                      {'name': 'LOAD ROIS', 'type':'action'},
  109.                      {'name': 'SAVE', 'type':'action'},                
  110.                      {'name': 'ADD', 'type': 'action'},
  111.                      {'name': 'REMOVE', 'type': 'action'},
  112.                      {'name': 'SHOW ALL', 'type': 'action'},
  113.                      {'name': 'CLEAR', 'type': 'action'},
  114.                      {'name': 'IMAGES', 'type': 'list', 'values': ['MEAN','CORR']},
  115.                      {'name': 'DISPLAY', 'type': 'list', 'values': ['CONTOUR','SPATIAL FOOTPRINTS']},
  116.                      {'name': 'MODE', 'type': 'list', 'values': ['POLYGON','CELL MAGIC WAND', 'CHOOSE NEURONS']},
  117.                      {'name': 'MAGIC WAND PARAMS', 'type': 'group', 'children': [{'name': 'MIN RADIUS', 'type': 'int', 'value': 4},
  118.                                                                         {'name': 'MAX RADIUS', 'type': 'int', 'value': 10},
  119.                                                                         {'name': 'ROUGHNESS', 'type': 'int', 'value': 1}]}]
  120.  
  121.     pars_action = Parameter.create(name='params_action', type='group', children=params_action)
  122.     neuron_action.setParameters(pars_action, showTop=False)
  123.     neuron_action.setWindowTitle('Parameter Action')
  124.     mode = pars_action.getValues()['MODE'][0]
  125.  
  126.     # Add event
  127.     #p1.mousePressEvent = mouseClickEvent
  128.     p1.mouseReleaseEvent = release
  129.     p1.mouseMoveEvent = move
  130.     pars_action.param('ADD').sigActivated.connect(add)
  131.     pars_action.param('REMOVE').sigActivated.connect(remove)
  132.     pars_action.param('SHOW ALL').sigActivated.connect(show_all)
  133.     pars_action.param('CLEAR').sigActivated.connect(clear)
  134.     pars_action.param('LOAD DATA').sigActivated.connect(load)
  135.     pars_action.param('LOAD ROIS').sigActivated.connect(load_rois)
  136.     pars_action.param('SAVE').sigActivated.connect(save)
  137.     pars_action.sigTreeStateChanged.connect(change)    
  138.     shortcut_down = QShortcut(QtGui.QKeySequence("down"), w)
  139.     shortcut_down.activated.connect(down)
  140.     shortcut_up = QShortcut(QtGui.QKeySequence("up"), w)
  141.     shortcut_up.activated.connect(up)
  142.     neuron_list.itemClicked.connect(show_neuron)
  143.  
  144.     # Create dictionary for saving
  145.     F = FileDialog()
  146.     all_pts = {}
  147.     all_centers = {}
  148.     all_ROIs = {}
  149.     pts = []
  150.     pen = pg.mkPen(color=(255, 255, 0), width=4)#, style=Qt.DashDotLine)
  151.  
  152.     ## Display the widget as a new window
  153.     w.show()
  154.  
  155.     ## Start the Qt event loop
  156.     app.exec()
  157.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement