From 70b1c42987592b380132dc8c78e05ac496abd073 Mon Sep 17 00:00:00 2001 From: Josef Brandt Date: Fri, 31 Jul 2020 07:33:42 +0200 Subject: [PATCH] blur images in optical scan --- ramancom/simulatedraman.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/ramancom/simulatedraman.py b/ramancom/simulatedraman.py index 9c22720..a7b58fd 100644 --- a/ramancom/simulatedraman.py +++ b/ramancom/simulatedraman.py @@ -25,8 +25,10 @@ import sys, os stdout = sys.stdout from time import sleep import numpy as np +import cv2 from shutil import copyfile from .ramanbase import RamanBase +from ..helperfunctions import cv2imread_fix, cv2imwrite_fix class SimulatedRaman(RamanBase): magn = 20 @@ -38,11 +40,11 @@ class SimulatedRaman(RamanBase): self.currentpos = None, 0., 0. self.currentZ = 0. # some plausible data to simulate consecutively changing positions - self.positionlist = np.array([[ -1201, 1376, -1290], - [ -1195, -1200, -1279], - [ 1097, -1254, -1297], - [ 2704.1, 1288.2, -1381], - [ 1884. , -1500.8, -1381]]) + self.positionlist = np.array([[ -201, 876, -1290], + [ -55, -900, -1279], + [ 1097, -754, -1297], + [ 2004.1, 788.2, -1381], + [ 1884., -1000.8, -1381]]) self.znum = 4 self.gridnum = 36 self.positionindex = 0 @@ -95,7 +97,17 @@ class SimulatedRaman(RamanBase): assert self.connected cwd = os.getcwd() fakeImgPath = os.path.join(cwd, "gepard", "fakeData/image.bmp") - copyfile(fakeImgPath, fname) + if fname.endswith('tmp.bmp'): + copyfile(fakeImgPath, fname) + else: # fake defocussing + img: np.ndarray = cv2imread_fix(fakeImgPath) + zLevel: int = int(fname.split('.bmp')[0].split('_')[-1]) + if zLevel > 0: + blurRad: int = 8*zLevel + 1 # increase and make it odd + self.logger.info(f'blurring fake image with radius {blurRad} for z-Level {zLevel}') + img = cv2.medianBlur(img, blurRad) + cv2imwrite_fix(fname, img) + self.imageindex = (self.imageindex+1)%(self.znum*self.gridnum) sleep(.01) -- GitLab