Exemple #1
0
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 482)
        MainWindow.setMinimumSize(QtCore.QSize(800, 0))
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout_2 = QtGui.QVBoxLayout(self.centralwidget)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.gridLayout = QtGui.QGridLayout()
        self.gridLayout.setObjectName("gridLayout")
        self.label_4 = QtGui.QLabel(self.centralwidget)
        self.label_4.setEnabled(True)
        self.label_4.setObjectName("label_4")
        self.gridLayout.addWidget(self.label_4, 1, 0, 1, 1)
        self.iv_original = ImageView(self.centralwidget)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.iv_original.sizePolicy().hasHeightForWidth())
        self.iv_original.setSizePolicy(sizePolicy)
        self.iv_original.setObjectName("iv_original")
        self.gridLayout.addWidget(self.iv_original, 2, 0, 1, 1)
        self.iv_processed = ImageView(self.centralwidget)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.iv_processed.sizePolicy().hasHeightForWidth())
        self.iv_processed.setSizePolicy(sizePolicy)
        self.iv_processed.setObjectName("iv_processed")
        self.gridLayout.addWidget(self.iv_processed, 2, 1, 1, 1)
        self.label_5 = QtGui.QLabel(self.centralwidget)
        self.label_5.setObjectName("label_5")
        self.gridLayout.addWidget(self.label_5, 1, 1, 1, 1)
        self.verticalLayout_2.addLayout(self.gridLayout)
        self.line = QtGui.QFrame(self.centralwidget)
        self.line.setFrameShape(QtGui.QFrame.HLine)
        self.line.setFrameShadow(QtGui.QFrame.Sunken)
        self.line.setObjectName("line")
        self.verticalLayout_2.addWidget(self.line)
        self.StatusBarLayout = QtGui.QHBoxLayout()
        self.StatusBarLayout.setObjectName("StatusBarLayout")
        self.PositionLayout = QtGui.QHBoxLayout()
        self.PositionLayout.setObjectName("PositionLayout")
        self.label = QtGui.QLabel(self.centralwidget)
        self.label.setObjectName("label")
        self.PositionLayout.addWidget(self.label)
        self.lbl_position = QtGui.QLabel(self.centralwidget)
        self.lbl_position.setText("")
        self.lbl_position.setObjectName("lbl_position")
        self.PositionLayout.addWidget(self.lbl_position)
        spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
        self.PositionLayout.addItem(spacerItem)
        self.StatusBarLayout.addLayout(self.PositionLayout)
        self.OriginalColorLayout = QtGui.QHBoxLayout()
        self.OriginalColorLayout.setObjectName("OriginalColorLayout")
        self.label_2 = QtGui.QLabel(self.centralwidget)
        self.label_2.setObjectName("label_2")
        self.OriginalColorLayout.addWidget(self.label_2)
        self.lbl_original_color = QtGui.QLabel(self.centralwidget)
        self.lbl_original_color.setText("")
        self.lbl_original_color.setObjectName("lbl_original_color")
        self.OriginalColorLayout.addWidget(self.lbl_original_color)
        spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
        self.OriginalColorLayout.addItem(spacerItem1)
        self.StatusBarLayout.addLayout(self.OriginalColorLayout)
        self.ProcessedColorLayout = QtGui.QHBoxLayout()
        self.ProcessedColorLayout.setObjectName("ProcessedColorLayout")
        self.label_3 = QtGui.QLabel(self.centralwidget)
        self.label_3.setObjectName("label_3")
        self.ProcessedColorLayout.addWidget(self.label_3)
        self.lbl_processed_color = QtGui.QLabel(self.centralwidget)
        self.lbl_processed_color.setText("")
        self.lbl_processed_color.setObjectName("lbl_processed_color")
        self.ProcessedColorLayout.addWidget(self.lbl_processed_color)
        spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
        self.ProcessedColorLayout.addItem(spacerItem2)
        self.StatusBarLayout.addLayout(self.ProcessedColorLayout)
        self.SelectedColorLayout = QtGui.QHBoxLayout()
        self.SelectedColorLayout.setObjectName("SelectedColorLayout")
        self.label_7 = QtGui.QLabel(self.centralwidget)
        self.label_7.setObjectName("label_7")
        self.SelectedColorLayout.addWidget(self.label_7)
        self.lbl_selected_color = QtGui.QLabel(self.centralwidget)
        self.lbl_selected_color.setObjectName("lbl_selected_color")
        self.SelectedColorLayout.addWidget(self.lbl_selected_color)
        spacerItem3 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
        self.SelectedColorLayout.addItem(spacerItem3)
        self.PositionLayout_2 = QtGui.QHBoxLayout()
        self.PositionLayout_2.setObjectName("PositionLayout_2")
        self.label_6 = QtGui.QLabel(self.centralwidget)
        self.label_6.setObjectName("label_6")
        self.PositionLayout_2.addWidget(self.label_6)
        self.lbl_zoom = QtGui.QLabel(self.centralwidget)
        self.lbl_zoom.setObjectName("lbl_zoom")
        self.PositionLayout_2.addWidget(self.lbl_zoom)
        self.SelectedColorLayout.addLayout(self.PositionLayout_2)
        self.StatusBarLayout.addLayout(self.SelectedColorLayout)
        self.verticalLayout_2.addLayout(self.StatusBarLayout)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 27))
        self.menubar.setObjectName("menubar")
        self.menuFile = QtGui.QMenu(self.menubar)
        self.menuFile.setObjectName("menuFile")
        self.menuColors = QtGui.QMenu(self.menubar)
        self.menuColors.setObjectName("menuColors")
        self.menuZoom = QtGui.QMenu(self.menubar)
        self.menuZoom.setObjectName("menuZoom")
        self.menuProcessing = QtGui.QMenu(self.menubar)
        self.menuProcessing.setObjectName("menuProcessing")
        self.menuEdit = QtGui.QMenu(self.menubar)
        self.menuEdit.setObjectName("menuEdit")
        MainWindow.setMenuBar(self.menubar)
        self.action_open = QtGui.QAction(MainWindow)
        self.action_open.setObjectName("action_open")
        self.action_save = QtGui.QAction(MainWindow)
        self.action_save.setObjectName("action_save")
        self.action_quit = QtGui.QAction(MainWindow)
        self.action_quit.setObjectName("action_quit")
        self.action_select_pen_color = QtGui.QAction(MainWindow)
        self.action_select_pen_color.setObjectName("action_select_pen_color")
        self.action_filter_red = QtGui.QAction(MainWindow)
        self.action_filter_red.setCheckable(False)
        self.action_filter_red.setChecked(False)
        self.action_filter_red.setObjectName("action_filter_red")
        self.action_filter_green = QtGui.QAction(MainWindow)
        self.action_filter_green.setCheckable(False)
        self.action_filter_green.setChecked(False)
        self.action_filter_green.setObjectName("action_filter_green")
        self.action_filter_blue = QtGui.QAction(MainWindow)
        self.action_filter_blue.setCheckable(False)
        self.action_filter_blue.setChecked(False)
        self.action_filter_blue.setObjectName("action_filter_blue")
        self.action_zoom_in = QtGui.QAction(MainWindow)
        self.action_zoom_in.setSoftKeyRole(QtGui.QAction.NoSoftKey)
        self.action_zoom_in.setObjectName("action_zoom_in")
        self.action_zoom_out = QtGui.QAction(MainWindow)
        self.action_zoom_out.setObjectName("action_zoom_out")
        self.action_exp = QtGui.QAction(MainWindow)
        self.action_exp.setObjectName("action_exp")
        self.action_revert = QtGui.QAction(MainWindow)
        self.action_revert.setObjectName("action_revert")
        self.action_histogram = QtGui.QAction(MainWindow)
        self.action_histogram.setObjectName("action_histogram")
        self.action_log = QtGui.QAction(MainWindow)
        self.action_log.setObjectName("action_log")
        self.action_hist_stretch = QtGui.QAction(MainWindow)
        self.action_hist_stretch.setObjectName("action_hist_stretch")
        self.action_hist_eq = QtGui.QAction(MainWindow)
        self.action_hist_eq.setObjectName("action_hist_eq")
        self.action_grayscale = QtGui.QAction(MainWindow)
        self.action_grayscale.setObjectName("action_grayscale")
        self.action_custom_thresholding = QtGui.QAction(MainWindow)
        self.action_custom_thresholding.setObjectName("action_custom_thresholding")
        self.action_otsu_thresholding = QtGui.QAction(MainWindow)
        self.action_otsu_thresholding.setObjectName("action_otsu_thresholding")
        self.action_niblack_thresholding = QtGui.QAction(MainWindow)
        self.action_niblack_thresholding.setObjectName("action_niblack_thresholding")
        self.action_linear_filter = QtGui.QAction(MainWindow)
        self.action_linear_filter.setObjectName("action_linear_filter")
        self.action_median_filter = QtGui.QAction(MainWindow)
        self.action_median_filter.setObjectName("action_median_filter")
        self.action_kuwahara_filter = QtGui.QAction(MainWindow)
        self.action_kuwahara_filter.setObjectName("action_kuwahara_filter")
        self.menuFile.addAction(self.action_open)
        self.menuFile.addAction(self.action_save)
        self.menuFile.addSeparator()
        self.menuFile.addAction(self.action_quit)
        self.menuColors.addAction(self.action_select_pen_color)
        self.menuColors.addSeparator()
        self.menuColors.addAction(self.action_filter_red)
        self.menuColors.addAction(self.action_filter_green)
        self.menuColors.addAction(self.action_filter_blue)
        self.menuColors.addAction(self.action_grayscale)
        self.menuColors.addSeparator()
        self.menuColors.addAction(self.action_histogram)
        self.menuZoom.addAction(self.action_zoom_in)
        self.menuZoom.addAction(self.action_zoom_out)
        self.menuProcessing.addAction(self.action_exp)
        self.menuProcessing.addAction(self.action_log)
        self.menuProcessing.addAction(self.action_hist_stretch)
        self.menuProcessing.addAction(self.action_hist_eq)
        self.menuProcessing.addSeparator()
        self.menuProcessing.addAction(self.action_custom_thresholding)
        self.menuProcessing.addAction(self.action_otsu_thresholding)
        self.menuProcessing.addAction(self.action_niblack_thresholding)
        self.menuProcessing.addSeparator()
        self.menuProcessing.addAction(self.action_linear_filter)
        self.menuProcessing.addAction(self.action_median_filter)
        self.menuProcessing.addAction(self.action_kuwahara_filter)
        self.menuEdit.addAction(self.action_revert)
        self.menubar.addAction(self.menuFile.menuAction())
        self.menubar.addAction(self.menuEdit.menuAction())
        self.menubar.addAction(self.menuColors.menuAction())
        self.menubar.addAction(self.menuZoom.menuAction())
        self.menubar.addAction(self.menuProcessing.menuAction())

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "Image editor", None, QtGui.QApplication.UnicodeUTF8))
        self.label_4.setText(QtGui.QApplication.translate("MainWindow", "Original image", None, QtGui.QApplication.UnicodeUTF8))
        self.label_5.setText(QtGui.QApplication.translate("MainWindow", "Processed image", None, QtGui.QApplication.UnicodeUTF8))
        self.label.setText(QtGui.QApplication.translate("MainWindow", "Position:", None, QtGui.QApplication.UnicodeUTF8))
        self.label_2.setText(QtGui.QApplication.translate("MainWindow", "Original color:", None, QtGui.QApplication.UnicodeUTF8))
        self.label_3.setText(QtGui.QApplication.translate("MainWindow", "Processed color:", None, QtGui.QApplication.UnicodeUTF8))
        self.label_7.setText(QtGui.QApplication.translate("MainWindow", "Selected color:", None, QtGui.QApplication.UnicodeUTF8))
        self.lbl_selected_color.setText(QtGui.QApplication.translate("MainWindow", "R:255 G:255 B:255", None, QtGui.QApplication.UnicodeUTF8))
        self.label_6.setText(QtGui.QApplication.translate("MainWindow", "Zoom:", None, QtGui.QApplication.UnicodeUTF8))
        self.lbl_zoom.setText(QtGui.QApplication.translate("MainWindow", "x1.0", None, QtGui.QApplication.UnicodeUTF8))
        self.menuFile.setTitle(QtGui.QApplication.translate("MainWindow", "File", None, QtGui.QApplication.UnicodeUTF8))
        self.menuColors.setTitle(QtGui.QApplication.translate("MainWindow", "Colors", None, QtGui.QApplication.UnicodeUTF8))
        self.menuZoom.setTitle(QtGui.QApplication.translate("MainWindow", "Zoom", None, QtGui.QApplication.UnicodeUTF8))
        self.menuProcessing.setTitle(QtGui.QApplication.translate("MainWindow", "Processing", None, QtGui.QApplication.UnicodeUTF8))
        self.menuEdit.setTitle(QtGui.QApplication.translate("MainWindow", "Edit", None, QtGui.QApplication.UnicodeUTF8))
        self.action_open.setText(QtGui.QApplication.translate("MainWindow", "Open", None, QtGui.QApplication.UnicodeUTF8))
        self.action_open.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+O", None, QtGui.QApplication.UnicodeUTF8))
        self.action_save.setText(QtGui.QApplication.translate("MainWindow", "Save", None, QtGui.QApplication.UnicodeUTF8))
        self.action_save.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+S", None, QtGui.QApplication.UnicodeUTF8))
        self.action_quit.setText(QtGui.QApplication.translate("MainWindow", "Quit", None, QtGui.QApplication.UnicodeUTF8))
        self.action_quit.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+Q", None, QtGui.QApplication.UnicodeUTF8))
        self.action_select_pen_color.setText(QtGui.QApplication.translate("MainWindow", "Select pen color", None, QtGui.QApplication.UnicodeUTF8))
        self.action_filter_red.setText(QtGui.QApplication.translate("MainWindow", "Filter red", None, QtGui.QApplication.UnicodeUTF8))
        self.action_filter_green.setText(QtGui.QApplication.translate("MainWindow", "Filter green", None, QtGui.QApplication.UnicodeUTF8))
        self.action_filter_blue.setText(QtGui.QApplication.translate("MainWindow", "Filter blue", None, QtGui.QApplication.UnicodeUTF8))
        self.action_zoom_in.setText(QtGui.QApplication.translate("MainWindow", "Zoom in", None, QtGui.QApplication.UnicodeUTF8))
        self.action_zoom_in.setShortcut(QtGui.QApplication.translate("MainWindow", "+", None, QtGui.QApplication.UnicodeUTF8))
        self.action_zoom_out.setText(QtGui.QApplication.translate("MainWindow", "Zoom out", None, QtGui.QApplication.UnicodeUTF8))
        self.action_zoom_out.setShortcut(QtGui.QApplication.translate("MainWindow", "-", None, QtGui.QApplication.UnicodeUTF8))
        self.action_exp.setText(QtGui.QApplication.translate("MainWindow", "Exponential function", None, QtGui.QApplication.UnicodeUTF8))
        self.action_revert.setText(QtGui.QApplication.translate("MainWindow", "Revert changes", None, QtGui.QApplication.UnicodeUTF8))
        self.action_histogram.setText(QtGui.QApplication.translate("MainWindow", "Show histogram", None, QtGui.QApplication.UnicodeUTF8))
        self.action_log.setText(QtGui.QApplication.translate("MainWindow", "Logarithmic function", None, QtGui.QApplication.UnicodeUTF8))
        self.action_hist_stretch.setText(QtGui.QApplication.translate("MainWindow", "Histogram stretching", None, QtGui.QApplication.UnicodeUTF8))
        self.action_hist_eq.setText(QtGui.QApplication.translate("MainWindow", "Histogram equalization", None, QtGui.QApplication.UnicodeUTF8))
        self.action_grayscale.setText(QtGui.QApplication.translate("MainWindow", "Grayscale", None, QtGui.QApplication.UnicodeUTF8))
        self.action_custom_thresholding.setText(QtGui.QApplication.translate("MainWindow", "Custom thresholding", None, QtGui.QApplication.UnicodeUTF8))
        self.action_otsu_thresholding.setText(QtGui.QApplication.translate("MainWindow", "Otsu thresholding", None, QtGui.QApplication.UnicodeUTF8))
        self.action_niblack_thresholding.setText(QtGui.QApplication.translate("MainWindow", "Niblack thresholding", None, QtGui.QApplication.UnicodeUTF8))
        self.action_linear_filter.setText(QtGui.QApplication.translate("MainWindow", "Linear Filter", None, QtGui.QApplication.UnicodeUTF8))
        self.action_median_filter.setText(QtGui.QApplication.translate("MainWindow", "Median Filter", None, QtGui.QApplication.UnicodeUTF8))
        self.action_kuwahara_filter.setText(QtGui.QApplication.translate("MainWindow", "Kuwahara Filter", None, QtGui.QApplication.UnicodeUTF8))
