Error when applying MovingLeastSquareTransform to Trakem2 patch - Windows/Java8

trakem2
Tags: #<Tag:0x00007fd541e3f698>

#1

With the latest downloaded Windows64bit/Java8 I get an error when applying to a patch in Trakem2 a MovingLeastSquareTransform computed and saved to file with RegisterVirtualStack. The minimal example below reproduces the error.

  1. Save the following transform to a xxx.xml file.
<ict_transform_list>
	<ict_transform class="mpicbg.trakem2.transform.MovingLeastSquaresTransform" data="affine 2 1.0 1434.4869082939167 1405.6302110892125 818.2194226159065 766.3353135168139 1.0 1633.1983079313684 1887.2741254083849 342.36782632214164 485.3119101399767 1.0 1772.5997320995223 1943.590409149802 191.44260488605178 523.3048313904443 1.0 920.8429430555449 761.3328498825596 1664.2603583060318 986.140534099123 1.0 1600.92013762068 2095.6905805603237 237.6447529998048 291.80301985950314 1.0 1394.2093696206978 1596.1621146108337 729.5673442555965 584.2939886037537 1.0 1115.7107645523945 840.2144505711622 1447.5140529025439 1039.200106635108 1.0 1769.3606272154843 1301.9104943892066 603.290869469157 1054.7064559775029 1.0 1795.3751437176886 1902.9516298228439 197.68955407876064 568.9999133682941 1.0 923.6481090977883 1569.1295718574436 1147.1179082321628 317.14488708858147 1.0 711.4175514556051 1400.9062200562348 1429.1489495408453 330.24525153408035 1.0 891.1165127648582 1039.8839627827301 1509.0292025710642 739.2918772366237 1.0 1634.570535799409 1929.1781615556538 316.15129216653924 452.9043745692779 1.0 982.2185774138992 627.1916521275506 1698.3072487259535 1135.1444412655815 1.0 1299.7976223185128 1785.0090702658842 688.6805166626305 368.0353661273675 1.0 1389.0668733189202 2011.9106093821083 470.99014760322166 232.31059924516381 1.0 1075.2109467064197 804.8347752106555 1505.7754855208232 1043.9832190271404 1.0 583.093043376716 1227.927721294636 1648.1704947190324 394.3999141909369 1.0 1456.899525591548 1752.533462673427 577.3539858875422 492.5506488855287 1.0 642.4286755130306 1267.088593923512 1573.8135760372866 400.8899296508153 1.0 1314.9761157257885 1289.8832619569534 994.7909148420877 787.4567861618702 1.0 879.428182584594 789.8794788861345 1678.7638835476682 936.5689478105104 1.0 974.4614846689472 1382.9369390960612 1222.7136647916295 507.45713100982584 1.0 1368.3829469280554 1644.104574895724 721.8005884369162 528.4753500723032 1.0 1013.9005589993964 798.3240720411893 1561.252714590615 1005.3555628813615 1.0 1414.7941579067879 1494.032250886637 778.3297849996484 679.5404933014102 1.0 1316.9433847424166 1311.7819711722075 977.3516656506002 769.8245486051036 1.0 1600.2110583767208 2094.8449683694826 239.46543548662802 294.26227552421045 1.0 1695.0068069070908 1208.0641956818984 726.079894187385 1083.453322374816 1.0 895.1899733040711 780.7696735858714 1673.103112757987 952.6030102475916 1.0 1375.484574809594 1038.7652634919366 1102.9283372401935 1031.1391289727746 1.0 1447.2600662024852 1721.9034456136808 605.555007047573 510.4333016607104 1.0 616.5466965634913 1293.1496331282206 1578.3624629449405 363.593365259275 1.0 1510.7256531001674 1582.03376608904 644.0498428293844 670.8363353174553 1.0 901.9348950953822 1415.2306283727535 1261.0846312298652 433.7669536547837 1.0 1294.7219591573657 1783.7485630370986 693.8263324808996 367.58699333595143 1.0 1202.7378993279258 1348.0821703232218 1050.987602739649 673.1443230150804 1.0 744.1423604519637 1391.483768852196 1408.4563957165976 356.07087639341876 1.0 1253.6819828478567 1170.800711631765 1120.1296326553652 848.2049906021139 1.0 1114.716290010134 825.283191415838 1459.446968141639 1042.6999285343247 1.0 1813.8413493240064 1802.997960676251 245.33370264859659 667.0858195858914 1.0 1376.821155997362 1355.7592317793133 899.1553020195145 770.9644337492531 1.0 1534.9217686765378 991.8221776630312 998.0902792743613 1168.5999620367454 1.0 1019.4901008913981 814.8102276403592 1545.2056616172363 999.8334052700054 1.0 1141.1895580793885 705.5824510410334 1512.1656382443139 1167.6492669506013 1.0 894.9094367778498 780.6467043937586 1674.189992622147 953.0650117104599 1.0 1649.8426687452345 1291.5189259992371 711.468125015186 982.1646612588772 1.0 1077.4876424060808 806.9865966946966 1502.3315232238494 1044.6069946205557 1.0 1534.2333415940934 1969.3501919984974 373.4299350896711 353.9029540766383 1.0 1608.431946765301 1066.9418461725884 889.3244305334915 1151.8189581912106 1.0 612.2261590957775 1252.3690823053334 1611.8761148529034 394.95830087595556 1.0 1321.3315769481853 1551.786410942917 822.6543073018164 574.8958901276233 1.0 1586.3674377254324 2020.5602776399357 299.27716484643486 342.2691117714696 1.0 1525.1564234355722 1914.7777541685216 416.11903509817444 397.59899605333874 1.0 828.6422241893397 1241.2329475639835 1436.7656899499723 533.3363005371269 1.0 1149.0588751988375 820.5697550311862 1434.582409900309 1075.800411946898 1.0 1393.4483845032173 1790.0939941707902 607.616862505568 420.62313988332767 1.0 1127.5358119538041 765.5584747231187 1485.7203002198319 1104.2673263177194 1.0 1639.7948562998197 995.8568900231995 906.8713003625382 1221.1288617804005 1.0 1553.7194121570024 1633.7258666481941 572.434952486203 650.0608974233543 1.0 1434.5931350192152 1807.7127795377403 561.6040053163277 430.3181662378807 1.0 1603.511168669631 1694.7402575440162 494.18281093505715 630.5695593576212 1.0 1587.9487657254458 2019.185761442019 298.70478189358624 344.36944657874176 1.0 1480.5997896309113 1220.6948855657595 897.1151247071423 948.7003142494817 1.0 1403.2710099283354 1803.272142072266 590.5063127274382 418.91209793661346 1.0 1665.9320032707474 1262.2928141190373 714.9921668714323 1027.9165528331644 1.0 1780.8567094784266 1776.9375033537124 288.8236260458967 667.4726884089899 1.0 1288.17813950558 1552.9833103816975 845.5199272716358 555.4213528561686 1.0 1072.789095529829 1151.3000278246038 1280.883297131406 760.5082877322776 1.0 1094.3253161396624 1439.0819715279104 1080.3710953680986 528.5535466528426 1.0 1220.7122392174144 1378.5512720576971 1014.6653335796526 656.1259029438097 1.0 1290.2490975460253 1535.6119481769633 855.0720429558737 574.7399846338475 1.0 1320.10495058729 1827.2068369020158 641.9176725650377 347.667305848439 1.0 1632.3153954832842 1255.9329311403928 745.5711136295228 1012.5868533316268 1.0 1123.8812512283682 841.7848385944604 1439.0094533831862 1040.6471867100458 1.0 901.3769180782183 1307.4935453213827 1320.7092675592012 526.2791779077836 1.0 1868.6457845702207 1299.4212689642195 519.551285594474 1118.1844569785812 1.0 1772.4997021540378 1280.5430153726259 611.9815096034366 1077.9208623171512 1.0 686.9308522811709 1380.2499752622532 1461.5934993693502 333.65342684506896 1.0 973.0846228129142 1286.2384472110102 1282.131053174804 582.6985790191005 1.0 1199.9956643621551 1392.1489704977441 1022.4362942755719 633.7094171938211 1.0 1608.3140002474418 1063.7635569955746 888.919481422547 1153.049766038911 1.0 1535.852842387296 1841.3109130263813 448.4069173819294 463.5787320531696 1.0 693.7591853550268 1381.9365824489366 1455.0267192093831 333.55815795397683 1.0 986.1461170016179 1548.6436707096404 1095.624674013367 372.3159770210096 1.0 1190.961566871061 1172.3022148892223 1171.1189145959531 808.9666806133409 1.0 1638.6121385243566 1286.3808212187105 721.9610711805864 992.2629542009641 1.0 1126.0033389878897 844.056216233627 1435.9815650971343 1038.6148509921545 1.0 1309.9255933851312 1549.2826579366986 828.2625267267907 572.6248695491273 1.0 1171.9716102471355 1317.29657033503 1089.6366941098108 681.5345874250613 1.0 1122.5661813406216 841.08803819046 1440.2372191237348 1041.4199102579719 1.0 1570.9246134467076 1898.0605361010143 386.31232924947057 438.6084736532896 1.0 1216.8681728679358 1347.563975928154 1035.5982561022122 674.3236667624182 1.0 957.7241921975644 1308.4472514678016 1279.1852549794537 554.5622705883975 1.0 891.2320067645632 1438.793991245254 1252.565622478559 401.60412395242855 1.0 1527.3581582332276 1606.7559567293606 606.7374898440733 655.4672527429152 1.0 839.2546268522261 1158.886032661694 1471.5762994377217 610.2537187973697 1.0 1374.562873963938 1486.2479976609243 816.115337275469 661.754907980397 1.0 1596.856988039305 1082.741878963327 886.2832080553294 1134.1325221553675 1.0 1768.0867189072942 1905.6613726952062 214.68731892503027 551.1934088275399 1.0 1425.4943120881298 1060.8153797530263 1040.6018135745212 1044.7784528545728 1.0 968.2136654658751 1429.1925375983478 1194.6468655080278 463.19949615965953 1.0 1592.1602848533569 1791.2691454165506 437.9496973316785 540.9413001368289 1.0 1868.6995184995023 1298.9774831167667 519.3213510402143 1119.1100206564747 1.0 1326.6916742983915 1529.0941853902928 828.6497955204857 596.9164681401301 1.0 1035.234397095586 1430.7492137590336 1135.8571648204108 505.78610005372195 1.0 976.7020182205624 1323.5924821176154 1254.8793765979008 554.2285279993482 1.0 1305.2387423471184 1082.4814457340624 1131.6903706446778 949.3734020916221 1.0 1069.3009095315538 851.3886458135989 1478.413703540633 1004.822038866414 1.0 1707.997594191069 1038.2089062052223 821.7577280826904 1233.305738124862 1.0 1332.7723945241041 1336.9341593899678 944.8313078818289 753.7507861015839 1.0 1631.7379775627871 1820.4474004894194 382.4111519529889 536.8829823673354 1.0 1948.0877537444792 1245.9790824453657 483.0402745827459 1207.8679022540553 1.0 1434.3493714986723 1806.5332846430147 559.154022554359 428.329535933264 1.0 1295.5971289431097 1716.5625188022573 733.0671651268409 420.8283838158228 1.0 1032.4983004071585 858.6510445371647 1504.633468306896 981.1580759395248 1.0 1098.2720509292765 1475.3138831164135 1049.9292167822518 503.18200060319424 1.0 1081.3853532912426 774.3354674043403 1517.0659008218927 1081.0107418074733 1.0 689.6066855513624 1380.9148305151882 1459.371839354105 333.230806677241 1.0"/>
	<iict_transform invertible="true" class="mpicbg.trakem2.transform.TranslationModel2D" data="0.0 0.0" />
