diff --git a/src/main/java/ch/epfl/biop/wrappers/elastix/ij2commands/Elastix_Test.java b/src/main/java/ch/epfl/biop/wrappers/elastix/ij2commands/Elastix_Test.java new file mode 100644 index 0000000..147db54 --- /dev/null +++ b/src/main/java/ch/epfl/biop/wrappers/elastix/ij2commands/Elastix_Test.java @@ -0,0 +1,66 @@ +package ch.epfl.biop.wrappers.elastix.ij2commands; + +import ch.epfl.biop.wrappers.elastix.RegisterHelper; +import ch.epfl.biop.wrappers.transformix.ij2commands.Transformix_TransformImgPlus; +import ij.IJ; +import ij.ImagePlus; +import ij.gui.WaitForUserDialog; +import org.scijava.command.Command; +import org.scijava.command.CommandService; +import org.scijava.plugin.Parameter; +import org.scijava.plugin.Plugin; + +/** + * BIOP, EPFL, Nicolas Chiaruttini, 18th April 2021 + * Simple script for a simple registration test + */ + +@Plugin(type = Command.class, menuPath = "Plugins>BIOP>Elastix>Test Elastix") +public class Elastix_Test implements Command { + + @Parameter + CommandService cs; + + @Override + public void run() { + + try { + + (new WaitForUserDialog( + "The PTBIOP update site should be enabled.\n" + + "Elastix and Transformix should be installed and work in a command line interface.")).show(); + (new WaitForUserDialog("Set the location of elastix and transformix executable file")).show(); + IJ.run("Set and Check Wrappers", ""); + + // Test images : blobs and rotated blobs + (new WaitForUserDialog("Click 'OK' to start a registration test, which should take about 10 seconds ...")).show(); + IJ.run("Blobs (25K)"); + IJ.run("Duplicate...", "title=blobs-rot15.gif"); + IJ.run("Rotate... ", "angle=8 grid=1 interpolation=Bilinear"); + + // Get transformation + RegisterHelper rh = (RegisterHelper) cs.run(Elastix_Register.class, true, + "moving_image", "blobs.gif", + "fixed_image", "blobs-rot15.gif", + "rigid", false, + "fast_affine", true, + "affine", false, + "spline", false, + "spline_grid_spacing", 40 + ).get().getOutput("rh"); + + // Transform image + ImagePlus transformed_image = (ImagePlus) cs.run(Transformix_TransformImgPlus.class, true, + "img_in", "blobs.gif", + "rh", rh + ).get().getOutput("img_out"); + + transformed_image.show(); + + IJ.run("Tile"); + (new WaitForUserDialog("The test is successful if the last and the next-to.last images look identical.")).show(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/test/java/DemoDeepSlice.java b/src/test/java/DemoDeepSlice.java new file mode 100644 index 0000000..5cc84ec --- /dev/null +++ b/src/test/java/DemoDeepSlice.java @@ -0,0 +1,49 @@ + +import ch.epfl.biop.wrappers.deepslice.ij2commands.DeepSliceFolderCommand; +import net.imagej.ImageJ; + +public class DemoDeepSlice { + + public static void main(String... args) throws Exception { + + ImageJ ij = new ImageJ(); + ij.ui().showUI(); + + ij.command().run(DeepSliceFolderCommand.class, true, + "input_folder", "src/test/resources/deepslice_test_folder", + "output_folder", null, + "model", "mouse", + "ensemble", false, + "section_number", true, + "propagate_angle", true, + "enforce_index_order", true, + "use_enforce_index_spacing", false, + "enforce_index_spacing", "None" + ).get(); + + ij.command().run(DeepSliceFolderCommand.class, true, + "input_folder", "src/test/resources/deepslice_test_folder_single", + "output_folder", null, + "model", "mouse", + "ensemble", false, + "section_number", true, + "propagate_angle", false, + "enforce_index_order", false, + "use_enforce_index_spacing", false, + "enforce_index_spacing", "None" + ).get(); + + ij.command().run(DeepSliceFolderCommand.class, true, + "input_folder", "src/test/resources/deepslice_test_folder_double", + "output_folder", null, + "model", "mouse", + "ensemble", false, + "section_number", true, + "propagate_angle", false, + "enforce_index_order", false, + "use_enforce_index_spacing", false, + "enforce_index_spacing", "None" + ).get(); + + } +} diff --git a/src/test/java/DemoRegistration.java b/src/test/java/DemoRegistration.java index 3a895d0..5a3b48e 100644 --- a/src/test/java/DemoRegistration.java +++ b/src/test/java/DemoRegistration.java @@ -16,8 +16,8 @@ public static void main(String... args) throws Exception { new ImagePlus("src/test/resources/blobs-rot15deg.tif").show(); RegisterHelper rh = (RegisterHelper) ij.command().run(Elastix_Register.class, true, - "fixed_image", "blobs.tif", - "moving_image", "blobs-rot15deg.tif", + "fixed_image", "blobs-rot15deg.tif", + "moving_image", "blobs.tif", "rigid", true, "fast_affine", false, "affine", true, @@ -27,7 +27,7 @@ public static void main(String... args) throws Exception { ij.command().run(Transformix_TransformImgPlus.class, true, "rh", rh, - "img_in", "blobs-rot15deg.tif" + "img_in", "blobs.tif" ); } diff --git a/src/test/resources/deepslice_test_folder/results.json b/src/test/resources/deepslice_test_folder/results.json index e537329..6679a8c 100644 --- a/src/test/resources/deepslice_test_folder/results.json +++ b/src/test/resources/deepslice_test_folder/results.json @@ -1 +1 @@ -{"name": "", "target": "ABA_Mouse_CCFv3_2017_25um.cutlas", "aligner": "prerelease_1.0.0", "slices": [{"filename": "deepslice_test_folder\\Section_s000.jpg", "anchoring": [499.9523803576818, 343.7968496369665, 375.294952865236, -556.5848593430806, 12.63448832978338, 16.468824607955185, -9.398692774352696, -1.9334693265826672, -479.7371949092775], "height": 306, "width": 437, "nr": 0, "markers": []}, {"filename": "deepslice_test_folder\\Section_s001.jpg", "anchoring": [505.6635445861323, 316.03625689630127, 387.5868057330812, -568.0494334310507, 12.826831124103421, 1.6253069415994332, -1.7678386505690469, -2.0883631592162715, -475.8652302617503], "height": 306, "width": 437, "nr": 1, "markers": []}, {"filename": "deepslice_test_folder\\Section_s002.jpg", "anchoring": [497.44367853213373, 294.5127000077424, 400.40272149506995, -559.8774154214541, 12.598809133395662, -8.123029744818837, 5.653776763888345, -2.2568113409326997, -476.07989679793883], "height": 306, "width": 437, "nr": 2, "markers": []}, {"filename": "deepslice_test_folder\\Section_s003.jpg", "anchoring": [510.5337996196529, 279.55950656220153, 379.7513614939203, -561.4997011691145, 12.822354462442604, 33.67425481964193, -23.37793981712815, -1.5915742219361846, -473.8308723253468], "height": 306, "width": 437, "nr": 3, "markers": []}, {"filename": "deepslice_test_folder\\Section_s004.jpg", "anchoring": [507.74561792239285, 250.27406301355873, 390.38546147853197, -565.1042154643862, 12.794015854924538, 9.149551530557574, -5.43999432992814, -1.9905533620180051, -472.524510965407], "height": 306, "width": 437, "nr": 4, "markers": []}, {"filename": "deepslice_test_folder\\Section_s005.jpg", "anchoring": [514.4678620020013, 237.87735957274458, 384.0046866156413, -562.6625289862687, 12.785594786352704, 19.587396027808268, -13.637418759808043, -1.7695034700157066, -464.46398422911585], "height": 306, "width": 437, "nr": 5, "markers": []}, {"filename": "deepslice_test_folder\\Section_s006.jpg", "anchoring": [505.92524965938367, 220.2171697850744, 391.0282319848342, -552.2024010318015, 12.512223340224551, 11.244996474307868, -11.236674910423972, -1.7795994215349822, -454.6072762857161], "height": 306, "width": 437, "nr": 6, "markers": []}, {"filename": "deepslice_test_folder\\Section_s007.jpg", "anchoring": [496.2012981430258, 197.7002591956458, 406.0403608910871, -552.5727805218758, 12.422010311762676, -10.794999192420562, 6.351255180363353, -2.1665891228413727, -452.387361621869], "height": 306, "width": 437, "nr": 7, "markers": []}, {"filename": "deepslice_test_folder\\Section_s008.jpg", "anchoring": [501.26227570968985, 181.10076299300596, 394.5377565195999, -556.6243421985243, 12.605497960016407, 9.787540723411837, -8.968808102097114, -1.872022375587079, -463.8292879784733], "height": 306, "width": 437, "nr": 8, "markers": []}, {"filename": "deepslice_test_folder\\Section_s009.jpg", "anchoring": [501.952424212457, 156.7442671618744, 400.75882616599114, -552.1898973289444, 12.488692836317057, 6.046834976552475, -6.974034391833811, -1.874926209708235, -454.4137035307595], "height": 306, "width": 437, "nr": 9, "markers": []}, {"filename": "deepslice_test_folder\\Section_s010.jpg", "anchoring": [498.2453147302789, 132.9401054248435, 389.61395454583067, -556.5965683527716, 12.509632470957854, -11.507258196228236, 8.54592038459458, -2.104655610011605, -427.4657968907174], "height": 306, "width": 437, "nr": 10, "markers": []}, {"filename": "deepslice_test_folder\\Section_s011.jpg", "anchoring": [493.7364736242781, 126.00814822160322, 386.5076884103962, -561.7963249995054, 12.653555140990363, -5.5649722081682285, 7.950481371269575, -2.119764668407953, -433.8480791951136], "height": 306, "width": 437, "nr": 11, "markers": []}]} \ No newline at end of file +{"name": "", "target": "ABA_Mouse_CCFv3_2017_25um.cutlas", "aligner": "prerelease_1.0.0", "slices": [{"filename": "deepslice_test_folder\\Section_s000.jpg", "anchoring": [498.48117410419513, 350.6925209721278, 368.0510644114035, -553.5373642548519, 2.2867326312044725, 14.476492510845674, -7.574715530680123, -14.068149758654783, -471.3313813900163], "height": 306, "width": 437, "nr": 0, "markers": []}, {"filename": "deepslice_test_folder\\Section_s001.jpg", "anchoring": [502.2416276301825, 331.1775459026617, 375.4990042003614, -559.20032561742, 1.8889441779983827, 0.5389287196387613, 1.663252376988794, -13.751123788899406, -459.6943409121956], "height": 306, "width": 437, "nr": 1, "markers": []}, {"filename": "deepslice_test_folder\\Section_s002.jpg", "anchoring": [497.8171388978558, 303.13095738989256, 393.1293449972537, -566.3154718376036, 1.7380327370249802, -5.304930916529656, 6.384579870302559, -13.980790086139336, -466.8462885743433], "height": 306, "width": 437, "nr": 2, "markers": []}, {"filename": "deepslice_test_folder\\Section_s003.jpg", "anchoring": [512.1424143225496, 283.26149141105486, 375.8942177633071, -560.6081679477857, 2.9823418219260134, 36.947942024470535, -24.645603040189258, -13.848635155160366, -465.902149412809], "height": 306, "width": 437, "nr": 3, "markers": []}, {"filename": "deepslice_test_folder\\Section_s004.jpg", "anchoring": [507.69811768690454, 271.0005502443215, 376.4427870437435, -557.3246683413784, 2.215624972833666, 11.674274147602716, -8.543620072640579, -13.466743550826607, -451.3269963143421], "height": 306, "width": 437, "nr": 4, "markers": []}, {"filename": "deepslice_test_folder\\Section_s005.jpg", "anchoring": [515.9257680256874, 246.29644868415173, 377.2295129289684, -560.8988358478844, 2.4462592804291603, 18.987033971928838, -13.827031332035858, -13.497886457435044, -452.9602825289118], "height": 306, "width": 437, "nr": 5, "markers": []}, {"filename": "deepslice_test_folder\\Section_s006.jpg", "anchoring": [507.7622569321897, 230.02378547044503, 384.89693412792747, -550.3258979267487, 2.20809989864253, 12.206437294811167, -7.784024348920241, -13.174834133581186, -441.4795540159606], "height": 306, "width": 437, "nr": 6, "markers": []}, {"filename": "deepslice_test_folder\\Section_s007.jpg", "anchoring": [498.01456944815425, 210.4626018422605, 393.15917631747476, -549.8426665329398, 1.7427417618429502, -3.302458112774559, 3.7369415768537237, -13.164378936488333, -439.83949207619236], "height": 306, "width": 437, "nr": 7, "markers": []}, {"filename": "deepslice_test_folder\\Section_s008.jpg", "anchoring": [502.54122104256027, 190.49983665298586, 384.30767846873573, -556.3782559973802, 2.243242975631688, 12.703772671972047, -8.959972229312086, -13.527355045336321, -453.4006710782572], "height": 306, "width": 437, "nr": 8, "markers": []}, {"filename": "deepslice_test_folder\\Section_s009.jpg", "anchoring": [501.29181243437733, 163.80440145688885, 388.138294922117, -543.7479087256368, 2.023747223483241, 6.7778226881926, -6.332104035987641, -13.068958726483942, -437.7761292540059], "height": 306, "width": 437, "nr": 9, "markers": []}, {"filename": "deepslice_test_folder\\Section_s010.jpg", "anchoring": [500.9946133280887, 141.10104096066198, 380.2585723305913, -552.5781524056971, 1.4055925893198946, -14.88418062254857, 10.015744929554558, -12.256036990608749, -408.7584357580422], "height": 306, "width": 437, "nr": 10, "markers": []}, {"filename": "deepslice_test_folder\\Section_s011.jpg", "anchoring": [493.2800149998785, 132.98862132291006, 379.70367186863945, -562.4269129517229, 1.7460187264828733, -4.6022466218105365, 4.282262601394336, -12.694138890154889, -424.05211599966566], "height": 306, "width": 437, "nr": 11, "markers": []}]} \ No newline at end of file diff --git a/src/test/resources/deepslice_test_folder_double/Section_s004.jpg b/src/test/resources/deepslice_test_folder_double/Section_s004.jpg new file mode 100644 index 0000000..edb8f37 Binary files /dev/null and b/src/test/resources/deepslice_test_folder_double/Section_s004.jpg differ diff --git a/src/test/resources/deepslice_test_folder_double/Section_s007.jpg b/src/test/resources/deepslice_test_folder_double/Section_s007.jpg new file mode 100644 index 0000000..27062e8 Binary files /dev/null and b/src/test/resources/deepslice_test_folder_double/Section_s007.jpg differ diff --git a/src/test/resources/deepslice_test_folder_double/results.json b/src/test/resources/deepslice_test_folder_double/results.json new file mode 100644 index 0000000..f5622c1 --- /dev/null +++ b/src/test/resources/deepslice_test_folder_double/results.json @@ -0,0 +1 @@ +{"name": "", "target": "ABA_Mouse_CCFv3_2017_25um.cutlas", "aligner": "prerelease_1.0.0", "slices": [{"filename": "deepslice_test_folder_double\\Section_s004.jpg", "anchoring": [507.6295166015625, 281.8793029785156, 375.8902587890625, -557.3164672851562, -3.26045560836792, 11.819828033447266, -8.352317810058594, -38.49862289428711, -449.88720703125], "height": 306, "width": 437, "nr": 4, "markers": []}, {"filename": "deepslice_test_folder_double\\Section_s007.jpg", "anchoring": [498.0075988769531, 209.27745056152344, 393.1946105957031, -549.8264770507812, 4.504228115081787, -3.3850231170654297, 3.7370471954345703, -13.156675338745117, -439.8397216796875], "height": 306, "width": 437, "nr": 7, "markers": []}]} \ No newline at end of file diff --git a/src/test/resources/deepslice_test_folder_single/Section_s007.jpg b/src/test/resources/deepslice_test_folder_single/Section_s007.jpg new file mode 100644 index 0000000..27062e8 Binary files /dev/null and b/src/test/resources/deepslice_test_folder_single/Section_s007.jpg differ diff --git a/src/test/resources/deepslice_test_folder_single/results.json b/src/test/resources/deepslice_test_folder_single/results.json new file mode 100644 index 0000000..8cd81da --- /dev/null +++ b/src/test/resources/deepslice_test_folder_single/results.json @@ -0,0 +1 @@ +{"name": "", "target": "ABA_Mouse_CCFv3_2017_25um.cutlas", "aligner": "prerelease_1.0.0", "slices": [{"filename": "deepslice_test_folder_single\\Section_s007.jpg", "anchoring": [498.0075988769531, 209.27745056152344, 393.1946105957031, -549.8264770507812, 4.504228115081787, -3.3850231170654297, 3.7370471954345703, -13.156675338745117, -439.8397216796875], "height": 306, "width": 437, "nr": 7, "markers": []}]} \ No newline at end of file