Exemple #2
0
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 482)
        MainWindow.setMinimumSize(QtCore.QSize(800, 0))
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout_2 = QtGui.QVBoxLayout(self.centralwidget)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.gridLayout = QtGui.QGridLayout()
        self.gridLayout.setObjectName("gridLayout")
        self.label_4 = QtGui.QLabel(self.centralwidget)
        self.label_4.setEnabled(True)
        self.label_4.setObjectName("label_4")
        self.gridLayout.addWidget(self.label_4, 1, 0, 1, 1)
        self.iv_original = ImageView(self.centralwidget)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.iv_original.sizePolicy().hasHeightForWidth())
        self.iv_original.setSizePolicy(sizePolicy)
        self.iv_original.setObjectName("iv_original")
        self.gridLayout.addWidget(self.iv_original, 2, 0, 1, 1)
        self.iv_processed = ImageView(self.centralwidget)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.iv_processed.sizePolicy().hasHeightForWidth())
        self.iv_processed.setSizePolicy(sizePolicy)
        self.iv_processed.setObjectName("iv_processed")
        self.gridLayout.addWidget(self.iv_processed, 2, 1, 1, 1)
        self.label_5 = QtGui.QLabel(self.centralwidget)
        self.label_5.setObjectName("label_5")
        self.gridLayout.addWidget(self.label_5, 1, 1, 1, 1)
        self.verticalLayout_2.addLayout(self.gridLayout)
        self.line = QtGui.QFrame(self.centralwidget)
        self.line.setFrameShape(QtGui.QFrame.HLine)
        self.line.setFrameShadow(QtGui.QFrame.Sunken)
        self.line.setObjectName("line")
        self.verticalLayout_2.addWidget(self.line)
        self.StatusBarLayout = QtGui.QHBoxLayout()
        self.StatusBarLayout.setObjectName("StatusBarLayout")
        self.PositionLayout = QtGui.QHBoxLayout()
        self.PositionLayout.setObjectName("PositionLayout")
        self.label = QtGui.QLabel(self.centralwidget)
        self.label.setObjectName("label")
        self.PositionLayout.addWidget(self.label)
        self.lbl_position = QtGui.QLabel(self.centralwidget)
        self.lbl_position.setText("")
        self.lbl_position.setObjectName("lbl_position")
        self.PositionLayout.addWidget(self.lbl_position)
        spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
        self.PositionLayout.addItem(spacerItem)
        self.StatusBarLayout.addLayout(self.PositionLayout)
        self.OriginalColorLayout = QtGui.QHBoxLayout()
        self.OriginalColorLayout.setObjectName("OriginalColorLayout")
        self.label_2 = QtGui.QLabel(self.centralwidget)
        self.label_2.setObjectName("label_2")
        self.OriginalColorLayout.addWidget(self.label_2)
        self.lbl_original_color = QtGui.QLabel(self.centralwidget)
        self.lbl_original_color.setText("")
        self.lbl_original_color.setObjectName("lbl_original_color")
        self.OriginalColorLayout.addWidget(self.lbl_original_color)
        spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
        self.OriginalColorLayout.addItem(spacerItem1)
        self.StatusBarLayout.addLayout(self.OriginalColorLayout)
        self.ProcessedColorLayout = QtGui.QHBoxLayout()
        self.ProcessedColorLayout.setObjectName("ProcessedColorLayout")
        self.label_3 = QtGui.QLabel(self.centralwidget)
        self.label_3.setObjectName("label_3")
        self.ProcessedColorLayout.addWidget(self.label_3)
        self.lbl_processed_color = QtGui.QLabel(self.centralwidget)
        self.lbl_processed_color.setText("")
        self.lbl_processed_color.setObjectName("lbl_processed_color")
        self.ProcessedColorLayout.addWidget(self.lbl_processed_color)
        spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
        self.ProcessedColorLayout.addItem(spacerItem2)
        self.StatusBarLayout.addLayout(self.ProcessedColorLayout)
        self.SelectedColorLayout = QtGui.QHBoxLayout()
        self.SelectedColorLayout.setObjectName("SelectedColorLayout")
        self.label_7 = QtGui.QLabel(self.centralwidget)
        self.label_7.setObjectName("label_7")
        self.SelectedColorLayout.addWidget(self.label_7)
        self.lbl_selected_color = QtGui.QLabel(self.centralwidget)
        self.lbl_selected_color.setObjectName("lbl_selected_color")
        self.SelectedColorLayout.addWidget(self.lbl_selected_color)
        spacerItem3 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
        self.SelectedColorLayout.addItem(spacerItem3)
        self.PositionLayout_2 = QtGui.QHBoxLayout()
        self.PositionLayout_2.setObjectName("PositionLayout_2")
        self.label_6 = QtGui.QLabel(self.centralwidget)
        self.label_6.setObjectName("label_6")
        self.PositionLayout_2.addWidget(self.label_6)
        self.lbl_zoom = QtGui.QLabel(self.centralwidget)
        self.lbl_zoom.setObjectName("lbl_zoom")
        self.PositionLayout_2.addWidget(self.lbl_zoom)
        self.SelectedColorLayout.addLayout(self.PositionLayout_2)
        self.StatusBarLayout.addLayout(self.SelectedColorLayout)
        self.verticalLayout_2.addLayout(self.StatusBarLayout)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 27))
        self.menubar.setObjectName("menubar")
        self.menuFile = QtGui.QMenu(self.menubar)
        self.menuFile.setObjectName("menuFile")
        self.menuColors = QtGui.QMenu(self.menubar)
        self.menuColors.setObjectName("menuColors")
        self.menuZoom = QtGui.QMenu(self.menubar)
        self.menuZoom.setObjectName("menuZoom")
        self.menuProcessing = QtGui.QMenu(self.menubar)
        self.menuProcessing.setObjectName("menuProcessing")
        self.menuEdit = QtGui.QMenu(self.menubar)
        self.menuEdit.setObjectName("menuEdit")
        MainWindow.setMenuBar(self.menubar)
        self.action_open = QtGui.QAction(MainWindow)
        self.action_open.setObjectName("action_open")
        self.action_save = QtGui.QAction(MainWindow)
        self.action_save.setObjectName("action_save")
        self.action_quit = QtGui.QAction(MainWindow)
        self.action_quit.setObjectName("action_quit")
        self.action_select_pen_color = QtGui.QAction(MainWindow)
        self.action_select_pen_color.setObjectName("action_select_pen_color")
        self.action_filter_red = QtGui.QAction(MainWindow)
        self.action_filter_red.setCheckable(False)
        self.action_filter_red.setChecked(False)
        self.action_filter_red.setObjectName("action_filter_red")
        self.action_filter_green = QtGui.QAction(MainWindow)
        self.action_filter_green.setCheckable(False)
        self.action_filter_green.setChecked(False)
        self.action_filter_green.setObjectName("action_filter_green")
        self.action_filter_blue = QtGui.QAction(MainWindow)
        self.action_filter_blue.setCheckable(False)
        self.action_filter_blue.setChecked(False)
        self.action_filter_blue.setObjectName("action_filter_blue")
        self.action_zoom_in = QtGui.QAction(MainWindow)
        self.action_zoom_in.setSoftKeyRole(QtGui.QAction.NoSoftKey)
        self.action_zoom_in.setObjectName("action_zoom_in")
        self.action_zoom_out = QtGui.QAction(MainWindow)
        self.action_zoom_out.setObjectName("action_zoom_out")
        self.action_exp = QtGui.QAction(MainWindow)
        self.action_exp.setObjectName("action_exp")
        self.action_revert = QtGui.QAction(MainWindow)
        self.action_revert.setObjectName("action_revert")
        self.action_histogram = QtGui.QAction(MainWindow)
        self.action_histogram.setObjectName("action_histogram")
        self.action_log = QtGui.QAction(MainWindow)
        self.action_log.setObjectName("action_log")
        self.action_hist_stretch = QtGui.QAction(MainWindow)
        self.action_hist_stretch.setObjectName("action_hist_stretch")
        self.action_hist_eq = QtGui.QAction(MainWindow)
        self.action_hist_eq.setObjectName("action_hist_eq")
        self.action_grayscale = QtGui.QAction(MainWindow)
        self.action_grayscale.setObjectName("action_grayscale")
        self.action_custom_thresholding = QtGui.QAction(MainWindow)
        self.action_custom_thresholding.setObjectName("action_custom_thresholding")
        self.action_otsu_thresholding = QtGui.QAction(MainWindow)
        self.action_otsu_thresholding.setObjectName("action_otsu_thresholding")
        self.action_niblack_thresholding = QtGui.QAction(MainWindow)
        self.action_niblack_thresholding.setObjectName("action_niblack_thresholding")
        self.action_linear_filter = QtGui.QAction(MainWindow)
        self.action_linear_filter.setObjectName("action_linear_filter")
        self.action_median_filter = QtGui.QAction(MainWindow)
        self.action_median_filter.setObjectName("action_median_filter")
        self.action_kuwahara_filter = QtGui.QAction(MainWindow)
        self.action_kuwahara_filter.setObjectName("action_kuwahara_filter")
        self.menuFile.addAction(self.action_open)
        self.menuFile.addAction(self.action_save)
        self.menuFile.addSeparator()
        self.menuFile.addAction(self.action_quit)
        self.menuColors.addAction(self.action_select_pen_color)
        self.menuColors.addSeparator()
        self.menuColors.addAction(self.action_filter_red)
        self.menuColors.addAction(self.action_filter_green)
        self.menuColors.addAction(self.action_filter_blue)
        self.menuColors.addAction(self.action_grayscale)
        self.menuColors.addSeparator()
        self.menuColors.addAction(self.action_histogram)
        self.menuZoom.addAction(self.action_zoom_in)
        self.menuZoom.addAction(self.action_zoom_out)
        self.menuProcessing.addAction(self.action_exp)
        self.menuProcessing.addAction(self.action_log)
        self.menuProcessing.addAction(self.action_hist_stretch)
        self.menuProcessing.addAction(self.action_hist_eq)
        self.menuProcessing.addSeparator()
        self.menuProcessing.addAction(self.action_custom_thresholding)
        self.menuProcessing.addAction(self.action_otsu_thresholding)
        self.menuProcessing.addAction(self.action_niblack_thresholding)
        self.menuProcessing.addSeparator()
        self.menuProcessing.addAction(self.action_linear_filter)
        self.menuProcessing.addAction(self.action_median_filter)
        self.menuProcessing.addAction(self.action_kuwahara_filter)
        self.menuEdit.addAction(self.action_revert)
        self.menubar.addAction(self.menuFile.menuAction())
        self.menubar.addAction(self.menuEdit.menuAction())
        self.menubar.addAction(self.menuColors.menuAction())
        self.menubar.addAction(self.menuZoom.menuAction())
        self.menubar.addAction(self.menuProcessing.menuAction())

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
Exemple #3
0
 def createImgView(self):
     self.imgView = ImageView(self)
     self.MDI.addSubWindow(self.imgView)
     self.imgView.show()