</ict_transform_list>

  1. Create a trakem2 project, add a patch in the first layer and leave the project open.
  2. Run the following python script in the script editor:
from ij import IJ

from ini.trakem2 import Project
from ini.trakem2.display import Patch
from ini.trakem2.io import CoordinateTransformXML

# open the current project
project = Project.getProjects().get(0)
layerset = project.getRootLayerSet()
layer = layerset.getLayers().get(0)
patch = layer.getDisplayables(Patch)[0]

# load the MovingLeastSquaresTransform
MLSTPath = XXX
transformList = CoordinateTransformXML().parse(MLSTPath)
IJ.log('transformList: ' + str(transformList))

mlsTransform = transformList.get(0)
IJ.log('The mlsTransform: ' + str(mlsTransform))

affTransform = transformList.get(1).createAffine()
IJ.log('The affTransform: ' + str(affTransform))

# apply the affine and MLS transforms
patch.setAffineTransform(affTransform)
patch.setCoordinateTransform(mlsTransform)
patch.updateBucket()
IJ.log('Done')
  1. I get the error:
Traceback (most recent call last):
  File "E:\Users\Thomas\minimalMLSTExampleFailure.py", line 26, in <module>
    patch.setCoordinateTransform(mlsTransform)
	at ini.trakem2.display.Patch.setCoordinateTransform(Patch.java:1266)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at un.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)

