Commit 09e96c92 authored by Lars Bittrich's avatar Lars Bittrich

Some code cleanup -> old uncommented code removed

reworking of simulated raman interface to work with smaller data
ramancontrol now works with a config file to switch interfaces and default path
parent eaebe41d
...@@ -116,8 +116,8 @@ class DataSet(object): ...@@ -116,8 +116,8 @@ class DataSet(object):
from opticalscan import loadAndPasteImage from opticalscan import loadAndPasteImage
# try to load png and check for detection contours # try to load png and check for detection contours
buggyimage = recreatefullimage recreatefullimage = recreatefullimage or not os.path.exists(self.getLegacyImageName())
if not buggyimage and os.path.exists(self.getLegacyImageName()): if not recreatefullimage:
img = cv2imread_fix(self.getLegacyImageName()) img = cv2imread_fix(self.getLegacyImageName())
Nc = len(self.particlecontours) Nc = len(self.particlecontours)
if Nc>0: if Nc>0:
...@@ -125,12 +125,12 @@ class DataSet(object): ...@@ -125,12 +125,12 @@ class DataSet(object):
contpixels = img[contour[:,0,1],contour[:,0,0]] contpixels = img[contour[:,0,1],contour[:,0,0]]
if np.all(contpixels[:,1]==255) and np.all(contpixels[:,2]==0) \ if np.all(contpixels[:,1]==255) and np.all(contpixels[:,2]==0) \
and np.all(contpixels[:,0]==0): and np.all(contpixels[:,0]==0):
buggyimage = True recreatefullimage = True
if not buggyimage: if not recreatefullimage:
cv2imwrite_fix(self.getImageName(), img) cv2imwrite_fix(self.getImageName(), img)
del img del img
if buggyimage: if recreatefullimage:
print("recreating fullimage from grid data") print("recreating fullimage from grid data")
imgdata = None imgdata = None
zvalimg = None zvalimg = None
...@@ -154,9 +154,6 @@ class DataSet(object): ...@@ -154,9 +154,6 @@ class DataSet(object):
del self.particleimgs del self.particleimgs
self.version = 1 self.version = 1
#os.remove(self.getLegacyImageName())
#os.remove(self.getLegacyDetectImageName())
#self.save()
# add later conversion for higher version numbers here # add later conversion for higher version numbers here
def getSubImage(self, img, index, draw=True): def getSubImage(self, img, index, draw=True):
...@@ -260,12 +257,4 @@ class DataSet(object): ...@@ -260,12 +257,4 @@ class DataSet(object):
def save(self): def save(self):
saveData(self, self.fname) saveData(self, self.fname)
if __name__ == '__main__':
dset = loadData(r'C:\Users\brandt\Desktop\20180723DemoTZW\20180723DemoTZW.pkl')
print(dset.detectParams)
# dset.seedpoints = np.array([])
# dset.seeddeletepoints = np.array([])
# dset.save()
\ No newline at end of file
...@@ -302,7 +302,7 @@ class ParticleDetectionView(QtWidgets.QWidget): ...@@ -302,7 +302,7 @@ class ParticleDetectionView(QtWidgets.QWidget):
group = QtWidgets.QGroupBox("Detection settings", self) group = QtWidgets.QGroupBox("Detection settings", self)
grid = QtWidgets.QGridLayout() grid = QtWidgets.QGridLayout()
self.parameters = [] self.parameters = []
#create editable parameters: # create editable parameters:
for i, p in enumerate(self.seg.parlist): for i, p in enumerate(self.seg.parlist):
label, colstretch = None, 1 label, colstretch = None, 1
if p.name == "points": if p.name == "points":
...@@ -385,9 +385,9 @@ class ParticleDetectionView(QtWidgets.QWidget): ...@@ -385,9 +385,9 @@ class ParticleDetectionView(QtWidgets.QWidget):
for param in self.parameters: for param in self.parameters:
if param[1] == 'points': if param[1] == 'points':
print(param[0].value()) print(param[0].value())
try: #is it a spinbox or the histWidget? Read out the value try: # is it a spinbox or the histWidget? Read out the value
ds.detectParams[param[1]] = param[0].value() ds.detectParams[param[1]] = param[0].value()
except: #otherwise checkbox -> take its state except: # otherwise checkbox -> take its state
ds.detectParams[param[1]] = param[0].isChecked() ds.detectParams[param[1]] = param[0].isChecked()
ds.detectParams['seedRad'] = self.seedradiusedit.value() ds.detectParams['seedRad'] = self.seedradiusedit.value()
ds.save() ds.save()
...@@ -396,14 +396,14 @@ class ParticleDetectionView(QtWidgets.QWidget): ...@@ -396,14 +396,14 @@ class ParticleDetectionView(QtWidgets.QWidget):
seedpoints = dataset.seedpoints seedpoints = dataset.seedpoints
seeddeletepoints = dataset.seeddeletepoints seeddeletepoints = dataset.seeddeletepoints
if len(seedpoints) > 0: #points are present if len(seedpoints) > 0: # points are present
if seedpoints.shape[1] == 2: #old entries with only x,y coordinates if seedpoints.shape[1] == 2: # old entries with only x,y coordinates
radii = np.ones((seedpoints.shape[0], 1))*3 radii = np.ones((seedpoints.shape[0], 1))*3
dataset.seedpoints = np.hstack((seedpoints, radii)) dataset.seedpoints = np.hstack((seedpoints, radii))
else: else:
dataset.seedpoints = np.array([]) dataset.seedpoints = np.array([])
if len(seeddeletepoints) > 0: #points are present if len(seeddeletepoints) > 0: # points are present
if seeddeletepoints.shape[1] == 2: #old entries with only x,y coordinates if seeddeletepoints.shape[1] == 2: #old entries with only x,y coordinates
radii = np.ones((seeddeletepoints.shape[0], 1))*3 radii = np.ones((seeddeletepoints.shape[0], 1))*3
dataset.seeddeletepoints = np.hstack((seeddeletepoints, radii)) dataset.seeddeletepoints = np.hstack((seeddeletepoints, radii))
...@@ -443,34 +443,20 @@ class ParticleDetectionView(QtWidgets.QWidget): ...@@ -443,34 +443,20 @@ class ParticleDetectionView(QtWidgets.QWidget):
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def updateImageSeeds(self): def updateImageSeeds(self):
if self.dataset is not None: if self.dataset is not None:
# seedradius = self.seedradiusedit.value()
n1,n2,m1,m2 = self.imgclip n1,n2,m1,m2 = self.imgclip
p0 = np.array([[m1,n1]], dtype=np.int32) p0 = np.array([[m1,n1]], dtype=np.int32)
seedpoints = [] seedpoints = []
seeddeletepoints = [] seeddeletepoints = []
arr1 = self.dataset.seedpoints arr1 = self.dataset.seedpoints
#what seeds are actually in image view? # what seeds are actually in image view?
for point in arr1: #Josef says: I replaced the commented logic with the one right here below, as the old one somehow did not work.... The for-loop might become slow at some point?? for point in arr1: #Josef says: I replaced the commented logic with the one right here below, as the old one somehow did not work.... The for-loop might become slow at some point??
if point[0] > (m1-point[2]) and point[0] <= (m2+point[2]) and point[1] > (n1-point[2]) and point[1] <= (n2+point[2]): if point[0] > (m1-point[2]) and point[0] <= (m2+point[2]) and point[1] > (n1-point[2]) and point[1] <= (n2+point[2]):
seedpoints.append([point[0] - p0[0][0], point[1] - p0[0][1], point[2]]) seedpoints.append([point[0] - p0[0][0], point[1] - p0[0][1], point[2]])
# if arr1.shape[0]>0:
# ind = (arr1[:,0]>m1-seedradius)&(arr1[:,0]<=m2+seedradius)
# ind &= (arr1[:,1]>n1-seedradius)&(arr1[:,1]<=n2+seedradius)
# if np.any(ind):
# arr1[ind, :2] -= p0
# seedpoints = arr1.tolist()
#
arr2 = self.dataset.seeddeletepoints arr2 = self.dataset.seeddeletepoints
for point in arr2: #Josef says: I replaced the commented logic with the one right here below, as the old one somehow did not work.... The for-loop might become slow at some point?? for point in arr2: #Josef says: I replaced the commented logic with the one right here below, as the old one somehow did not work.... The for-loop might become slow at some point??
if point[0] > (m1-point[2]) and point[0] <= (m2+point[2]) and point[1] > (n1-point[2]) and point[1] <= (n2+point[2]): if point[0] > (m1-point[2]) and point[0] <= (m2+point[2]) and point[1] > (n1-point[2]) and point[1] <= (n2+point[2]):
seeddeletepoints.append([point[0] - p0[0][0], point[1] - p0[0][1], point[2]]) seeddeletepoints.append([point[0] - p0[0][0], point[1] - p0[0][1], point[2]])
# if arr2.shape[0]>0:
# ind = (arr2[:,0]>m1-seedradius)&(arr2[:,0]<=m2+seedradius)
# ind &= (arr2[:,1]>n1-seedradius)&(arr2[:,1]<=n2+seedradius)
# if np.any(ind):
# arr2[ind, :2] -= p0
# seeddeletepoints = arr2.tolist()
self.imglabel.updateSeedPoints(seedpoints, seeddeletepoints) self.imglabel.updateSeedPoints(seedpoints, seeddeletepoints)
...@@ -657,7 +643,6 @@ if __name__ == "__main__": ...@@ -657,7 +643,6 @@ if __name__ == "__main__":
from dataset import DataSet from dataset import DataSet
from time import time from time import time
# fname = r"D:\Projekte\Mikroplastik\Waferreinigung_Kerzenfilter\WaferMilliQH118\fullimage.tif"
fname = r"C:\Users\brandt\Desktop\20180723DemoTZW\fullimage.tif" fname = r"C:\Users\brandt\Desktop\20180723DemoTZW\fullimage.tif"
app = QtWidgets.QApplication(sys.argv) app = QtWidgets.QApplication(sys.argv)
......
This diff is collapsed.
...@@ -526,7 +526,6 @@ class OpticalScan(QtWidgets.QWidget): ...@@ -526,7 +526,6 @@ class OpticalScan(QtWidgets.QWidget):
self.timer.start(100.) self.timer.start(100.)
if __name__ == "__main__": if __name__ == "__main__":
import sys
from WITecCOM import WITecCOM from WITecCOM import WITecCOM
app = QtWidgets.QApplication(sys.argv) app = QtWidgets.QApplication(sys.argv)
......
...@@ -19,27 +19,37 @@ along with this program, see COPYING. ...@@ -19,27 +19,37 @@ along with this program, see COPYING.
If not, see <https://www.gnu.org/licenses/>. If not, see <https://www.gnu.org/licenses/>.
""" """
import os import os
from socket import gethostname import configparser
from WITecCOM import WITecCOM
#from renishawcom import RenishawCOM
from simulatedraman import SimulatedRaman
__all__ = ["RamanControl", "simulatedRaman", "defaultPath"] __all__ = ["RamanControl", "defaultPath", "simulatedRaman"]
config = configparser.ConfigParser()
config.read('gepard.cfg')
interface = "SIMULATED_RAMAN_CONTROL"
defaultPath = os.path.split(__file__)[0] defaultPath = os.path.split(__file__)[0]
RamanControl = SimulatedRaman try:
hostname = gethostname() defaultPath = config["Defaults"]["file_path"]
if "SIMULATED_RAMAN_CONTROL" not in os.environ: except KeyError:
if "NO_WITEC_CONTROL" not in os.environ: pass
WITecCOM.hostname = hostname
#defaultPath = r"D:\Projekte\Mikroplastik" try:
RamanControl = WITecCOM interface = config["Interface"]["raman_interface"]
# elif hostname == RenishawCOM.hostname and "NO_RENISHAW_CONTROL" not in os.environ: except KeyError:
# RamanControl = RenishawCOM pass
if RamanControl == SimulatedRaman: if interface == "SIMULATED_RAMAN_CONTROL":
from simulatedraman import SimulatedRaman
RamanControl = SimulatedRaman
print("WARNING: using only simulated raman control!") print("WARNING: using only simulated raman control!")
simulatedRaman = True simulatedRaman = True
else: elif interface == "SIMULATED_RAMAN_CONTROL":
simulatedRaman = False from WITecCOM import WITecCOM
\ No newline at end of file RamanControl = WITecCOM
simulatedRaman = False
elif interface == "RENISHAW_CONTROL":
raise NotImplementedError
simulatedRaman = False
\ No newline at end of file
# rename this file to gepard.cfg and adapt these parameters
[Defaults]
# file path without "" !
file_path = .
[Interface]
# possible values: SIMULATED_RAMAN_CONTROL, WITEC_CONTROL, RENISHAW_CONTROL
raman_interface = SIMULATED_RAMAN_CONTROL
\ No newline at end of file
...@@ -116,7 +116,6 @@ class SampleView(QtWidgets.QGraphicsView): ...@@ -116,7 +116,6 @@ class SampleView(QtWidgets.QGraphicsView):
if mode is None: if mode is None:
return return
assert mode in ["OpticalScan", "ParticleDetection", "RamanScan", "ParticleAnalysis"] assert mode in ["OpticalScan", "ParticleDetection", "RamanScan", "ParticleAnalysis"]
# TODO add code for mode switching here
self.oscanwidget.setVisible(False) self.oscanwidget.setVisible(False)
if self.detectionwidget is not None: if self.detectionwidget is not None:
self.detectionwidget.close() self.detectionwidget.close()
...@@ -374,7 +373,7 @@ class SampleView(QtWidgets.QGraphicsView): ...@@ -374,7 +373,7 @@ class SampleView(QtWidgets.QGraphicsView):
item.setHighLight(False) item.setHighLight(False)
self.ramanscanitems[index].setHighLight(True) self.ramanscanitems[index].setHighLight(True)
self.ensureVisible(self.ramanscanitems[index]) self.ensureVisible(self.ramanscanitems[index])
#self.centerOn(self.ramanscanitems[index]) # alternatively use self.centerOn(self.ramanscanitems[index])
def clearItems(self): def clearItems(self):
for item in self.fititems: for item in self.fititems:
......
...@@ -74,7 +74,6 @@ class ScaleBar(QtWidgets.QMdiSubWindow): ...@@ -74,7 +74,6 @@ class ScaleBar(QtWidgets.QMdiSubWindow):
qp.begin(self) qp.begin(self)
qp.setPen(QtGui.QColor(0,0,0)) qp.setPen(QtGui.QColor(0,0,0))
backgroundColor = self.palette().light().color() backgroundColor = self.palette().light().color()
#backgroundColor.setAlpha(200)
qp.setBrush(backgroundColor) qp.setBrush(backgroundColor)
qp.drawRect(0,0,WX,WY) qp.drawRect(0,0,WX,WY)
qp.setPen(QtGui.QColor(0,0,0)) qp.setPen(QtGui.QColor(0,0,0))
......
...@@ -177,8 +177,7 @@ class Segmentation(object): ...@@ -177,8 +177,7 @@ class Segmentation(object):
indices = np.where(im_floodfill == 0)[0] indices = np.where(im_floodfill == 0)[0]
if len(indices) > 0: if len(indices) > 0:
if np.mean(grayimage[indices[0]]) > maxbrightness: if np.mean(grayimage[indices[0]]) > maxbrightness:
# close hole and add closed image to thresh:
#close hole and add closed image to thresh:
im_floodfill_inv = cv2.bitwise_not(im_floodfill) im_floodfill_inv = cv2.bitwise_not(im_floodfill)
# Combine the two images to get the foreground. # Combine the two images to get the foreground.
im_out = subimg | im_floodfill_inv im_out = subimg | im_floodfill_inv
...@@ -308,7 +307,6 @@ class Segmentation(object): ...@@ -308,7 +307,6 @@ class Segmentation(object):
return None, None, None return None, None, None
#close holes darkter than self.max_brightness #close holes darkter than self.max_brightness
# if self.maxholebrightness > 0.01: <-- NO! Always do it, 0 closes ALL holes
self.closeBrightHoles(thresh, blur, self.maxholebrightness) self.closeBrightHoles(thresh, blur, self.maxholebrightness)
print("closed holes") print("closed holes")
...@@ -401,7 +399,6 @@ class Segmentation(object): ...@@ -401,7 +399,6 @@ class Segmentation(object):
contours = [] contours = []
for i, cnt in enumerate(tmpcontours): for i, cnt in enumerate(tmpcontours):
#print(cnt.shape, hierarchy[0,i,3])
label = markers[cnt[0,0,1],cnt[0,0,0]] label = markers[cnt[0,0,1],cnt[0,0,0]]
if label==0: if label==0:
continue continue
...@@ -418,8 +415,6 @@ class Segmentation(object): ...@@ -418,8 +415,6 @@ class Segmentation(object):
print(len(np.unique(markers))-1, len(contours)) print(len(np.unique(markers))-1, len(contours))
print("stats") print("stats")
#img = np.zeros_like(thresh)
#img[markers!=0] = 255.
if return_step is not None: if return_step is not None:
raise NotImplementedError(f"this particular return_step: {return_step} is not implemented yet") raise NotImplementedError(f"this particular return_step: {return_step} is not implemented yet")
print("contours") print("contours")
......
...@@ -22,7 +22,7 @@ Simualted Raman interface module for testing without actual raman system connect ...@@ -22,7 +22,7 @@ Simualted Raman interface module for testing without actual raman system connect
""" """
from time import sleep from time import sleep
from dataset import loadData import numpy as np
from shutil import copyfile from shutil import copyfile
from ramanbase import RamanBase from ramanbase import RamanBase
...@@ -31,13 +31,16 @@ from ramanbase import RamanBase ...@@ -31,13 +31,16 @@ from ramanbase import RamanBase
class SimulatedRaman(RamanBase): class SimulatedRaman(RamanBase):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
fname = "fakeData/test1.pkl"
ds = loadData(fname)
self.currentpos = None, 0., 0. self.currentpos = None, 0., 0.
self.currentZ = 0. self.currentZ = 0.
self.positionlist = ds.fitpoints # some plausible data to simulate consecutively changing positions
self.znum = len(ds.zpositions) self.positionlist = np.array([[ 1526. , -1379.9, -131. ],
self.gridnum = len(ds.grid) [ 3762.5, -1197.7, -138.1],
[ 2313.7, -2627.2, -138.1],
[ 2704.1, -1788.2, -138.1],
[ 3884. , -2650.8, -138.1]])
self.znum = 4
self.gridnum = 36
self.positionindex = 0 self.positionindex = 0
self.imageindex = 0 self.imageindex = 0
...@@ -84,9 +87,7 @@ class SimulatedRaman(RamanBase): ...@@ -84,9 +87,7 @@ class SimulatedRaman(RamanBase):
def saveImage(self, fname): def saveImage(self, fname):
assert self.connected assert self.connected
i, k = self.imageindex//self.znum, self.imageindex%self.znum copyfile(f"fakeData/image.bmp", fname)
#print("Fake saving:", fname)
copyfile(f"fakeData/scanimages/image_{i}_{k}.bmp", fname)
self.imageindex = (self.imageindex+1)%(self.znum*self.gridnum) self.imageindex = (self.imageindex+1)%(self.znum*self.gridnum)
sleep(.01) sleep(.01)
...@@ -110,7 +111,7 @@ class SimulatedRaman(RamanBase): ...@@ -110,7 +111,7 @@ class SimulatedRaman(RamanBase):
def nextTimeSeriesScan(self, num): def nextTimeSeriesScan(self, num):
#assert self.timeseries # will not work since initiateTimeSeries is done by a different class assert self.timeseries
print("Scan number:", num) print("Scan number:", num)
sleep(.3) sleep(.3)
if num==self.timeseries-1: if num==self.timeseries-1:
......
...@@ -94,7 +94,6 @@ class FitPosIndicator(QtWidgets.QGraphicsItem): ...@@ -94,7 +94,6 @@ class FitPosIndicator(QtWidgets.QGraphicsItem):
class RamanScanIndicator(QtWidgets.QGraphicsItem): class RamanScanIndicator(QtWidgets.QGraphicsItem):
def __init__(self, view, number, radius, pos=(0,0)): def __init__(self, view, number, radius, pos=(0,0)):
super().__init__() super().__init__()
#self.setAcceptedMouseButtons(QtCore.Qt.LeftButton)
self.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable) self.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable)
self.view = view self.view = view
self.number = number self.number = number
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment