@@ -164,7 +164,8 @@ def load_leaf_json(d):
164164 SimilarityModel .className : lambda x : SimilarityModel (json = x ),
165165 NonLinearTransform .className : lambda x : NonLinearTransform (json = x ),
166166 LensCorrection .className : lambda x : LensCorrection (json = x ),
167- NonLinearCoordinateTransform .className : lambda x : NonLinearCoordinateTransform (json = x )}
167+ NonLinearCoordinateTransform .className :
168+ lambda x : NonLinearCoordinateTransform (json = x )}
168169
169170 tform_type = d .get ('type' , 'leaf' )
170171 if tform_type != 'leaf' :
@@ -571,7 +572,7 @@ def estimate(self, A, B, return_params=True, **kwargs):
571572 def concatenate (self , model ):
572573 """concatenate a model to this model -- ported from trakEM2 below:
573574 ::
574-
575+
575576 final double a00 = m00 * model.m00 + m01 * model.m10;
576577 final double a01 = m00 * model.m01 + m01 * model.m11;
577578 final double a02 = m00 * model.m02 + m01 * model.m12 + m02;
@@ -752,8 +753,6 @@ class TranslationModel(AffineModel):
752753
753754 def __init__ (self , * args , ** kwargs ):
754755 super (TranslationModel , self ).__init__ (* args , ** kwargs )
755- # raise NotImplementedError(
756- # 'TranslationModel not implemented. please use Affine')
757756
758757 def _process_dataString (self , dataString ):
759758 """expected dataString is 'tx ty'"""
@@ -843,8 +842,6 @@ class RigidModel(AffineModel):
843842
844843 def __init__ (self , * args , ** kwargs ):
845844 super (RigidModel , self ).__init__ (* args , ** kwargs )
846- # raise NotImplementedError(
847- # 'RigidModel not implemented. please use Affine')
848845
849846 def _process_dataString (self , dataString ):
850847 """expected datastring is 'theta tx ty'"""
@@ -972,8 +969,6 @@ class SimilarityModel(RigidModel):
972969
973970 def __init__ (self , * args , ** kwargs ):
974971 super (SimilarityModel , self ).__init__ (* args , ** kwargs )
975- # raise NotImplementedError(
976- # 'SimilarityModel not implemented. please use Affine')
977972
978973 def _process_dataString (self , dataString ):
979974 """expected datastring is 's theta tx ty'"""
@@ -1373,17 +1368,16 @@ def estimate_dstpts(transformlist, src=None):
13731368 return dstpts
13741369
13751370
1376-
1377-
13781371class NonLinearCoordinateTransform (Transform ):
13791372 """
1380- render-python class that implements the mpicbg.trakem2.transform.NonLinearCoordinateTransform class
1381-
1373+ render-python class that implements the
1374+ mpicbg.trakem2.transform.NonLinearCoordinateTransform class
1375+
13821376 Parameters
13831377 ----------
1384- dataString:str or None
1378+ dataString: str or None
13851379 data string of transformation
1386- json:dict or NOne
1380+ json: dict or None
13871381 json compatible dictionary representation of the transformation
13881382
13891383 Returns
@@ -1396,7 +1390,7 @@ class NonLinearCoordinateTransform(Transform):
13961390
13971391 className = 'mpicbg.trakem2.transform.NonLinearCoordinateTransform'
13981392
1399- def __init__ (self , dataString = None , json = None ,transformId = None ):
1393+ def __init__ (self , dataString = None , json = None , transformId = None ):
14001394 if json is not None :
14011395 self .from_dict (json )
14021396 else :
@@ -1408,31 +1402,41 @@ def __init__(self, dataString=None, json=None,transformId=None):
14081402 def _process_dataString (self , dataString ):
14091403
14101404 fields = dataString .split (" " )
1411-
1405+
14121406 self .dimension = int (fields [0 ])
14131407 self .length = int (fields [1 ])
14141408
1415- #cutoff whitespace if there
1416- fields = fields [0 :2 + 4 * self .length + 2 ]
1409+ # cutoff whitespace if there
1410+ fields = fields [0 :2 + 4 * self .length + 2 ]
14171411 # last 2 fields are width and height
14181412 self .width = int (fields [- 2 ])
14191413 self .height = int (fields [- 1 ])
1420-
1421- data = np .array (fields [2 :- 2 ],dtype = 'float32' )
1422- self .beta = data [0 :2 * self .length ].reshape (self .length ,2 )
1423- if not (self .beta .shape [0 ]== self .length ):
1414+
1415+ data = np .array (fields [2 :- 2 ], dtype = 'float32' )
1416+ try :
1417+ self .beta = data [0 :2 * self .length ].reshape (self .length , 2 )
1418+ except ValueError as e :
1419+ raise RenderError (
1420+ 'Incorrect number of coefficients in '
1421+ 'NonLinearCoordinateTransform. msg: {}' .format (e ))
1422+ if not (self .beta .shape [0 ] == self .length ):
14241423 raise RenderError ("not correct number of coefficents" )
14251424
14261425 # normMean and normVar follow
14271426 self .normMean = data [self .length * 2 :self .length * 3 ]
14281427 self .normVar = data [self .length * 3 :self .length * 4 ]
1429- if not (self .normMean .shape [0 ]== self .length ):
1430- raise RenderError ("incorrect number of normMean coefficents" )
1431- if not (self .normVar .shape [0 ]== self .length ):
1432- raise RenderError ("incorrect number of normVar coefficents" )
1433-
1434- def kernelExpand (self ,src ):
1435- """creates an expanded representation of the x,y src points in a polynomial form
1428+ if not (self .normMean .shape [0 ] == self .length ):
1429+ raise RenderError (
1430+ "incorrect number of normMean coefficents "
1431+ "{} != length {}" .format (self .normMean .shape [0 ], self .length ))
1432+ if not (self .normVar .shape [0 ] == self .length ):
1433+ raise RenderError (
1434+ "incorrect number of normVar coefficents "
1435+ "{} != {}" .format (self .normVar .shape [0 ], self .length ))
1436+
1437+ def kernelExpand (self , src ):
1438+ """creates an expanded representation of the x,y
1439+ src points in a polynomial form
14361440
14371441 Parameters
14381442 ----------
@@ -1446,7 +1450,7 @@ def kernelExpand(self,src):
14461450 """
14471451 x = src [:, 0 ]
14481452 y = src [:, 1 ]
1449-
1453+
14501454 expanded = np .zeros ([len (x ), self .length ])
14511455 pidx = 0
14521456 for i in range (1 , self .dimension + 1 ):
@@ -1455,8 +1459,8 @@ def kernelExpand(self,src):
14551459 np .power (x , j ) * np .power (y , i - j ))
14561460 pidx += 1
14571461
1458-
1459- expanded [:, : - 1 ] = ( expanded [:, : - 1 ] - self . normMean [: - 1 ]) / self .normVar [:- 1 ]
1462+ expanded [:, : - 1 ] = (( expanded [:, : - 1 ] - self . normMean [: - 1 ]) /
1463+ self .normVar [:- 1 ])
14601464 expanded [:, - 1 ] = 100.0
14611465 return expanded
14621466
@@ -1476,31 +1480,33 @@ def tform(self, src):
14761480
14771481 # final double[] featureVector = kernelExpand(position);
14781482 # return multiply(beta, featureVector);
1479- nsrc = np .array (src ,dtype = np .float64 )
1483+ nsrc = np .array (src , dtype = np .float64 )
14801484 featureVector = self .kernelExpand (nsrc )
14811485
14821486 dst = np .zeros (src .shape )
14831487 for i in range (0 , featureVector .shape [1 ]):
1484- dst [:, 0 ] = dst [:, 0 ] + (featureVector [:, i ] * self .beta [i ,0 ])
1485- dst [:, 1 ] = dst [:, 1 ] + (featureVector [:, i ] * self .beta [i ,1 ])
1486- return np .array (dst ,dtype = src .dtype )
1487-
1488+ dst [:, 0 ] = dst [:, 0 ] + (featureVector [:, i ] * self .beta [i , 0 ])
1489+ dst [:, 1 ] = dst [:, 1 ] + (featureVector [:, i ] * self .beta [i , 1 ])
1490+ return np .array (dst , dtype = src .dtype )
1491+
14881492 @property
14891493 def dataString (self ):
14901494 shapestring = '{} {}' .format (self .dimension , self .length )
14911495 betastring = ' ' .join ([str (i ).replace ('e-0' , 'e-' ).replace ('e+0' , 'e+' )
1492- for i in self .beta .ravel ()]).replace ('e' , 'E' )
1496+ for i in self .beta .ravel ()]).replace ('e' , 'E' )
14931497 meanstring = ' ' .join ([str (i ).replace ('e-0' , 'e-' ).replace ('e+0' , 'e+' )
1494- for i in self .normMean ]).replace ('e' , 'E' )
1498+ for i in self .normMean ]).replace ('e' , 'E' )
14951499 varstring = ' ' .join ([str (i ).replace ('e-0' , 'e-' ).replace ('e+0' , 'e+' )
14961500 for i in self .normVar ]).replace ('e' , 'E' )
14971501 dimstring = '{} {}' .format (self .height , self .width )
14981502 return '{} {} {} {} {} ' .format (
14991503 shapestring , betastring , meanstring , varstring , dimstring )
15001504
1505+
15011506class NonLinearTransform (NonLinearCoordinateTransform ):
15021507 className = 'mpicbg.trakem2.transform.nonLinearTransform'
15031508
1509+
15041510class LensCorrection (NonLinearCoordinateTransform ):
15051511 """
15061512 a placeholder for the lenscorrection transform, same as NonLinearTransform
0 commit comments