java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Comparison method violates its general contract!

	at org.python.core.Py.JavaError(Py.java:546)
	at org.python.core.Py.JavaError(Py.java:537)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:204)
	at org.python.core.PyObject.__call__(PyObject.java:478)
	at org.python.core.PyObject.__call__(PyObject.java:482)
	at org.python.core.PyMethod.__call__(PyMethod.java:141)
	at org.python.pycode._pyx0.f$0(E:\Users\Thomas\puzzletomography\minimalMLSTExampleFailure.py:28)
	at org.python.pycode._pyx0.call_function(E:\Users\Thomas\puzzletomography\minimalMLSTExampleFailure.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:167)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1386)
	at org.python.core.__builtin__.eval(__builtin__.java:497)
	at org.python.core.__builtin__.eval(__builtin__.java:501)
	at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
	at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:40)
	at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
	at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
	at org.scijava.script.ScriptModule.run(ScriptModule.java:159)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)
	at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:237)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: Comparison method violates its general contract!
	at ini.trakem2.display.Patch.setCoordinateTransform(Patch.java:1266)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:186)
	... 24 more
Caused by: java.lang.IllegalArgumentException: Comparison method violates its general contract!
	at java.util.TimSort.mergeLo(TimSort.java:777)
	at java.util.TimSort.mergeAt(TimSort.java:514)
	at java.util.TimSort.mergeCollapse(TimSort.java:441)
	at java.util.TimSort.sort(TimSort.java:245)
	at java.util.Arrays.sort(Arrays.java:1512)
	at java.util.ArrayList.sort(ArrayList.java:1454)
	at java.util.Collections.sort(Collections.java:175)
	at mpicbg.trakem2.transform.MovingLeastSquaresTransform.toDataString(MovingLeastSquaresTransform.java:132)
	at mpicbg.trakem2.transform.MovingLeastSquaresTransform.toXML(MovingLeastSquaresTransform.java:154)
	at ini.trakem2.display.Patch.writeNewCoordinateTransform(Patch.java:2367)
	at ini.trakem2.display.Patch.setNewCoordinateTransform(Patch.java:2347)
	at ini.trakem2.display.Patch.setCoordinateTransform(Patch.java:1264)
	... 29 more

