Commit 58e2489c by Lars Bittrich

### Zeiss Importer with permutation variation on the marker positions to allow...

`Zeiss Importer with permutation variation on the marker positions to allow changing marker sequence between Zeiss measurement and at Raman microscope -> minimize human error; but at the cost of limiting maximum angle rotations to -45,45 degrees in each euler angle`
parent 5fd1cb0c
 ... ... @@ -26,6 +26,7 @@ from helperfunctions import cv2imread_fix, cv2imwrite_fix from ramancom.ramancontrol import defaultPath from dataset import DataSet from scipy.optimize import least_squares from itertools import permutations import cv2 import numpy as np ... ... @@ -228,20 +229,34 @@ class ZeissImporter(QtWidgets.QDialog): [s1*c3+c1*c2*s3, -s1*s3+c1*c2*c3, -c1*s2], [s1*s3, s2*c3, c2]]) # find the transformation matrix with best fit for small angles in # [-45°,45°] for all permutation of markers permbest = None pointsbest = None for perm in permutations(range(points.shape[0])): ppoints = points[perm,:] def err(angles_shift): T = getRotMat(angles_shift[:3]).T.A return (np.dot(zpoints, T)-angles_shift[np.newaxis,3:]-points).ravel() best = None for i in range(100): angle = np.pi*np.random.rand(3)-np.pi/2. opt = least_squares(err, np.concatenate((angle, np.zeros(3))), method='lm') if best is None or best.cost>opt.cost: best = opt optangles = best.x[:3] shift = best.x[3:] return (np.dot(zpoints, T) - angles_shift[np.newaxis,3:] \ - ppoints).ravel() angle = np.zeros(3) opt = least_squares(err, np.concatenate((angle, np.zeros(3))), bounds=(np.array([-np.pi/4]*3+[-np.inf]*3), np.array([np.pi/4]*3+[np.inf]*3)), method='dogbox') if permbest is None or \ permbest.cost>opt.cost: print("Current best permutation:", perm, flush=True) permbest = opt pointsbest = ppoints optangles = permbest.x[:3] shift = permbest.x[3:] T = getRotMat(optangles).T.A e = (np.dot(zpoints, T)-shift[np.newaxis,:]-points) e = (np.dot(zpoints, T)-shift[np.newaxis,:]-pointsbest) print("Transformation angles:", optangles, flush=True) print("Transformation shift:", shift, flush=True) print("Transformation err:", e, flush=True) ... ...
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