Exemple #4
0
class TMSControl(QMainWindow):
    
    imageChanged = pyqtSignal(str)
    
    def __init__(self, ROIs=None, parent=None):
        QMainWindow.__init__(self, parent)
        self.setWindowTitle('TMS Parameter Control')
        self.imgfile = None
        self.ROInames = []
        if ROIs != None:
            self.ROIs = []
            for i in range(len(ROIs)):
                self.ROIs.append(ROIs[i].ROI)
                self.ROInames.append('ROI_%d'%(i+1))
        else:
            self.ROIs = []
        
        self.createMainFrame()
        self.createImgView()
        self.createMenu()
        
    def createMainFrame(self):
        self.mainFrame = QWidget()
        self.MDI = QMdiArea()
        self.view = QTreeWidget()
        self.view.setColumnCount(4)
        self.view.setHeaderLabels(['Filename', 'Condition', 'TMS', 'Baseline'])
        listLabel = QLabel('Check frames with stimulation:')
        self.showBarPlot = QPushButton('Show Results')
                     
        self.view.itemDoubleClicked.connect(self.onSelect)
        self.showBarPlot.clicked.connect(self.onPlot)
        
        vbox = QVBoxLayout()
        vbox.addWidget(listLabel)
        vbox.addWidget(self.view)
        vbox.addWidget(self.showBarPlot)
        hbox = QHBoxLayout()
        hbox.addLayout(vbox)
        hbox.addWidget(self.MDI)
                
        self.mainFrame.setLayout(hbox)
        self.setCentralWidget(self.mainFrame)

    def createImgView(self):
        self.imgView = ImageView(self)
        self.MDI.addSubWindow(self.imgView)
        self.imgView.show()
       
    def createMenu(self):
        '''
        Creates the file menu
        '''
        self.file_menu = self.menuBar().addMenu("&File")
        load_action = self.create_action("&Open Images",
            shortcut="Ctrl+O", slot=self.onOpen, 
            tip="Open a set of image directories")
        save_ROI_action = self.create_action("&Save ROIs", slot=self.onSaveROIs,
            shortcut="Ctrl+R", tip="Save each ROI to a .npy file")
        load_ROI_action = self.create_action("&Load ROI",
            shortcut="Ctrl+L", slot=self.onLoadROI,
            tip="Load ROIs from files")
        export_action = self.create_action("&Export Results", slot=self.onExport,
            shortcut="Ctrl+S", tip="Export results to file")
        colormap_action = self.create_action("Export &Activations", slot=self.onExportActivations,
            shortcut="Ctrl+C", tip="Export activation images to csv files")
        quit_action = self.create_action("&Quit", slot=self.close, 
            shortcut="Ctrl+Q", tip="Close the application")
        roi_from_img_action = self.create_action("&ROI from images", slot=self.onROIfromImg,
            tip="Use TMS images to define an ROI")
        
        self.settings_menu = self.menuBar().addMenu("&Settings")
        save_settings_action = self.create_action("Save Se&ttings",
            slot=self.onSaveSettings, tip="Save check settings")
        load_settings_action = self.create_action("&Load Settings",
            slot=self.onLoadSettings, tip="Load a settings file")
        
        self.add_actions(self.file_menu, (load_action, save_ROI_action, load_ROI_action, roi_from_img_action, 
                                          None, export_action, colormap_action, None, quit_action))
        self.add_actions(self.settings_menu, (save_settings_action, load_settings_action))
        
    def add_actions(self, target, actions):
        '''
        Adds the actions to the file menu
        '''
        for action in actions:
            if action is None:
                target.addSeparator()
            else:
                target.addAction(action)

    def create_action(  self, text, slot=None, shortcut=None, 
                        icon=None, tip=None, checkable=False, 
                        signal="triggered()"):
        '''
        Creates actions for the file menu
        '''
        action = QAction(text, self)
        if icon is not None:
            action.setIcon(QIcon(":/%s.png" % icon))
        if shortcut is not None:
            action.setShortcut(shortcut)
        if tip is not None:
            action.setToolTip(tip)
            action.setStatusTip(tip)
        if slot is not None:
            self.connect(action, SIGNAL(signal), slot)
        if checkable:
            action.setCheckable(True)
        return action

    def getResults(self, stim, nostim):
        if self.ROIs == []:
            warn = QMessageBox.warning(self, "No ROI specified", "Warning: No ROI specified")
        else:
            thread = WorkThread(stim, nostim, self.ROIs)
            prog = ProgressWidget(thread)
            prog.show()
            thread.run()
            self.stimval, self.nostimval, self.conditions, self.stimfiles, self.nostimfiles, \
                self.stimpx, self.nostimpx, self.stimcenter, self.nostimcenter = thread.getVals()

    def onExportActivations(self):
        dirname = QFileDialog.getExistingDirectory(parent=self, caption="Choose a directory for export")
        dirname = str(dirname)
        if dirname != '':
            self.onCalculate()
            for n in range(len(self.stimfiles)):
                for i in range(len(self.stimfiles[n])):
                    filename = (os.path.basename(self.stimfiles[n][i]))[:-3] + 'csv'
                    np.savetxt(os.path.join(dirname, filename), self.stimpx[n][i], fmt='%d', delimiter=',')

    def onROIfromImg(self):
        stim = []
        for item in self.items:
            idx = self.items.index(item)
            if item.checkState(2) == Qt.Checked:              
                stim.append(self.pngs[idx])
        self.control = TmsROI(stim, self)
        self.MDI.addSubWindow(self.control)
        self.control.ROISignal.connect(self.onROIchanged)
        self.control.show()
    
    def onROIchanged(self):
        self.ROIs = []
        for i in range(len(self.control.ROIs)):
            self.ROIs.append(self.control.ROIs[i].ROI)
            self.ROInames.append('ROI_%d'%(i+1))
        self.imageChanged.emit(self.imgfile)
    
    def onSaveSettings(self):
        filename = QFileDialog.getSaveFileName(parent=self, caption="Choose a settings filename", filter='*.txt')
        f = open(filename, 'w')
        for item in self.items:
            idx = self.items.index(item)
            if item.checkState(2) == Qt.Checked:    
                f.write('%s,True,'%self.pngs[idx])          
            else:
                f.write('%s,False,'%self.pngs[idx])
            if item.checkState(3) == Qt.Checked:
                f.write('True\n')
            else:
                f.write('False\n')
        f.close()
    
    def onLoadSettings(self):
        filename = QFileDialog.getOpenFileName(parent=self, caption="Open a settings file", filter='*.txt')
        f = open(filename, 'r').readlines()
        basepngs = []
        for i in range(len(self.pngs)):
            basepngs.append(os.path.basename(self.pngs[i]))
        for i in range(len(f)):   
            l = f[i][:-1].split(',')
            png = l[0]
            TMS = l[1]
            try:
                baseline = l[2]
            except IndexError:
                baseline = 'False'
            if TMS == 'True':
                try:
                    idx = basepngs.index(os.path.basename(png))
                    self.items[idx].setCheckState(2, Qt.Checked)
                except ValueError:
                    pass
            if baseline == 'True':
                try:
                    idx = basepngs.index(os.path.basename(png))
                    self.items[idx].setCheckState(3, Qt.Checked)
                except ValueError:
                    pass
            
    def onLoadROI(self):
        files = QFileDialog.getOpenFileNamesAndFilter(parent=self, caption="Choose ROI files", filter='*.npy')
        self.ROIs = []
        self.ROInames = []
        for f in  list(files[0]):
            ROI = np.load(str(f))
            self.ROIs.append(ROI)
            self.ROInames.append(f[:-4])
        self.imageChanged.emit(self.imgfile)

    def onSaveROIs(self):
        for roi in self.ROIs:
            filename = QFileDialog.getSaveFileNameAndFilter(parent=self, caption="Choose a save file name",
                                                            filter="*.npy")
            np.save(str(filename[0]), roi)
            np.savetxt(str(filename[0][:-3]+'csv'), roi, fmt='%d', delimiter=',')
            
    def onOpen(self):
        fd = MultiDirectoryFileDialog()
        fd.exec_()
        dirs = fd.filesSelected()
        self.view.clear()
        parent = self.view.invisibleRootItem()
        try:
            self.pngs = []
            self.items = []
            for d in dirs:
                files = sorted(os.listdir(d))
                dname = os.path.basename(d) 
                condition = dname.split('_')[1]
                topitem = QTreeWidgetItem(parent, [dname])
                topitem.setText(0, dname)
                topitem.setChildIndicatorPolicy(QTreeWidgetItem.ShowIndicator)
                topitem.setExpanded(True)
                for f in files:
                    if f[-3:] == 'png':
                        self.pngs.append(os.path.join(d, f))
                        item = QTreeWidgetItem(topitem, [f, condition])
                        item.setText(0, f)
                        item.setText(1, condition)
                        item.setCheckState(2, Qt.Unchecked)
                        item.setCheckState(3, Qt.Unchecked)
                        self.items.append(item)
            self.view.setColumnWidth(0, 200)
            self.view.setColumnWidth(1, 75)
            self.view.setColumnWidth(2, 50)
            self.view.setColumnWidth(3, 50)
        except TypeError:
            pass
                    
    def onExport(self):
        filename = QFileDialog.getSaveFileName(parent=self, caption="Choose a save file name")
        self.onCalculate()
        f = open(filename, 'w')
        f.write('filename,condition,stim,center_x,center_y,')
        for i in range(0, self.stimval[0].shape[1], 2):
            f.write('ROI_%d_pos,ROI_%d_neg,'%((i/2)+1,(i/2)+1))
        f.write('\n')
        for n in range(len(self.stimval)):
            for i in range(self.stimval[n].shape[0]):
                f.write('%s,%s,stim,%0.6f,%0.6f,'%(self.stimfiles[n][i], str(self.conditions[n][0]),
                                             self.stimcenter[n][i][0],self.stimcenter[n][i][1]))
                for j in range(0, self.stimval[n].shape[1], 2):
                    f.write('%0.6f,%0.6f,'%(self.stimval[n][i,j], self.stimval[n][i,j+1]))
                f.write('\n')
        for n in range(len(self.nostimval)):
            for i in range(self.nostimval[n].shape[0]):
                f.write('%s,%s,no_stim,%0.6f,%0.6f,'%(self.nostimfiles[n][i], str(self.conditions[n][0]),
                                                self.nostimcenter[n][i][0],self.nostimcenter[n][i][1]))
                for j in range(0, self.nostimval[n].shape[1], 2):
                    f.write('%0.6f,%0.6f,'%(self.nostimval[n][i,j], self.nostimval[n][i,j+1]))
                f.write('\n')
        f.close()

    def onSelect(self, item):
        try:
            idx = self.items.index(item)
            self.imgfile = self.pngs[idx]
            self.imageChanged.emit(str(self.imgfile))
        except ValueError:
            pass
        
    def onCalculate(self):
        stim = []
        nostim = []
        for item in self.items:
            idx = self.items.index(item)
            if item.checkState(2) == Qt.Checked:              
                stim.append([self.pngs[idx], item.text(1)])
            if item.checkState(3) == Qt.Checked:
                nostim.append([self.pngs[idx], item.text(1)])
        self.getResults(stim, nostim)

    def onPlot(self):
        self.onCalculate()
        bp = BarPlot(self)
        self.MDI.addSubWindow(bp)
        bp.show()
        av = ActivationView(control=self)
        self.MDI.addSubWindow(av)
        av.show()
    def setupUi(self, ExifViewer):
        ExifViewer.setObjectName("ExifViewer")
        ExifViewer.resize(1920, 771)
        sizePolicy = QtWidgets.QSizePolicy(
            QtWidgets.QSizePolicy.MinimumExpanding,
            QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            ExifViewer.sizePolicy().hasHeightForWidth())
        ExifViewer.setSizePolicy(sizePolicy)
        ExifViewer.setMinimumSize(QtCore.QSize(0, 0))
        ExifViewer.setMaximumSize(QtCore.QSize(1920, 1080))
        ExifViewer.setStyleSheet("")
        ExifViewer.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
        self.centralwidget = QtWidgets.QWidget(ExifViewer)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                           QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.centralwidget.sizePolicy().hasHeightForWidth())
        self.centralwidget.setSizePolicy(sizePolicy)
        self.centralwidget.setMaximumSize(QtCore.QSize(1920, 1080))
        self.centralwidget.setStyleSheet("")
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout.setObjectName("gridLayout")
        self.DataExifTab_Layout = QtWidgets.QHBoxLayout()
        self.DataExifTab_Layout.setSizeConstraint(
            QtWidgets.QLayout.SetNoConstraint)
        self.DataExifTab_Layout.setObjectName("DataExifTab_Layout")
        self.ExifDataTab = QtWidgets.QTableWidget(self.centralwidget)
        self.ExifDataTab.setEnabled(True)
        sizePolicy = QtWidgets.QSizePolicy(
            QtWidgets.QSizePolicy.MinimumExpanding,
            QtWidgets.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.ExifDataTab.sizePolicy().hasHeightForWidth())
        self.ExifDataTab.setSizePolicy(sizePolicy)
        self.ExifDataTab.setMinimumSize(QtCore.QSize(550, 0))
        self.ExifDataTab.setMaximumSize(QtCore.QSize(16777215, 16777215))
        font = QtGui.QFont()
        font.setPointSize(11)
        self.ExifDataTab.setFont(font)
        self.ExifDataTab.setContextMenuPolicy(QtCore.Qt.NoContextMenu)
        self.ExifDataTab.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.ExifDataTab.setAutoFillBackground(False)
        self.ExifDataTab.setFrameShape(QtWidgets.QFrame.HLine)
        self.ExifDataTab.setFrameShadow(QtWidgets.QFrame.Plain)
        self.ExifDataTab.setLineWidth(6)
        self.ExifDataTab.setMidLineWidth(0)
        self.ExifDataTab.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAsNeeded)
        self.ExifDataTab.setSizeAdjustPolicy(
            QtWidgets.QAbstractScrollArea.AdjustToContentsOnFirstShow)
        self.ExifDataTab.setAutoScroll(True)
        self.ExifDataTab.setAutoScrollMargin(5)
        self.ExifDataTab.setEditTriggers(
            QtWidgets.QAbstractItemView.NoEditTriggers)
        self.ExifDataTab.setTabKeyNavigation(False)
        self.ExifDataTab.setProperty("showDropIndicator", False)
        self.ExifDataTab.setDragDropOverwriteMode(False)
        self.ExifDataTab.setAlternatingRowColors(False)
        self.ExifDataTab.setSelectionMode(
            QtWidgets.QAbstractItemView.ExtendedSelection)
        self.ExifDataTab.setSelectionBehavior(
            QtWidgets.QAbstractItemView.SelectRows)
        self.ExifDataTab.setTextElideMode(QtCore.Qt.ElideRight)
        self.ExifDataTab.setHorizontalScrollMode(
            QtWidgets.QAbstractItemView.ScrollPerPixel)
        self.ExifDataTab.setShowGrid(True)
        self.ExifDataTab.setGridStyle(QtCore.Qt.SolidLine)
        self.ExifDataTab.setWordWrap(True)
        self.ExifDataTab.setCornerButtonEnabled(False)
        self.ExifDataTab.setRowCount(0)
        self.ExifDataTab.setColumnCount(2)
        self.ExifDataTab.setObjectName("ExifDataTab")
        self.ExifDataTab.horizontalHeader().setVisible(False)
        self.ExifDataTab.horizontalHeader().setDefaultSectionSize(650)
        self.ExifDataTab.horizontalHeader().setHighlightSections(False)
        self.ExifDataTab.horizontalHeader().setMinimumSectionSize(200)
        self.ExifDataTab.verticalHeader().setVisible(False)
        self.ExifDataTab.verticalHeader().setCascadingSectionResizes(False)
        self.ExifDataTab.verticalHeader().setDefaultSectionSize(30)
        self.ExifDataTab.verticalHeader().setMinimumSectionSize(15)
        self.DataExifTab_Layout.addWidget(self.ExifDataTab)
        self.gridLayout.addLayout(self.DataExifTab_Layout, 0, 1, 1, 1)
        self.externalGrid_layout = QtWidgets.QGridLayout()
        self.externalGrid_layout.setSizeConstraint(
            QtWidgets.QLayout.SetNoConstraint)
        self.externalGrid_layout.setVerticalSpacing(0)
        self.externalGrid_layout.setObjectName("externalGrid_layout")
        self.ListImage_Layout = QtWidgets.QVBoxLayout()
        self.ListImage_Layout.setSizeConstraint(QtWidgets.QLayout.SetFixedSize)
        self.ListImage_Layout.setObjectName("ListImage_Layout")
        self.button_addImages = QtWidgets.QPushButton(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.button_addImages.sizePolicy().hasHeightForWidth())
        self.button_addImages.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setPointSize(14)
        self.button_addImages.setFont(font)
        self.button_addImages.setContextMenuPolicy(
            QtCore.Qt.ActionsContextMenu)
        self.button_addImages.setObjectName("button_addImages")
        self.ListImage_Layout.addWidget(self.button_addImages)
        spacerItem = QtWidgets.QSpacerItem(10, 10,
                                           QtWidgets.QSizePolicy.Minimum,
                                           QtWidgets.QSizePolicy.Preferred)
        self.ListImage_Layout.addItem(spacerItem)
        self.verticalLayout_2 = QtWidgets.QVBoxLayout()
        self.verticalLayout_2.setSizeConstraint(
            QtWidgets.QLayout.SetMinimumSize)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.listWidget = ListPreviewImages(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                           QtWidgets.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.listWidget.sizePolicy().hasHeightForWidth())
        self.listWidget.setSizePolicy(sizePolicy)
        self.listWidget.setMinimumSize(QtCore.QSize(0, 150))
        self.listWidget.setAcceptDrops(True)
        self.listWidget.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.listWidget.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAsNeeded)
        self.listWidget.setSizeAdjustPolicy(
            QtWidgets.QAbstractScrollArea.AdjustToContents)
        self.listWidget.setEditTriggers(
            QtWidgets.QAbstractItemView.DoubleClicked
            | QtWidgets.QAbstractItemView.EditKeyPressed
            | QtWidgets.QAbstractItemView.SelectedClicked)
        self.listWidget.setDragEnabled(True)
        self.listWidget.setDragDropMode(QtWidgets.QAbstractItemView.DragDrop)
        self.listWidget.setDefaultDropAction(QtCore.Qt.IgnoreAction)
        self.listWidget.setSelectionMode(
            QtWidgets.QAbstractItemView.MultiSelection)
        self.listWidget.setIconSize(QtCore.QSize(150, 150))
        self.listWidget.setFlow(QtWidgets.QListView.TopToBottom)
        self.listWidget.setProperty("isWrapping", False)
        self.listWidget.setResizeMode(QtWidgets.QListView.Adjust)
        self.listWidget.setViewMode(QtWidgets.QListView.IconMode)
        self.listWidget.setModelColumn(0)
        self.listWidget.setUniformItemSizes(False)
        self.listWidget.setObjectName("listWidget")
        self.verticalLayout_2.addWidget(self.listWidget)
        spacerItem1 = QtWidgets.QSpacerItem(10, 10,
                                            QtWidgets.QSizePolicy.Minimum,
                                            QtWidgets.QSizePolicy.Preferred)
        self.verticalLayout_2.addItem(spacerItem1)
        self.ListImage_Layout.addLayout(self.verticalLayout_2)
        self.button_deleteSelectedImages = QtWidgets.QPushButton(
            self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.button_deleteSelectedImages.sizePolicy().hasHeightForWidth())
        self.button_deleteSelectedImages.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setPointSize(14)
        self.button_deleteSelectedImages.setFont(font)
        self.button_deleteSelectedImages.setObjectName(
            "button_deleteSelectedImages")
        self.ListImage_Layout.addWidget(self.button_deleteSelectedImages)
        spacerItem2 = QtWidgets.QSpacerItem(10, 10,
                                            QtWidgets.QSizePolicy.Minimum,
                                            QtWidgets.QSizePolicy.Preferred)
        self.ListImage_Layout.addItem(spacerItem2)
        self.button_deleteAllImages = QtWidgets.QPushButton(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.button_deleteAllImages.sizePolicy().hasHeightForWidth())
        self.button_deleteAllImages.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setPointSize(14)
        self.button_deleteAllImages.setFont(font)
        self.button_deleteAllImages.setObjectName("button_deleteAllImages")
        self.ListImage_Layout.addWidget(self.button_deleteAllImages)
        self.externalGrid_layout.addLayout(self.ListImage_Layout, 0, 0, 1, 1)
        self.ViewerImage_Layout = QtWidgets.QVBoxLayout()
        self.ViewerImage_Layout.setSizeConstraint(
            QtWidgets.QLayout.SetMinAndMaxSize)
        self.ViewerImage_Layout.setSpacing(7)
        self.ViewerImage_Layout.setObjectName("ViewerImage_Layout")
        self.widgetImg = QtWidgets.QWidget(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.widgetImg.sizePolicy().hasHeightForWidth())
        self.widgetImg.setSizePolicy(sizePolicy)
        self.widgetImg.setMinimumSize(QtCore.QSize(1, 1))
        self.widgetImg.setMaximumSize(QtCore.QSize(800, 800))
        font = QtGui.QFont()
        font.setBold(False)
        font.setWeight(50)
        self.widgetImg.setFont(font)
        self.widgetImg.setStyleSheet("")
        self.widgetImg.setObjectName("widgetImg")
        self.gridLayout_2 = QtWidgets.QGridLayout(self.widgetImg)
        self.gridLayout_2.setSizeConstraint(QtWidgets.QLayout.SetNoConstraint)
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.image = ImageView(self.widgetImg)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.image.sizePolicy().hasHeightForWidth())
        self.image.setSizePolicy(sizePolicy)
        self.image.setMaximumSize(QtCore.QSize(800, 800))
        font = QtGui.QFont()
        font.setPointSize(16)
        font.setBold(False)
        font.setItalic(False)
        font.setUnderline(False)
        font.setWeight(50)
        font.setStrikeOut(False)
        font.setKerning(True)
        self.image.setFont(font)
        self.image.setAcceptDrops(True)
        self.image.setAutoFillBackground(False)
        self.image.setStyleSheet("")
        self.image.setText("No loaded image")
        self.image.setAlignment(QtCore.Qt.AlignCenter)
        self.image.setWordWrap(True)
        self.image.setObjectName("image")
        self.gridLayout_2.addWidget(self.image, 0, 0, 1, 1)
        self.ViewerImage_Layout.addWidget(self.widgetImg)
        self.BeforeAfterLayout = QtWidgets.QHBoxLayout()
        self.BeforeAfterLayout.setSizeConstraint(
            QtWidgets.QLayout.SetNoConstraint)
        self.BeforeAfterLayout.setObjectName("BeforeAfterLayout")
        spacerItem3 = QtWidgets.QSpacerItem(100, 20,
                                            QtWidgets.QSizePolicy.Expanding,
                                            QtWidgets.QSizePolicy.Minimum)
        self.BeforeAfterLayout.addItem(spacerItem3)
        self.button_previous = QtWidgets.QPushButton(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.button_previous.sizePolicy().hasHeightForWidth())
        self.button_previous.setSizePolicy(sizePolicy)
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(238, 238, 236))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(238, 238, 236))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Light, brush)
        brush = QtGui.QBrush(QtGui.QColor(238, 238, 236))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(238, 238, 236))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Light, brush)
        brush = QtGui.QBrush(QtGui.QColor(238, 238, 236))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(238, 238, 236))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Light, brush)
        self.button_previous.setPalette(palette)
        self.button_previous.setMouseTracking(True)
        self.button_previous.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.button_previous.setText("")
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("icons/left-arrow.png"),
                       QtGui.QIcon.Active, QtGui.QIcon.On)
        self.button_previous.setIcon(icon)
        self.button_previous.setIconSize(QtCore.QSize(40, 40))
        self.button_previous.setCheckable(False)
        self.button_previous.setAutoExclusive(False)
        self.button_previous.setAutoDefault(False)
        self.button_previous.setDefault(False)
        self.button_previous.setFlat(True)
        self.button_previous.setObjectName("button_previous")
        self.BeforeAfterLayout.addWidget(self.button_previous, 0,
                                         QtCore.Qt.AlignHCenter)
        self.button_rotateLeft = QtWidgets.QPushButton(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.button_rotateLeft.sizePolicy().hasHeightForWidth())
        self.button_rotateLeft.setSizePolicy(sizePolicy)
        self.button_rotateLeft.setText("")
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap("icons/LeftRotate.png"),
                        QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.button_rotateLeft.setIcon(icon1)
        self.button_rotateLeft.setIconSize(QtCore.QSize(40, 40))
        self.button_rotateLeft.setFlat(True)
        self.button_rotateLeft.setObjectName("button_rotateLeft")
        self.BeforeAfterLayout.addWidget(self.button_rotateLeft, 0,
                                         QtCore.Qt.AlignHCenter)
        self.button_rotateRight = QtWidgets.QPushButton(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.button_rotateRight.sizePolicy().hasHeightForWidth())
        self.button_rotateRight.setSizePolicy(sizePolicy)
        self.button_rotateRight.setText("")
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap("icons/RightRotate.png"),
                        QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.button_rotateRight.setIcon(icon2)
        self.button_rotateRight.setIconSize(QtCore.QSize(40, 40))
        self.button_rotateRight.setFlat(True)
        self.button_rotateRight.setObjectName("button_rotateRight")
        self.BeforeAfterLayout.addWidget(self.button_rotateRight, 0,
                                         QtCore.Qt.AlignHCenter)
        self.button_next = QtWidgets.QPushButton(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.button_next.sizePolicy().hasHeightForWidth())
        self.button_next.setSizePolicy(sizePolicy)
        self.button_next.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
        self.button_next.setText("")
        icon3 = QtGui.QIcon()
        icon3.addPixmap(QtGui.QPixmap("icons/right-arrow.png"),
                        QtGui.QIcon.Normal, QtGui.QIcon.Off)
        icon3.addPixmap(
            QtGui.QPixmap(
                "../github projects/ExifViewer/icons/right-arrow.png"),
            QtGui.QIcon.Active, QtGui.QIcon.On)
        self.button_next.setIcon(icon3)
        self.button_next.setIconSize(QtCore.QSize(40, 40))
        self.button_next.setFlat(True)
        self.button_next.setObjectName("button_next")
        self.BeforeAfterLayout.addWidget(self.button_next, 0,
                                         QtCore.Qt.AlignHCenter)
        spacerItem4 = QtWidgets.QSpacerItem(100, 20,
                                            QtWidgets.QSizePolicy.Expanding,
                                            QtWidgets.QSizePolicy.Minimum)
        self.BeforeAfterLayout.addItem(spacerItem4)
        self.ViewerImage_Layout.addLayout(self.BeforeAfterLayout)
        self.externalGrid_layout.addLayout(self.ViewerImage_Layout, 0, 1, 1, 1)
        self.gridLayout.addLayout(self.externalGrid_layout, 0, 0, 1, 1)
        ExifViewer.setCentralWidget(self.centralwidget)

        self.retranslateUi(ExifViewer)
        self.listWidget.setCurrentRow(-1)
        QtCore.QMetaObject.connectSlotsByName(ExifViewer)