I thought I had found a workaround by applying successfully the transforms with Fiji/Java6, but when opening back the project with Fiji/Java8 (I need Fiji/Java8 at this point), I get the following error when opening a layer that contains a MLS transform (the transformed patch is then not displayed (the black-white default picture for missing patches is shown)):

==================
ERROR:
org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 6328; Content is not allowed in trailing section.
	at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
	at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
	at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
	at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
	at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentScannerImpl$TrailingMiscDispatcher.dispatch(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
	at ini.trakem2.io.CoordinateTransformXML.parse(CoordinateTransformXML.java:33)
	at ini.trakem2.display.Patch.fetchCoordinateTransform(Patch.java:2308)
	at ini.trakem2.display.Patch.getCT(Patch.java:2292)
	at ini.trakem2.display.Patch.getCoordinateTransform(Patch.java:1376)
	at ini.trakem2.display.Patch.createCoordinateTransformedImage(Patch.java:1419)
	at ini.trakem2.display.Patch.createTransformedImage(Patch.java:1516)
	at ini.trakem2.persistence.Loader.fetchAWTImage(Loader.java:1095)
	at ini.trakem2.persistence.Loader.fetchImage(Loader.java:951)
	at ini.trakem2.display.Patch.fetchImage(Patch.java:582)
	at ini.trakem2.display.Patch.paint(Patch.java:567)
	at ini.trakem2.display.DisplayCanvas.paintOffscreen(DisplayCanvas.java:2681)
	at ini.trakem2.display.DisplayCanvas.paintOffscreen(DisplayCanvas.java:2612)
	at ini.trakem2.display.DisplayCanvas$OffscreenThread.paint(DisplayCanvas.java:2485)
	at ini.trakem2.display.AbstractOffscreenThread.run(AbstractOffscreenThread.java:55)
==================

Note also that I have to use Fiji/Java6 to compute and save MLS transforms using RegisterVirtualStack because otherwise in Fiji/Java8 I get the error:

java.lang.IllegalArgumentException: Comparison method violates its general contract!
        at java.util.TimSort.mergeLo(TimSort.java:777)
        at java.util.TimSort.mergeAt(TimSort.java:514)
        at java.util.TimSort.mergeCollapse(TimSort.java:441)
        at java.util.TimSort.sort(TimSort.java:245)
        at java.util.Arrays.sort(Arrays.java:1512)
        at java.util.ArrayList.sort(ArrayList.java:1454)
        at java.util.Collections.sort(Collections.java:175)
        at mpicbg.trakem2.transform.MovingLeastSquaresTransform.toDataString(MovingLeastSquaresTransform.java:132)
        at mpicbg.trakem2.transform.MovingLeastSquaresTransform.toXML(MovingLeastSquaresTransform.java:154)
        at mpicbg.trakem2.transform.CoordinateTransformList.toXML(CoordinateTransformList.java:40)
        at register_virtual_stack.Register_Virtual_Stack_MT$3.call(Register_Virtual_Stack_MT.java:1458)
        at register_virtual_stack.Register_Virtual_Stack_MT$3.call(Register_Virtual_Stack_MT.java:1)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

So there seems to be something wrong with MLS transforms in Windows/Java8 but I cannot tell what.
Thanks a lot for any help


#2

Any thoughts on this one @albertcardona??