-
Notifications
You must be signed in to change notification settings - Fork 1
/
app_seg_params.py
84 lines (57 loc) · 2.72 KB
/
app_seg_params.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from PyQt5 import QtGui, QtWidgets
import sys
import numpy as np
import pyqtgraph
from uavClassification import *
import ui_app_seg_params
class segmentationParams(QtGui.QMainWindow, ui_app_seg_params.Ui_MainWindow):
def __init__(self, parent=None):
#pyqtgraph.setConfigOptions(imageAxisOrder='row-major')
super(self.__class__, self).__init__()
self.setupUi(self)
self.slider_spatialr.valueChanged.connect(self.runSegment)
self.slider_ranger.valueChanged.connect(self.runSegment)
self.slider_classes.valueChanged.connect(self.runClassification)
self.imageItem = pyqtgraph.ImageItem()
self.view = pyqtgraph.ViewBox()
self.view.addItem(self.imageItem)
#segResult is of class pyqtgraph.GraphicsView
self.segResult.setCentralItem(self.view)
#get file pathes with buttons
self.RGBimgpathButton.clicked.connect(self.getFileRGB)
self.smoothedpathButton.clicked.connect(self.getFilesmoothed)
self.saveClassificationButton.clicked.connect(self.saveFileClassified)
#temporary data of segmented image
self.segmentedout = "data/app_segmented.tif"
self.RGBimgpath = "data/test_image_cubic_resample.tif"
self.smoothedpath = "data/smoothed.tif"
def getFileRGB(self):
self.RGBimgpath = str(QtWidgets.QFileDialog.getOpenFileName(self, "Open RGB file", "~")[0])
self.RGBimgpathlabel.setText(self.RGBimgpath)
def getFilesmoothed(self):
self.smoothedpath = str(QtWidgets.QFileDialog.getOpenFileName(self, "Open smoothed file", "~")[0])
self.smoothedpathlabel.setText(self.smoothedpath)
def saveFileClassified(self):
savepath = str(QtWidgets.QFileDialog.getSaveFileName(self, "Save classification file", "~")[0])
writeRaster(savepath, self.classified)
def runSegment(self):
slSpatialr = self.slider_spatialr.value()
slRanger = self.slider_ranger.value()
slClasses = self.slider_classes.value()
mssin = self.smoothedpath
mssout = self.segmentedout
MeanShiftSegmentation(mssin, mssout, spatialr = slSpatialr, ranger = slRanger)
self.runClassification()
def runClassification(self):
slClasses = self.slider_classes.value()
RGBImg, rgbgrofile = readRaster(self.RGBimgpath)
segmentedImg, segprofile = readRaster(self.segmentedout)
ids, stats = segmentStats(segmentedImg, RGBImg)
self.classified = segmentClustering(stats, slClasses, segmentedImg, ids)
self.imageItem.setImage(self.classified[0].T)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
form = segmentationParams()
form.show()
form.runSegment()
app.exec_()