Exemple #6
0
 def createImgView(self):
     self.imgView = ImageView(self)
     self.MDI.addSubWindow(self.imgView)
     self.imgView.show()
Exemple #7
0
class TMSControl(QMainWindow):

    imageChanged = pyqtSignal(str)

    def __init__(self, ROIs=None, parent=None):
        QMainWindow.__init__(self, parent)
        self.setWindowTitle('TMS Parameter Control')
        self.imgfile = None
        self.ROInames = []
        if ROIs != None:
            self.ROIs = []
            for i in range(len(ROIs)):
                self.ROIs.append(ROIs[i].ROI)
                self.ROInames.append('ROI_%d' % (i + 1))
        else:
            self.ROIs = []

        self.createMainFrame()
        self.createImgView()
        self.createMenu()

    def createMainFrame(self):
        self.mainFrame = QWidget()
        self.MDI = QMdiArea()
        self.view = QTreeWidget()
        self.view.setColumnCount(4)
        self.view.setHeaderLabels(['Filename', 'Condition', 'TMS', 'Baseline'])
        listLabel = QLabel('Check frames with stimulation:')
        self.showBarPlot = QPushButton('Show Results')

        self.view.itemDoubleClicked.connect(self.onSelect)
        self.showBarPlot.clicked.connect(self.onPlot)

        vbox = QVBoxLayout()
        vbox.addWidget(listLabel)
        vbox.addWidget(self.view)
        vbox.addWidget(self.showBarPlot)
        hbox = QHBoxLayout()
        hbox.addLayout(vbox)
        hbox.addWidget(self.MDI)

        self.mainFrame.setLayout(hbox)
        self.setCentralWidget(self.mainFrame)

    def createImgView(self):
        self.imgView = ImageView(self)
        self.MDI.addSubWindow(self.imgView)
        self.imgView.show()

    def createMenu(self):
        '''
        Creates the file menu
        '''
        self.file_menu = self.menuBar().addMenu("&File")
        load_action = self.create_action("&Open Images",
                                         shortcut="Ctrl+O",
                                         slot=self.onOpen,
                                         tip="Open a set of image directories")
        save_ROI_action = self.create_action(
            "&Save ROIs",
            slot=self.onSaveROIs,
            shortcut="Ctrl+R",
            tip="Save each ROI to a .npy file")
        load_ROI_action = self.create_action("&Load ROI",
                                             shortcut="Ctrl+L",
                                             slot=self.onLoadROI,
                                             tip="Load ROIs from files")
        export_action = self.create_action("&Export Results",
                                           slot=self.onExport,
                                           shortcut="Ctrl+S",
                                           tip="Export results to file")
        colormap_action = self.create_action(
            "Export &Activations",
            slot=self.onExportActivations,
            shortcut="Ctrl+C",
            tip="Export activation images to csv files")
        quit_action = self.create_action("&Quit",
                                         slot=self.close,
                                         shortcut="Ctrl+Q",
                                         tip="Close the application")
        roi_from_img_action = self.create_action(
            "&ROI from images",
            slot=self.onROIfromImg,
            tip="Use TMS images to define an ROI")

        self.settings_menu = self.menuBar().addMenu("&Settings")
        save_settings_action = self.create_action("Save Se&ttings",
                                                  slot=self.onSaveSettings,
                                                  tip="Save check settings")
        load_settings_action = self.create_action("&Load Settings",
                                                  slot=self.onLoadSettings,
                                                  tip="Load a settings file")

        self.add_actions(self.file_menu,
                         (load_action, save_ROI_action, load_ROI_action,
                          roi_from_img_action, None, export_action,
                          colormap_action, None, quit_action))
        self.add_actions(self.settings_menu,
                         (save_settings_action, load_settings_action))

    def add_actions(self, target, actions):
        '''
        Adds the actions to the file menu
        '''
        for action in actions:
            if action is None:
                target.addSeparator()
            else:
                target.addAction(action)

    def create_action(self,
                      text,
                      slot=None,
                      shortcut=None,
                      icon=None,
                      tip=None,
                      checkable=False,
                      signal="triggered()"):
        '''
        Creates actions for the file menu
        '''
        action = QAction(text, self)
        if icon is not None:
            action.setIcon(QIcon(":/%s.png" % icon))
        if shortcut is not None:
            action.setShortcut(shortcut)
        if tip is not None:
            action.setToolTip(tip)
            action.setStatusTip(tip)
        if slot is not None:
            self.connect(action, SIGNAL(signal), slot)
        if checkable:
            action.setCheckable(True)
        return action

    def getResults(self, stim, nostim):
        if self.ROIs == []:
            warn = QMessageBox.warning(self, "No ROI specified",
                                       "Warning: No ROI specified")
        else:
            thread = WorkThread(stim, nostim, self.ROIs)
            prog = ProgressWidget(thread)
            prog.show()
            thread.run()
            self.stimval, self.nostimval, self.conditions, self.stimfiles, self.nostimfiles, \
                self.stimpx, self.nostimpx, self.stimcenter, self.nostimcenter = thread.getVals()

    def onExportActivations(self):
        dirname = QFileDialog.getExistingDirectory(
            parent=self, caption="Choose a directory for export")
        dirname = str(dirname)
        if dirname != '':
            self.onCalculate()
            for n in range(len(self.stimfiles)):
                for i in range(len(self.stimfiles[n])):
                    filename = (os.path.basename(
                        self.stimfiles[n][i]))[:-3] + 'csv'
                    np.savetxt(os.path.join(dirname, filename),
                               self.stimpx[n][i],
                               fmt='%d',
                               delimiter=',')

    def onROIfromImg(self):
        stim = []
        for item in self.items:
            idx = self.items.index(item)
            if item.checkState(2) == Qt.Checked:
                stim.append(self.pngs[idx])
        self.control = TmsROI(stim, self)
        self.MDI.addSubWindow(self.control)
        self.control.ROISignal.connect(self.onROIchanged)
        self.control.show()

    def onROIchanged(self):
        self.ROIs = []
        for i in range(len(self.control.ROIs)):
            self.ROIs.append(self.control.ROIs[i].ROI)
            self.ROInames.append('ROI_%d' % (i + 1))
        self.imageChanged.emit(self.imgfile)

    def onSaveSettings(self):
        filename = QFileDialog.getSaveFileName(
            parent=self, caption="Choose a settings filename", filter='*.txt')
        f = open(filename, 'w')
        for item in self.items:
            idx = self.items.index(item)
            if item.checkState(2) == Qt.Checked:
                f.write('%s,True,' % self.pngs[idx])
            else:
                f.write('%s,False,' % self.pngs[idx])
            if item.checkState(3) == Qt.Checked:
                f.write('True\n')
            else:
                f.write('False\n')
        f.close()

    def onLoadSettings(self):
        filename = QFileDialog.getOpenFileName(parent=self,
                                               caption="Open a settings file",
                                               filter='*.txt')
        f = open(filename, 'r').readlines()
        basepngs = []
        for i in range(len(self.pngs)):
            basepngs.append(os.path.basename(self.pngs[i]))
        for i in range(len(f)):
            l = f[i][:-1].split(',')
            png = l[0]
            TMS = l[1]
            try:
                baseline = l[2]
            except IndexError:
                baseline = 'False'
            if TMS == 'True':
                try:
                    idx = basepngs.index(os.path.basename(png))
                    self.items[idx].setCheckState(2, Qt.Checked)
                except ValueError:
                    pass
            if baseline == 'True':
                try:
                    idx = basepngs.index(os.path.basename(png))
                    self.items[idx].setCheckState(3, Qt.Checked)
                except ValueError:
                    pass

    def onLoadROI(self):
        files = QFileDialog.getOpenFileNamesAndFilter(
            parent=self, caption="Choose ROI files", filter='*.npy')
        self.ROIs = []
        self.ROInames = []
        for f in list(files[0]):
            ROI = np.load(str(f))
            self.ROIs.append(ROI)
            self.ROInames.append(f[:-4])
        self.imageChanged.emit(self.imgfile)

    def onSaveROIs(self):
        for roi in self.ROIs:
            filename = QFileDialog.getSaveFileNameAndFilter(
                parent=self, caption="Choose a save file name", filter="*.npy")
            np.save(str(filename[0]), roi)
            np.savetxt(str(filename[0][:-3] + 'csv'),
                       roi,
                       fmt='%d',
                       delimiter=',')

    def onOpen(self):
        fd = MultiDirectoryFileDialog()
        fd.exec_()
        dirs = fd.filesSelected()
        self.view.clear()
        parent = self.view.invisibleRootItem()
        try:
            self.pngs = []
            self.items = []
            for d in dirs:
                files = sorted(os.listdir(d))
                dname = os.path.basename(d)
                condition = dname.split('_')[1]
                topitem = QTreeWidgetItem(parent, [dname])
                topitem.setText(0, dname)
                topitem.setChildIndicatorPolicy(QTreeWidgetItem.ShowIndicator)
                topitem.setExpanded(True)
                for f in files:
                    if f[-3:] == 'png':
                        self.pngs.append(os.path.join(d, f))
                        item = QTreeWidgetItem(topitem, [f, condition])
                        item.setText(0, f)
                        item.setText(1, condition)
                        item.setCheckState(2, Qt.Unchecked)
                        item.setCheckState(3, Qt.Unchecked)
                        self.items.append(item)
            self.view.setColumnWidth(0, 200)
            self.view.setColumnWidth(1, 75)
            self.view.setColumnWidth(2, 50)
            self.view.setColumnWidth(3, 50)
        except TypeError:
            pass

    def onExport(self):
        filename = QFileDialog.getSaveFileName(
            parent=self, caption="Choose a save file name")
        self.onCalculate()
        f = open(filename, 'w')
        f.write('filename,condition,stim,center_x,center_y,')
        for i in range(0, self.stimval[0].shape[1], 2):
            f.write('ROI_%d_pos,ROI_%d_neg,' % ((i / 2) + 1, (i / 2) + 1))
        f.write('\n')
        for n in range(len(self.stimval)):
            for i in range(self.stimval[n].shape[0]):
                f.write('%s,%s,stim,%0.6f,%0.6f,' %
                        (self.stimfiles[n][i], str(self.conditions[n][0]),
                         self.stimcenter[n][i][0], self.stimcenter[n][i][1]))
                for j in range(0, self.stimval[n].shape[1], 2):
                    f.write('%0.6f,%0.6f,' %
                            (self.stimval[n][i, j], self.stimval[n][i, j + 1]))
                f.write('\n')
        for n in range(len(self.nostimval)):
            for i in range(self.nostimval[n].shape[0]):
                f.write(
                    '%s,%s,no_stim,%0.6f,%0.6f,' %
                    (self.nostimfiles[n][i], str(self.conditions[n][0]),
                     self.nostimcenter[n][i][0], self.nostimcenter[n][i][1]))
                for j in range(0, self.nostimval[n].shape[1], 2):
                    f.write(
                        '%0.6f,%0.6f,' %
                        (self.nostimval[n][i, j], self.nostimval[n][i, j + 1]))
                f.write('\n')
        f.close()

    def onSelect(self, item):
        try:
            idx = self.items.index(item)
            self.imgfile = self.pngs[idx]
            self.imageChanged.emit(str(self.imgfile))
        except ValueError:
            pass

    def onCalculate(self):
        stim = []
        nostim = []
        for item in self.items:
            idx = self.items.index(item)
            if item.checkState(2) == Qt.Checked:
                stim.append([self.pngs[idx], item.text(1)])
            if item.checkState(3) == Qt.Checked:
                nostim.append([self.pngs[idx], item.text(1)])
        self.getResults(stim, nostim)

    def onPlot(self):
        self.onCalculate()
        bp = BarPlot(self)
        self.MDI.addSubWindow(bp)
        bp.show()
        av = ActivationView(control=self)
        self.MDI.addSubWindow(av)
        av.show()