Commit eaebe41d authored by Lars Bittrich's avatar Lars Bittrich

Merge commit '33010f81'

parents dedfb64d 33010f81
......@@ -74,6 +74,18 @@ class DataSet(object):
self.pshift = None # shift of raman scan position relative to image center
self.seedpoints = np.array([])
self.seeddeletepoints = np.array([])
self.detectParams = {'points': np.array([[50,0],[100,200],[200,255]]),
'contrastcurve': True,
'blurRadius': 9,
'threshold': 0.2,
'maxholebrightness': 0.5,
'erodeconvexdefects': 0,
'minparticlearea': 20,
'minparticledistance': 20,
'measurefrac': 1,
'compactness': 0.1,
'seedRad': 3}
self.ramanpoints = []
self.particlecontours = []
self.particlestats = []
......@@ -104,8 +116,8 @@ class DataSet(object):
from opticalscan import loadAndPasteImage
# try to load png and check for detection contours
recreatefullimage = recreatefullimage or not os.path.exists(self.getLegacyImageName())
if not recreatefullimage:
buggyimage = recreatefullimage
if not buggyimage and os.path.exists(self.getLegacyImageName()):
img = cv2imread_fix(self.getLegacyImageName())
Nc = len(self.particlecontours)
if Nc>0:
......@@ -113,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):
recreatefullimage = True
if not recreatefullimage:
buggyimage = True
if not buggyimage:
cv2imwrite_fix(self.getImageName(), img)
del img
if recreatefullimage:
if buggyimage:
print("recreating fullimage from grid data")
imgdata = None
zvalimg = None
......@@ -248,4 +260,12 @@ class DataSet(object):
def save(self):
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
This diff is collapsed.
......@@ -41,22 +41,36 @@ class Parameter(object):
self.show = show
class Segmentation(object):
def __init__(self):
def __init__(self, dataset=None):
self.cancelcomputation = False
if dataset is not None:
self.detectParams = dataset.detectParams
else:
self.detectParams = {'points': np.array([[50,0],[100,200],[200,255]]),
'contrastcurve': True,
'blurRadius': 9,
'threshold': 0.2,
'maxholebrightness': 0.5,
'erodeconvexdefects': 0,
'minparticlearea': 20,
'minparticledistance': 20,
'measurefrac': 1,
'compactness': 0.1,
'seedRad': 3}
self.initialParameters()
def initialParameters(self):
parlist = [Parameter("points", np.ndarray, np.array([[20,0],[50,100],[200,255]]), helptext="Curve contrast"),
Parameter("contrastcurve", np.bool, True, helptext="Contrast curve", show=True),
Parameter("blurRadius", int, 9, 3, 99, 1, 2, helptext="Blur radius", show=True),
Parameter("threshold", float, .2, .01, .9, 2, .02, helptext="Basic threshold", show=True),
Parameter("maxholebrightness", float, 0.5, 0, 1, 2, 0.02, helptext="Close holes brighter than..", show = True),
Parameter("erodeconvexdefects", int, 0, 0, 20, helptext="Erode convex defects", show=True),
Parameter("minparticlearea", int, 20, 10, 1000, 0, 50, helptext="Min. particle pixel area", show=False),
Parameter("minparticledistance", int, 20, 10, 1000, 0, 5, helptext="Min. distance between particles", show=False),
Parameter("measurefrac", float, 1, 0, 1, 2, stepsize = 0.05, helptext="measure fraction of particles", show=False),
parlist = [Parameter("points", np.ndarray, self.detectParams['points'], helptext="Curve contrast"),
Parameter("contrastcurve", np.bool, self.detectParams['contrastcurve'], helptext="Contrast curve", show=True),
Parameter("blurRadius", int, self.detectParams['blurRadius'], 3, 99, 1, 2, helptext="Blur radius", show=True),
Parameter("threshold", float, self.detectParams['threshold'], .01, .9, 2, .02, helptext="Basic threshold", show=True),
Parameter("maxholebrightness", float, self.detectParams['maxholebrightness'], 0, 1, 2, 0.02, helptext="Close holes brighter than..", show = True),
Parameter("erodeconvexdefects", int, self.detectParams['erodeconvexdefects'], 0, 20, helptext="Erode convex defects", show=True),
Parameter("minparticlearea", int, self.detectParams['minparticlearea'], 10, 1000, 0, 50, helptext="Min. particle pixel area", show=False),
Parameter("minparticledistance", int, self.detectParams['minparticledistance'], 10, 1000, 0, 5, helptext="Min. distance between particles", show=False),
Parameter("measurefrac", float, self.detectParams['measurefrac'], 0, 1, 2, stepsize = 0.05, helptext="measure fraction of particles", show=False),
Parameter("sure_fg", None, helptext="Show sure foreground", show=True),
Parameter("compactness", float, 0.1, 0, 1, 2, 0.05, helptext="watershed compactness", show=False),
Parameter("compactness", float, self.detectParams['compactness'], 0, 1, 2, 0.05, helptext="watershed compactness", show=False),
Parameter("watershed", None, helptext="Show watershed markers", show=True),
]
# make each parameter accessible via self.name
......@@ -279,10 +293,6 @@ class Segmentation(object):
if return_step=="contrastcurve": return gray, 0
# image blur for noise-reduction
if self.blurRadius%2 != 1:
self.blurRadius += 1
print('blur Radius was an even number, incremented blur Radius by 1')
blur = cv2.medianBlur(gray, self.blurRadius)
blur = np.uint8(blur*(255/blur.max()))
if return_step=="blurRadius": return blur, 0
......@@ -330,27 +340,26 @@ class Segmentation(object):
sure_fg = self.getSureForeground(erthresh, self.minparticledistance, self.minparticlearea)
# modify sure_fg with seedpoints and deletepoints
sure_bg = cv2.dilate(erthresh, np.ones((5, 5)), iterations = 1)
sure_bg = self.closeHoles(sure_bg)
sure_bg = cv2.dilate(thresh, np.ones((5, 5)), iterations = 1)
sure_bg = self.closeHoles(sure_bg)
# modify sure_fg and sure_bg with seedpoints and deletepoints
if len(deletepoints)>0:
h, w = sure_fg.shape[:2]
mask = np.zeros((h+2, w+2), np.uint8)
for p in np.int32(deletepoints):
if p[0] >= 0 and p[1] >= 0:
cv2.floodFill(sure_fg, mask, tuple(p), 0)
else:
print('skipped del point at {}'.format(p))
for p in np.int32(deletepoints):
cv2.circle(sure_fg, tuple(p), int(seedradius), 0, -1)
if p[0] > 0 and p[1] > 0:
cv2.floodFill(sure_fg, mask, tuple([p[0], p[1]]), 0)
for p in np.int32(seedpoints):
cv2.circle(sure_fg, tuple(p), int(seedradius), 1, -1)
sure_bg = cv2.dilate(erthresh, np.ones((5, 5)), iterations = 1)
sure_bg = self.closeHoles(sure_bg)
print("sure_fg, sure_bg")
cv2.circle(sure_fg, tuple([p[0], p[1]]), int(p[2]), 1, -1)
for p in np.int32(deletepoints):
cv2.circle(sure_fg, tuple([p[0], p[1]]), int(p[2]), 0, -1)
cv2.circle(sure_bg, tuple([p[0], p[1]]), int(p[2]), 0, -1)
sure_bg = cv2.dilate(thresh, np.ones((5, 5)), iterations = 1)
sure_bg = self.closeHoles(sure_bg)
print("sure_fg, sure_bg")
if self.cancelcomputation:
return None, None, None
......
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