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):
from opticalscan import loadAndPasteImage
# try to load png and check for detection contours
buggyimage = recreatefullimage
if not buggyimage and os.path.exists(self.getLegacyImageName()):
recreatefullimage = recreatefullimage or not os.path.exists(self.getLegacyImageName())
if not recreatefullimage:
img = cv2imread_fix(self.getLegacyImageName())
Nc = len(self.particlecontours)
if Nc>0:
......@@ -125,12 +125,12 @@ class DataSet(object):
contpixels = img[contour[:,0,1],contour[:,0,0]]
if np.all(contpixels[:,1]==255) and np.all(contpixels[:,2]==0) \
and np.all(contpixels[:,0]==0):
buggyimage = True
if not buggyimage:
recreatefullimage = True
if not recreatefullimage:
cv2imwrite_fix(self.getImageName(), img)
del img
if buggyimage:
if recreatefullimage:
print("recreating fullimage from grid data")
imgdata = None
zvalimg = None
......@@ -154,9 +154,6 @@ class DataSet(object):
del self.particleimgs
self.version = 1
#os.remove(self.getLegacyImageName())
#os.remove(self.getLegacyDetectImageName())
#self.save()
# add later conversion for higher version numbers here
def getSubImage(self, img, index, draw=True):
......@@ -261,11 +258,3 @@ class DataSet(object):
def save(self):
saveData(self, self.fname)
\ No newline at end of file
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):
group = QtWidgets.QGroupBox("Detection settings", self)
grid = QtWidgets.QGridLayout()
self.parameters = []
#create editable parameters:
# create editable parameters:
for i, p in enumerate(self.seg.parlist):
label, colstretch = None, 1
if p.name == "points":
......@@ -385,9 +385,9 @@ class ParticleDetectionView(QtWidgets.QWidget):
for param in self.parameters:
if param[1] == 'points':
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()
except: #otherwise checkbox -> take its state
except: # otherwise checkbox -> take its state
ds.detectParams[param[1]] = param[0].isChecked()
ds.detectParams['seedRad'] = self.seedradiusedit.value()
ds.save()
......@@ -396,14 +396,14 @@ class ParticleDetectionView(QtWidgets.QWidget):
seedpoints = dataset.seedpoints
seeddeletepoints = dataset.seeddeletepoints
if len(seedpoints) > 0: #points are present
if seedpoints.shape[1] == 2: #old entries with only x,y coordinates
if len(seedpoints) > 0: # points are present
if seedpoints.shape[1] == 2: # old entries with only x,y coordinates
radii = np.ones((seedpoints.shape[0], 1))*3
dataset.seedpoints = np.hstack((seedpoints, radii))
else:
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
radii = np.ones((seeddeletepoints.shape[0], 1))*3
dataset.seeddeletepoints = np.hstack((seeddeletepoints, radii))
......@@ -443,34 +443,20 @@ class ParticleDetectionView(QtWidgets.QWidget):
@QtCore.pyqtSlot()
def updateImageSeeds(self):
if self.dataset is not None:
# seedradius = self.seedradiusedit.value()
n1,n2,m1,m2 = self.imgclip
p0 = np.array([[m1,n1]], dtype=np.int32)
seedpoints = []
seeddeletepoints = []
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??
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]])
# 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
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]):
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)
......@@ -657,7 +643,6 @@ if __name__ == "__main__":
from dataset import DataSet
from time import time
# fname = r"D:\Projekte\Mikroplastik\Waferreinigung_Kerzenfilter\WaferMilliQH118\fullimage.tif"
fname = r"C:\Users\brandt\Desktop\20180723DemoTZW\fullimage.tif"
app = QtWidgets.QApplication(sys.argv)
......
This diff is collapsed.
......@@ -526,7 +526,6 @@ class OpticalScan(QtWidgets.QWidget):
self.timer.start(100.)
if __name__ == "__main__":
import sys
from WITecCOM import WITecCOM
app = QtWidgets.QApplication(sys.argv)
......
......@@ -19,27 +19,37 @@ along with this program, see COPYING.
If not, see <https://www.gnu.org/licenses/>.
"""
import os
from socket import gethostname
from WITecCOM import WITecCOM
#from renishawcom import RenishawCOM
from simulatedraman import SimulatedRaman
import configparser
__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]
RamanControl = SimulatedRaman
hostname = gethostname()
if "SIMULATED_RAMAN_CONTROL" not in os.environ:
if "NO_WITEC_CONTROL" not in os.environ:
WITecCOM.hostname = hostname
#defaultPath = r"D:\Projekte\Mikroplastik"
RamanControl = WITecCOM
# elif hostname == RenishawCOM.hostname and "NO_RENISHAW_CONTROL" not in os.environ:
# RamanControl = RenishawCOM
try:
defaultPath = config["Defaults"]["file_path"]
except KeyError:
pass
try:
interface = config["Interface"]["raman_interface"]
except KeyError:
pass
if RamanControl == SimulatedRaman:
if interface == "SIMULATED_RAMAN_CONTROL":
from simulatedraman import SimulatedRaman
RamanControl = SimulatedRaman
print("WARNING: using only simulated raman control!")
simulatedRaman = True
else:
elif interface == "SIMULATED_RAMAN_CONTROL":
from WITecCOM import WITecCOM
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):
if mode is None:
return
assert mode in ["OpticalScan", "ParticleDetection", "RamanScan", "ParticleAnalysis"]
# TODO add code for mode switching here
self.oscanwidget.setVisible(False)
if self.detectionwidget is not None:
self.detectionwidget.close()
......@@ -374,7 +373,7 @@ class SampleView(QtWidgets.QGraphicsView):
item.setHighLight(False)
self.ramanscanitems[index].setHighLight(True)
self.ensureVisible(self.ramanscanitems[index])
#self.centerOn(self.ramanscanitems[index])
# alternatively use self.centerOn(self.ramanscanitems[index])
def clearItems(self):
for item in self.fititems:
......
......@@ -74,7 +74,6 @@ class ScaleBar(QtWidgets.QMdiSubWindow):
qp.begin(self)
qp.setPen(QtGui.QColor(0,0,0))
backgroundColor = self.palette().light().color()
#backgroundColor.setAlpha(200)
qp.setBrush(backgroundColor)
qp.drawRect(0,0,WX,WY)
qp.setPen(QtGui.QColor(0,0,0))
......
......@@ -177,8 +177,7 @@ class Segmentation(object):
indices = np.where(im_floodfill == 0)[0]
if len(indices) > 0:
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)
# Combine the two images to get the foreground.
im_out = subimg | im_floodfill_inv
......@@ -308,7 +307,6 @@ class Segmentation(object):
return None, None, None
#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)
print("closed holes")
......@@ -401,7 +399,6 @@ class Segmentation(object):
contours = []
for i, cnt in enumerate(tmpcontours):
#print(cnt.shape, hierarchy[0,i,3])
label = markers[cnt[0,0,1],cnt[0,0,0]]
if label==0:
continue
......@@ -418,8 +415,6 @@ class Segmentation(object):
print(len(np.unique(markers))-1, len(contours))
print("stats")
#img = np.zeros_like(thresh)
#img[markers!=0] = 255.
if return_step is not None:
raise NotImplementedError(f"this particular return_step: {return_step} is not implemented yet")
print("contours")
......
......@@ -22,7 +22,7 @@ Simualted Raman interface module for testing without actual raman system connect
"""
from time import sleep
from dataset import loadData
import numpy as np
from shutil import copyfile
from ramanbase import RamanBase
......@@ -31,13 +31,16 @@ from ramanbase import RamanBase
class SimulatedRaman(RamanBase):
def __init__(self):
super().__init__()
fname = "fakeData/test1.pkl"
ds = loadData(fname)
self.currentpos = None, 0., 0.
self.currentZ = 0.
self.positionlist = ds.fitpoints
self.znum = len(ds.zpositions)
self.gridnum = len(ds.grid)
# some plausible data to simulate consecutively changing positions
self.positionlist = np.array([[ 1526. , -1379.9, -131. ],
[ 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.imageindex = 0
......@@ -84,9 +87,7 @@ class SimulatedRaman(RamanBase):
def saveImage(self, fname):
assert self.connected
i, k = self.imageindex//self.znum, self.imageindex%self.znum
#print("Fake saving:", fname)
copyfile(f"fakeData/scanimages/image_{i}_{k}.bmp", fname)
copyfile(f"fakeData/image.bmp", fname)
self.imageindex = (self.imageindex+1)%(self.znum*self.gridnum)
sleep(.01)
......@@ -110,7 +111,7 @@ class SimulatedRaman(RamanBase):
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)
sleep(.3)
if num==self.timeseries-1:
......
......@@ -94,7 +94,6 @@ class FitPosIndicator(QtWidgets.QGraphicsItem):
class RamanScanIndicator(QtWidgets.QGraphicsItem):
def __init__(self, view, number, radius, pos=(0,0)):
super().__init__()
#self.setAcceptedMouseButtons(QtCore.Qt.LeftButton)
self.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable)
self.view = view
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