├── .formatter
└── java-imagej-coding-style.xml
├── .gitignore
├── .travis.yml
├── .travis
├── build.sh
└── signingkey.asc.enc
├── CHANGELOG.md
├── LICENSE.txt
├── README.md
├── doc
├── eclipse-code-clean-up.xml
├── eclipse-code-formatter.xml
└── eclipse-import-order.importorder
├── pom.xml
├── script
└── CARE_generic.py
└── src
├── main
└── java
│ ├── de
│ └── csbdresden
│ │ └── csbdeep
│ │ ├── commands
│ │ ├── GenericCoreNetwork.java
│ │ ├── GenericIsotropicNetwork.java
│ │ ├── GenericNetwork.java
│ │ ├── GenericTableNetwork.java
│ │ ├── NetIso.java
│ │ ├── NetPlanaria.java
│ │ ├── NetProject.java
│ │ ├── NetTribolium.java
│ │ └── NetTubulin.java
│ │ ├── converter
│ │ ├── ByteRealConverter.java
│ │ ├── DoubleRealConverter.java
│ │ ├── FloatRealConverter.java
│ │ ├── IntRealConverter.java
│ │ ├── LongRealConverter.java
│ │ └── RealIntConverter.java
│ │ ├── imglib2
│ │ ├── GridView.java
│ │ └── TiledView.java
│ │ ├── io
│ │ ├── DatasetOutputProcessor.java
│ │ ├── DefaultInputProcessor.java
│ │ ├── InputProcessor.java
│ │ ├── OutputProcessor.java
│ │ └── TableOutputProcessor.java
│ │ ├── network
│ │ ├── DefaultInputMapper.java
│ │ ├── DefaultInputValidator.java
│ │ ├── DefaultModelExecutor.java
│ │ ├── DefaultModelLoader.java
│ │ ├── InputMapper.java
│ │ ├── InputValidator.java
│ │ ├── ModelExecutor.java
│ │ ├── ModelLoader.java
│ │ └── model
│ │ │ ├── DefaultNetwork.java
│ │ │ ├── ImageTensor.java
│ │ │ ├── Network.java
│ │ │ ├── NetworkSettings.java
│ │ │ └── tensorflow
│ │ │ ├── DatasetTensorFlowConverter.java
│ │ │ ├── TensorFlowNetwork.java
│ │ │ └── TensorFlowRunner.java
│ │ ├── normalize
│ │ ├── DefaultInputNormalizer.java
│ │ ├── GenericMinMax.java
│ │ ├── HistogramPercentile.java
│ │ ├── InputNormalizer.java
│ │ ├── Normalizer.java
│ │ ├── Percentile.java
│ │ └── PercentileNormalizer.java
│ │ ├── task
│ │ ├── DefaultTask.java
│ │ ├── DefaultTaskManager.java
│ │ ├── DefaultTaskPresenter.java
│ │ ├── Task.java
│ │ ├── TaskForce.java
│ │ ├── TaskForceManager.java
│ │ ├── TaskManager.java
│ │ └── TaskPresenter.java
│ │ ├── tiling
│ │ ├── AdvancedTiledView.java
│ │ ├── DefaultInputTiler.java
│ │ ├── DefaultOutputTiler.java
│ │ ├── DefaultTiling.java
│ │ ├── InputTiler.java
│ │ ├── OutputTiler.java
│ │ └── Tiling.java
│ │ ├── ui
│ │ ├── CSBDeepProgress.java
│ │ └── MappingDialog.java
│ │ └── util
│ │ ├── ArrayHelper.java
│ │ ├── DatasetHelper.java
│ │ └── IOHelper.java
│ └── mpicbg
│ └── csbd
│ └── commands
│ └── GenericNetwork.java
└── test
├── java
└── de
│ └── csbdresden
│ └── csbdeep
│ ├── CSBDeepTest.java
│ ├── commands
│ ├── GenericIsotropicNetworkTest.java
│ ├── GenericNetworkTest.java
│ ├── GenericNetworksMismatchTest.java
│ ├── GenericNetworksMultipleCallsTest.java
│ ├── GenericTableNetworkTest.java
│ ├── NetIsoTest.java
│ ├── NetPlanariaTest.java
│ ├── NetProjectTest.java
│ ├── NetTriboliumTest.java
│ ├── NetTubulinTest.java
│ ├── OOMThrowingNetwork.java
│ ├── OOMThrowingTest.java
│ ├── TestCSBDeepCommand.java
│ └── TestSwingThreadCommand.java
│ ├── network
│ ├── InputMapperTest.java
│ ├── TestNetwork.java
│ ├── TestNetworkSingle2D2D.java
│ ├── TestNetworkSingle3D2D.java
│ ├── TestNetworkSingle3D3D.java
│ └── model
│ │ ├── ImageTensorTest.java
│ │ └── tensorflow
│ │ ├── TensorflowCommand.java
│ │ └── TensorflowTest.java
│ ├── normalize
│ ├── NormalizeTest.java
│ └── PercentileTest.java
│ └── tasks
│ ├── AllTasksTest.java
│ ├── InputProcessorTest.java
│ ├── PseudoNetwork.java
│ └── TilingTest.java
└── resources
└── de
└── csbdresden
└── csbdeep
└── commands
├── denoise2D
└── model.zip
├── denoise3D
└── model.zip
├── isoNet
└── model.zip
└── upsampling3D
└── model.zip
/.gitignore:
--------------------------------------------------------------------------------
1 | # Maven
2 | /target/
3 |
4 | # Eclipse
5 | /.project
6 | /.classpath
7 | /.settings/
8 |
9 | # IntelliJ
10 | /.idea/
11 | /*.iml
12 |
13 | # Custom
14 | /models/
15 | /bin/
16 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk: openjdk8
3 | branches:
4 | only:
5 | - master
6 | - "/.*-[0-9]+\\..*/"
7 | install: true
8 | script: ".travis/build.sh"
9 | cache:
10 | directories:
11 | - "~/.m2/repository"
12 | env:
13 | global:
14 | - secure: IHaP/zS26MBahE+hTwBBbJQciYoJN8w+Riumca4OQKc1c1nT4mqbWFXeEQ/U9bqM69NPyS0pHxo7fFkRKdLH6V/a3rZOOTtCxSC4Q4fapxcY1Q1Z9ToYOCm+wjjgXNFXKg0wVC4Dh96Ptgi/S7ctquYTuCnBEhtW8wGbeVy3xzjNwjNJKpsOz3HF7kK5CA9dZTF7+mmoM2yTxKvywhnizDscZbQNQtZ+OXf0jxjVdfQS3XBXn3mfPo4eE+SoytMAGdSoRsaukkHCQo6aLmE+t3QIBzjzS+ads8dCMuXK5pNrr3pOk9SaEm/CWZE1Bux5LuQk95HiaEeVL3l0P7yeHFy2QgRrdec+I7b/guBEX7DqT2rzDhm/fDFM0SrQF9DUKPON/D3gz026diDNpT70Q6jCxGGQPZIgaZ8r2F14G/Tp1lzGUT6QhHm/F4C3nrUEv+nXAjJzz1MPlBP2qXxNHAbeyLtnXMB2AB3RN6rwNhNdYwrfg/6fdr3u3t7g79+CHRshKP56/cghcQmytTD+t1apu0VQ7VtaTZabstB7FFDC6BCVkGwP7MwJhy62wvjUFzP2UBF37SSojqs0pAcU9DkZPDYtPLR3u65oM9v+g4ilEPakTDfDSgttcHK9CBb7JoSod8ptL9Yx0uXfMboSFz1DF+EdTUPvy0nTP4QKI7o=
15 | - secure: EPK0ncwwsyRt3w/GOox/S6qISKlj9o25VRIQ+RXZrCTFluYeV+PnfQplnT2GXd4DOE4ON1GXsbDIPdsaNER8290zzNj2TlkPzhP6xjfSYbVkh2LO7vzBSW8G3xGEMioddWGUXQMyjaAaSlg4nihJXni0qqrn+edJ4Z5bO5mCOKwqzY5cNkCV6eoeLIy8vqikzWPgpvt8XTmZtfqfAeQkxbGlhy2UtpfBb3USKgRQZaLHPwdkTtMX6/3qhVSdn+qE+PT9w4vAbR7VrPUIodL26EDjaLVVJHWprMgk28q749/kTuL/m1CtBX0EmOYyrUNBgw2O3QKxZ3BiEwR7CS1rBTAY6eId8zFsTeu07uSmYyB4oA/EPx3E7c29xjrEghSuo2y7Mr+ZcN4PiQ7YoglI3rz9tDgmCIqZCQdzPyts/jT3cW/ZI9F4nkP+gNXQYohaIDIh4wcfKPGrCk4cPo4L8KIRsuUpcuofCmQwMRmCvZ0y6J4ooH12p/1kRj/O0XqUGlZlGJS9paAwpRq01o6jvfb/khA7Lt4baDsFYeamJD8yz2Unklf1Ew+6tqyy1eIoy/1ksGGx8uCEzHvRj0HNLF58uc4ol4+SBFn+QsEMyAp/nuEW8gSJmdsxwBuxDty0pF6OwXvHinVzUG8oScTX87ag1qY1FmU96k5B/CTK7LQ=
16 | - secure: PZWywNGkWuCjbXS9KbN7woy4mZH3U35817PAfHIF936nm8A5ZLjMDXDab0EsFHJ8K9ZymUKnUJtg3dqati71U5ezGzkBZqNbHt244Go/dXTRnwFoLqjGsjpaSMbSFBb5OVnDmAbPgbx0fgiUNg5wB4+ZiPIHB30HX82D2wTzJCd6++1y4Z9S2uEpr9yxtCfRFUG8sncU4P6ptzlcgI8eTZrixJiYYxO8p+KzWySafamngYtfs2AJyjSWxOSMcmtpp07G9WAmEUPW6ERkJYvkjt0WPTpnuld+YBtewWziSKRMQhEycCNGt9d/MYdqsa+Bwz+HsW7rSuPo1n692eQGjz7O7c6m8HB8nWj08JAiEuXWfvLAP9yhPY6CtjC0kWlqquflOK/FaUfMDucuWs1KyDLOxzFE2ksJLWG2+bbzoNwoqAjrDoImmoJy8gDYGP+5E9Rw76HS5MAHce2WxsOZZHiR0dSLvIaRSdaxTYJrWl+ROB2ykkOpfpI6YTsxiA+OWnXQHnRFeqFk/mpj0exqFilSOtyJCXS50XS/pdPjgEaAViyKbiwf7OAfoUDiQ+1JfaJ8sfKTfGrSuynDs8v3ULt6pF45wDbAl8USgVMCV+hKyMF03ZXS47MWKvKfNPBt6d1FFSyBwcXLWG4/ZstyMTPdBfxxSpb/3EYZrJb+IUo=
17 | - secure: DhmEFPf7j/CXYgeCoyH1FY7dwoxbYhN7qQwMW5J0PfQkc2CO6l+QKpaL3wOp/Ga8Cb/UaanNORVumpwAZx3dMR6KbQkN6eKqCckDhe/vFCZqF9yHA+JKfteW5yQdNj7ybRtme59HaTT3+EOddAs1OBAp0A6IKVJjv/l/ybkKztUgHfFMk4hejlhg700gnrClpJl1i7H5D0xon9zA0N576W/u9kiyzmhYu7PNm2LeUC5uuDo7TbqPdX/S4KyPRv9znL/DRSt++GK8iOxZVkvpt7YUcCQdQSa5QLl3fD7tmWssJZE5CmKfKuGNn2TK9rZCSu5l99ppsWFxsTTj01qshfOtXxvPD1nwIv/V64wcEPniBBViW85lEMmqYj+7LIzUMBA/pf8/XGVpUXuwJaKnNlH8ehpEtcufFmFkPyYxKYEGmnqdp4HgvgUOUdnxoPahufXqPdA1sjxQcv8pzcEseAVO2z5fDvP/EDQ7PyyVoyvfDza0bwHF+4ayMzyXrW3bO2obvyL0XUrFgOXi/tCRCmiNR6O0pMLEcBiFpA6xhOThDUfyW+ZY5E6oBasN61wJOE0yCuLMuOUtY+jvHB/LmVmlUscFzRVFrfjXpkaoTHZELx8sbb6qfp4Hw6Zih8A5mFfVyxtfarstQ+x/xkvmx+d5Ql/pW+v3cqJFgScx3j8=
18 |
--------------------------------------------------------------------------------
/.travis/build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | curl -fsLO https://raw.githubusercontent.com/scijava/scijava-scripts/master/travis-build.sh
3 | sh travis-build.sh $encrypted_c8e2e06de7df_key $encrypted_c8e2e06de7df_iv
4 |
--------------------------------------------------------------------------------
/.travis/signingkey.asc.enc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSBDeep/CSBDeep_fiji/00aeb1298d5650bcfe3c00f4d2451cad79d51038/.travis/signingkey.asc.enc
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | ## 0.5.0
4 | - updated to `imagej-tensorflow 1.1.4`
5 | - native JNIs can now be switched via `Edit > Options > TensorFlow...`
6 |
7 | ## 0.4.1
8 | - `GenericCoreNetwork`: remove menu path
9 |
10 | ## 0.4.0
11 | - Adds `GenericTableNetwork`
12 | - add `scijava-plugins-io-table` dependency
13 | - rename `DefaultOutputProcessor` to `DatasetOutputProcessor`
14 | - add `TableOutputProcessor`
15 | - move everything but the `output` Parameter and the initialization of the `OutputProcessor` from `GenericNetwork` to `GenericCoreNetwork`
16 | - `GenericCoreNetwork`: `protected abstract initOutputProcessor` method
17 | - `GenericCoreNetwork`: `protected abstract computeOutput` method
18 | - make `GenericNetwork` extending `GenericCoreNetwork` with `Dataset` output parameter
19 | - create `GenericTableNetwork` extending `GenericCoreNetwork` with `GenericTable` output parameter
20 | - `OutputProcessor` is typed now, changed signature of `run`
21 | - `ImageTensor`: add `tilingAllowed` attribute
22 | - `ImageTensor`: make a few methods private
23 | - `POM`: `pom-scijava 23.2.0` → `27.0.1`
24 | - `PercentileNormalizer`: Fix normalization for images with the same value for all pixels
25 | - Images with the same value were normalized to images of value `NaN`
26 | - now they return an image of value `0.0`
27 |
28 | ## 0.3.4
29 | - don't load `meta.json` of model since we do not use it yet
30 |
31 | ## 0.3.2
32 | - !!! `groupId` and `artifactId` changed !!!
33 | ```xml
34 | de.csbdresden
35 | csbdeep
36 | ```
37 | - package names changed in the same fashion, e.g. usage in Python script:
38 | ```python
39 | from de.csbdresden.csbdeep.commands import GenericNetwork
40 | ```
41 | - Commands now return `Dataset` instead of `List` as `output`:
42 | ```Java
43 | @Parameter(type = ItemIO.OUTPUT)
44 | protected Dataset output;
45 | ```
46 | - updated to TensorFlow CPU Version 1.12.0
47 | - Adds parameter to hide process dialog (`showProcessDialog`)
48 | - fixes for input with singleton dimensions
49 | - removes singleton dimensions of output
50 | - removes unused `batchAxis` parameter
51 | - hopefully fixing thread issues with swing actions
52 | - prints duration time of plugin run
53 | - tiling improved
54 | - see github commits for details
55 | - manageable _OOM_ throws now _WARNING_ instead of _ERROR_
56 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2017 - 2020, Deborah Schmidt, Florian Jug, Benjamin Wilhelm
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification,
5 | are permitted provided that the following conditions are met:
6 |
7 | 1. Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 |
10 | 2. Redistributions in binary form must reproduce the above copyright notice,
11 | this list of conditions and the following disclaimer in the documentation
12 | and/or other materials provided with the distribution.
13 |
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 | POSSIBILITY OF SUCH DAMAGE.
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://travis-ci.com/CSBDeep/CSBDeep_fiji)
2 |
3 | # CSBDeep Fiji Plugin
4 |
5 | ## Install
6 |
7 | ### ImageJ update site
8 | The CSBDeep plugin can be installed from the ImageJ update site `http://sites.imagej.net/CSBDeep/`. See the [CSBDeep Wiki Pages](https://github.com/CSBDeep/CSBDeep_website/wiki/CSBDeep-in-Fiji) for more details.
9 |
10 | ### From source
11 | 1. Clone this repository.
12 | 2. Run the following command from inside the repo:
13 | ```
14 | mvn -Dimagej.app.directory=/path/to/Fiji.app/ -Ddelete.other.versions=true
15 | ```
16 |
17 | ## Run demos
18 | 1. Download the [examplary image data](http://csbdeep.bioimagecomputing.com/exemplary-image-data.zip)
19 | 2. Open Fiji.
20 | 3. Open an example image, e.g. `tribolium.tif`.
21 | 4. Run the plugin via `Plugins > CSBDeep > Demo`.
22 | 5. Run the plugin by pressing `Ok`.
23 |
24 | If all goes well, an image will be displayed representing the result of the model execution.
25 |
26 | See the [CSBDeep Wiki Pages](https://github.com/CSBDeep/CSBDeep_website/wiki/CSBDeep-in-Fiji) for more details.
27 |
28 | ## Run your own model
29 | 1. Use the [python code](https://github.com/CSBDeep/CSBDeep) to train your network with your data. Export it as ZIP.
30 | 2. Open Fiji.
31 | 3. Open an image.
32 | 4. Run the plugin for any network via `Plugins > CSBDeep > Run your network`.
33 | 5. Load your exported network by pressing `Browse` on the `Import model (.zip)` line.
34 | 5. Run the plugin by pressing `Ok`.
35 |
36 | If all goes well, an image will be displayed representing the result of the model execution.
37 |
38 | See the [CSBDeep Wiki Page](https://github.com/CSBDeep/CSBDeep_website/wiki/Your-Model-in-Fiji) for more details.
39 |
40 | ## Develop
41 |
42 | ### Code Style
43 |
44 | If you use eclipse you can import our code formatter `doc/eclipse-code-formatter.xml`, code cleanup (`doc/eclipse-code-clean-up.xml`) and import order (`eclipse-import-order.importorder`) settings.
45 |
46 | ## Switching the TensorFlow version
47 |
48 | For supporting a model trained with a specific TensorFlow version or for GPU support, one has to install a specific native TensorFlow JNI. In order to achieve that, do the following:
49 | 1. Open `Edit > Options > TensorFlow...`
50 | - Choose the version matching your system / model
51 | - Wait until a message opens telling you that the library was installed
52 | - Restart Fiji
53 |
54 | ## GPU support
55 |
56 | For GPU support, two things have to be done:
57 | - install CUDA and CuDNN and make sure Fiji knows about the installation paths
58 | - install a TensorFlow version with GPU support (see section above)
59 |
60 | For further details please refer to the [CSBDeep Wiki page](https://github.com/CSBDeep/CSBDeep_website/wiki/CSBDeep-in-Fiji-–-Installation#gpu-support).
61 |
62 | ### Muliple GPUs
63 |
64 | See the according [CSBDeep Wiki page](https://github.com/CSBDeep/CSBDeep_website/wiki/CSBDeep-in-Fiji-–-Installation#multiple-gpus).
65 |
66 | ## License
67 |
68 | This project is licensed under the BSD 2-clause "Simplified" License -- see the [LICENSE.txt](LICENSE.txt) file for details.
69 |
--------------------------------------------------------------------------------
/doc/eclipse-code-clean-up.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/doc/eclipse-import-order.importorder:
--------------------------------------------------------------------------------
1 | #Organize Import Order
2 | #Fri Nov 10 15:43:53 CET 2017
3 | 5=mpicbg
4 | 4=org
5 | 3=net
6 | 2=javax
7 | 1=java
8 | 0=com
9 |
--------------------------------------------------------------------------------
/script/CARE_generic.py:
--------------------------------------------------------------------------------
1 | # @String(label="Input path (.tif or folder with .tifs)", required=false, value='/home/random/Development/imagej/project/CSBDeep/script') input
2 | # @String(label="Output path (.tif or folder)", required=false, value='/home/random/Development/imagej/project/CSBDeep/script/out') output
3 | # @String(label="Model file", required=false, value='/home/random/Development/imagej/project/CSBDeep/data/Tobias Boothe/models/phago_C2_no_transform_model.zip') modelFile
4 | # @String(label="Model name", required=false, value='phago_C2_no_transform_model') _modelName
5 | # @Integer(label="Number of tiles", required=false, value=8) nTiles
6 | # @Integer(label="Tile overlap", required=false, value=32) overlap
7 | # @Boolean(label="Normalize input", required=false, value=true) normalizeInput
8 | # @Float(label="Bottom percentile", required=false, value=3.0, stepSize=0.1) percentileBottom
9 | # @Float(label="Top percentile", required=false, value=99.8, stepSize=0.1) percentileTop
10 | # @Boolean(label="Clip", required=false, value=false) clip
11 | # @Boolean(label="Show progress dialog", required=false, value=true) showProgressDialog
12 | # @DatasetIOService io
13 | # @CommandService command
14 | # @ModuleService module
15 |
16 | from java.io import File
17 | import sys
18 | from de.csbdresden.csbdeep.commands import GenericNetwork
19 |
20 | def getFileName(path):
21 | fileparts = path.split("/")
22 | return fileparts[len(fileparts)-1]
23 |
24 | def runNetwork(inputPath, outputPath):
25 | print("input: " + inputPath + ", output: " + outputPath)
26 | imp = io.open(inputPath)
27 | mymod = (command.run(GenericNetwork, False,
28 | "input", imp,
29 | "nTiles", nTiles,
30 | "overlap", overlap,
31 | "normalizeInput", normalizeInput,
32 | "percentileBottom", percentileBottom,
33 | "percentileTop", percentileTop,
34 | "clip", clip,
35 | "showProgressDialog", showProgressDialog,
36 | "modelFile", modelFile)).get()
37 | myoutput = mymod.getOutput("output")
38 | print(myoutput)
39 | io.save(myoutput, outputPath)
40 |
41 | if input.endswith(".tif"):
42 | if output.endswith(".tif"):
43 | runNetwork(input, output)
44 | else:
45 | if not(output.endswith("/")):
46 | output += "/"
47 | runNetwork(input, output + getFileName(input))
48 | else:
49 | if output.endswith(".tif"):
50 | print("ERROR: please provide a directory as output, because your input is also a directory")
51 | sys.exit()
52 | if not(output.endswith("/")):
53 | output += "/"
54 | if not(input.endswith("/")):
55 | input += "/"
56 | if(output == input):
57 | print("ERROR: please provide an output directory that is not the same as the input directory")
58 | sys.exit()
59 | directory = File(input);
60 | listOfFilesInFolder = directory.listFiles();
61 |
62 | for file in listOfFilesInFolder:
63 | if file.toString().endswith(".tif"):
64 | runNetwork(file.toString(), output + getFileName(file.toString()))
65 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/commands/GenericNetwork.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.commands;
31 |
32 | import java.io.File;
33 | import java.util.List;
34 |
35 | import org.scijava.ItemIO;
36 | import org.scijava.command.Command;
37 | import org.scijava.plugin.Parameter;
38 | import org.scijava.plugin.Plugin;
39 |
40 | import de.csbdresden.csbdeep.io.DatasetOutputProcessor;
41 | import de.csbdresden.csbdeep.io.OutputProcessor;
42 | import net.imagej.Dataset;
43 | import net.imagej.ImageJ;
44 | import net.imglib2.RandomAccessibleInterval;
45 | import net.imglib2.type.numeric.real.FloatType;
46 |
47 | @Plugin(type = Command.class, menuPath = "Plugins>CSBDeep>Run your network")
48 | public class GenericNetwork extends GenericCoreNetwork {
49 |
50 | @Parameter(type = ItemIO.OUTPUT)
51 | protected Dataset output;
52 |
53 | @Override
54 | protected OutputProcessor initOutputProcessor() {
55 | return new DatasetOutputProcessor(datasetService);
56 | }
57 |
58 | @Override
59 | protected void computeOutput(List> output) {
60 | this.output = (Dataset) outputProcessor.run(output, network.getOutputNode());
61 | }
62 |
63 | /**
64 | * This main function serves for development purposes. It allows you to run
65 | * the plugin immediately out of your integrated development environment
66 | * (IDE).
67 | *
68 | * @param args whatever, it's ignored
69 | * @throws Exception
70 | */
71 | public static void main(final String... args) throws Exception {
72 |
73 | final ImageJ ij = new ImageJ();
74 |
75 | ij.launch(args);
76 |
77 | // ij.log().setLevel(LogLevel.TRACE);
78 |
79 | // ask the user for a file to open
80 | final File file = ij.ui().chooseFile(null, "open");
81 |
82 | if (file != null && file.exists()) {
83 | // load the dataset
84 | final Dataset dataset = ij.scifio().datasetIO().open(file
85 | .getAbsolutePath());
86 |
87 | // show the image
88 | ij.ui().show(dataset);
89 |
90 | // invoke the plugin
91 | ij.command().run(GenericNetwork.class, true);
92 | }
93 |
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/commands/GenericTableNetwork.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.commands;
31 |
32 | import java.io.File;
33 | import java.util.List;
34 |
35 | import org.scijava.ItemIO;
36 | import org.scijava.command.Command;
37 | import org.scijava.plugin.Parameter;
38 | import org.scijava.plugin.Plugin;
39 | import org.scijava.table.GenericTable;
40 |
41 | import de.csbdresden.csbdeep.io.OutputProcessor;
42 | import de.csbdresden.csbdeep.io.TableOutputProcessor;
43 | import net.imagej.Dataset;
44 | import net.imagej.ImageJ;
45 | import net.imglib2.RandomAccessibleInterval;
46 | import net.imglib2.type.numeric.real.FloatType;
47 |
48 | @Plugin(type = Command.class, headless = true)
49 | public class GenericTableNetwork extends GenericCoreNetwork {
50 |
51 | @Parameter(type = ItemIO.OUTPUT)
52 | protected GenericTable output;
53 |
54 | @Override
55 | protected OutputProcessor initOutputProcessor() {
56 | return new TableOutputProcessor();
57 | }
58 |
59 | @Override
60 | protected void computeOutput(List> output) {
61 |
62 | this.output = (GenericTable) outputProcessor.run(output, network.getOutputNode());
63 | }
64 |
65 |
66 | /**
67 | * This main function serves for development purposes. It allows you to run
68 | * the plugin immediately out of your integrated development environment
69 | * (IDE).
70 | *
71 | * @param args whatever, it's ignored
72 | * @throws Exception
73 | */
74 | public static void main(final String... args) throws Exception {
75 |
76 | final ImageJ ij = new ImageJ();
77 |
78 | ij.launch(args);
79 |
80 | // ij.log().setLevel(LogLevel.TRACE);
81 |
82 | // ask the user for a file to open
83 | final File file = ij.ui().chooseFile(null, "open");
84 |
85 | if (file != null && file.exists()) {
86 | // load the dataset
87 | final Dataset dataset = ij.scifio().datasetIO().open(file
88 | .getAbsolutePath());
89 |
90 | // show the image
91 | ij.ui().show(dataset);
92 |
93 | // invoke the plugin
94 | ij.command().run(GenericTableNetwork.class, true);
95 | }
96 |
97 | }
98 |
99 | }
100 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/commands/NetIso.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.commands;
31 |
32 | import java.io.File;
33 | import java.io.IOException;
34 | import java.util.concurrent.ExecutionException;
35 |
36 | import org.scijava.ItemIO;
37 | import org.scijava.command.Command;
38 | import org.scijava.command.CommandModule;
39 | import org.scijava.command.CommandService;
40 | import org.scijava.plugin.Parameter;
41 | import org.scijava.plugin.Plugin;
42 | import org.scijava.ui.UIService;
43 |
44 | import net.imagej.Dataset;
45 | import net.imagej.ImageJ;
46 |
47 | @Plugin(type = Command.class,
48 | menuPath = "Plugins>CSBDeep>Demo>Isotropic Reconstruction - Retina",
49 | headless = true)
50 | public class NetIso implements
51 | Command
52 | {
53 |
54 | @Parameter(type = ItemIO.INPUT)
55 | public Dataset input;
56 |
57 | @Parameter(type = ItemIO.OUTPUT)
58 | protected Dataset output;
59 |
60 | @Parameter(label = "Number of tiles", min = "1")
61 | protected int nTiles = 8;
62 |
63 | @Parameter(label = "Scale factor of Z-Axis", min = "1", max = "15")
64 | protected float scale = 10.2f;
65 |
66 | @Parameter(label = "Batch size", min = "1")
67 | protected int batchSize = 10;
68 |
69 | @Parameter(label="Show progress dialog")
70 | protected boolean showProgressDialog = true;
71 |
72 | @Parameter
73 | CommandService commandService;
74 |
75 | @Parameter
76 | UIService uiService;
77 |
78 | private String modelFileUrl = "http://csbdeep.bioimagecomputing.com/model-iso.zip";
79 |
80 | @Override
81 | public void run() {
82 |
83 | try {
84 | final CommandModule module = commandService.run(
85 | GenericIsotropicNetwork.class, false,
86 | "input", input,
87 | "modelUrl", modelFileUrl,
88 | "scale", scale,
89 | "batchSize", batchSize,
90 | "blockMultiple", 8,
91 | "nTiles", nTiles,
92 | "showProgressDialog", showProgressDialog).get();
93 | output = (Dataset) module.getOutput("output");
94 | } catch (InterruptedException e) {
95 | e.printStackTrace();
96 | } catch (ExecutionException e) {
97 | e.printStackTrace();
98 | }
99 |
100 | }
101 |
102 | public static void main(final String[] args) throws IOException {
103 | // create the ImageJ application context with all available services
104 | final ImageJ ij = new ImageJ();
105 |
106 | ij.launch(args);
107 |
108 | // ask the user for a file to open
109 | final File file = ij.ui().chooseFile(null, "open");
110 |
111 | if (file != null && file.exists()) {
112 | // load the dataset
113 | final Dataset dataset = ij.scifio().datasetIO().open(file
114 | .getAbsolutePath());
115 |
116 | // show the image
117 | ij.ui().show(dataset);
118 |
119 | // invoke the plugin
120 | ij.command().run(NetIso.class, true);
121 | }
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/commands/NetPlanaria.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.commands;
31 |
32 | import java.io.File;
33 | import java.util.concurrent.ExecutionException;
34 |
35 | import org.scijava.ItemIO;
36 | import org.scijava.command.Command;
37 | import org.scijava.command.CommandModule;
38 | import org.scijava.command.CommandService;
39 | import org.scijava.plugin.Parameter;
40 | import org.scijava.plugin.Plugin;
41 | import org.scijava.ui.UIService;
42 |
43 | import net.imagej.Dataset;
44 | import net.imagej.ImageJ;
45 |
46 | /**
47 | */
48 | @Plugin(type = Command.class,
49 | menuPath = "Plugins>CSBDeep>Demo>3D Denoising - Planaria", headless = true)
50 | public class NetPlanaria implements Command {
51 |
52 | @Parameter(type = ItemIO.INPUT)
53 | public Dataset input;
54 |
55 | @Parameter(type = ItemIO.OUTPUT)
56 | protected Dataset output;
57 |
58 | @Parameter(label = "Number of tiles", min = "1")
59 | protected int nTiles = 8;
60 |
61 | @Parameter(label="Show progress dialog")
62 | protected boolean showProgressDialog = true;
63 |
64 | @Parameter
65 | CommandService commandService;
66 |
67 | @Parameter
68 | UIService uiService;
69 |
70 | private String modelFileUrl = "http://csbdeep.bioimagecomputing.com/model-planaria.zip";
71 |
72 | @Override
73 | public void run() {
74 |
75 | try {
76 | final CommandModule module = commandService.run(
77 | GenericNetwork.class, false,
78 | "input", input,
79 | "modelUrl", modelFileUrl,
80 | // "batchSize", 10,
81 | // "batchAxis", Axes.TIME.getLabel(),
82 | "blockMultiple", 8,
83 | "nTiles", nTiles,
84 | "showProgressDialog", showProgressDialog).get();
85 | output = (Dataset) module.getOutput("output");
86 | } catch (InterruptedException e) {
87 | e.printStackTrace();
88 | } catch (ExecutionException e) {
89 | e.printStackTrace();
90 | }
91 |
92 | }
93 |
94 | public static void main(final String... args) throws Exception {
95 | // create the ImageJ application context with all available services
96 | final ImageJ ij = new ImageJ();
97 |
98 | ij.launch(args);
99 |
100 | // ask the user for a file to open
101 | final File file = ij.ui().chooseFile(null, "open");
102 |
103 | if (file != null && file.exists()) {
104 | // load the dataset
105 | final Dataset dataset = ij.scifio().datasetIO().open(file
106 | .getAbsolutePath());
107 |
108 | // show the image
109 | ij.ui().show(dataset);
110 |
111 | // invoke the plugin
112 | ij.command().run(NetPlanaria.class, true);
113 | }
114 |
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/commands/NetProject.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.commands;
31 |
32 | import java.io.File;
33 | import java.util.OptionalLong;
34 | import java.util.concurrent.ExecutionException;
35 |
36 | import org.scijava.ItemIO;
37 | import org.scijava.command.Command;
38 | import org.scijava.command.CommandModule;
39 | import org.scijava.command.CommandService;
40 | import org.scijava.plugin.Parameter;
41 | import org.scijava.plugin.Plugin;
42 | import org.scijava.ui.UIService;
43 |
44 | import de.csbdresden.csbdeep.util.DatasetHelper;
45 | import net.imagej.Dataset;
46 | import net.imagej.ImageJ;
47 |
48 | /**
49 | */
50 | @Plugin(type = Command.class,
51 | menuPath = "Plugins>CSBDeep>Demo>Surface Projection - Flywing", headless = true)
52 | public class NetProject implements Command {
53 |
54 | @Parameter(type = ItemIO.INPUT)
55 | public Dataset input;
56 |
57 | @Parameter(type = ItemIO.OUTPUT)
58 | protected Dataset output;
59 |
60 | @Parameter(label = "Number of tiles", min = "1")
61 | protected int nTiles = 8;
62 |
63 | @Parameter(label="Show progress dialog")
64 | protected boolean showProgressDialog = true;
65 |
66 | @Parameter
67 | CommandService commandService;
68 |
69 | @Parameter
70 | UIService uiService;
71 |
72 |
73 | String modelFileUrl = "http://csbdeep.bioimagecomputing.com/model-project.zip";
74 |
75 | @Override
76 | public void run() {
77 |
78 | boolean validInput = DatasetHelper.validate(input, "3D grayscale image with size order X-Y-Z", uiService.isHeadless(),
79 | OptionalLong.empty(), OptionalLong.empty(), OptionalLong.empty());
80 | if(!validInput) return;
81 |
82 | try {
83 | final CommandModule module = commandService.run(
84 | GenericNetwork.class, false,
85 | "input", input,
86 | "modelUrl", modelFileUrl,
87 | "blockMultiple", 16,
88 | "nTiles", nTiles,
89 | "showProgressDialog", showProgressDialog).get();
90 | output = (Dataset) module.getOutput("output");
91 | } catch (InterruptedException e) {
92 | e.printStackTrace();
93 | } catch (ExecutionException e) {
94 | e.printStackTrace();
95 | }
96 |
97 | }
98 |
99 | public static void main(final String... args) throws Exception {
100 |
101 | // create the ImageJ application context with all available services
102 | final ImageJ ij = new ImageJ();
103 |
104 | ij.launch(args);
105 |
106 | // ask the user for a file to open
107 | final File file = ij.ui().chooseFile(null, "open");
108 |
109 | if (file != null && file.exists()) {
110 | // load the dataset
111 | final Dataset dataset = ij.scifio().datasetIO().open(file
112 | .getAbsolutePath());
113 |
114 | // show the image
115 | if (!ij.ui().isHeadless()) {
116 | ij.ui().show(dataset);
117 | }
118 |
119 | // invoke the plugin
120 | ij.command().run(NetProject.class, true);
121 | }
122 |
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/commands/NetTribolium.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.commands;
31 |
32 | import java.io.File;
33 | import java.util.concurrent.ExecutionException;
34 |
35 | import org.scijava.ItemIO;
36 | import org.scijava.command.Command;
37 | import org.scijava.command.CommandModule;
38 | import org.scijava.command.CommandService;
39 | import org.scijava.plugin.Parameter;
40 | import org.scijava.plugin.Plugin;
41 | import org.scijava.ui.UIService;
42 |
43 | import net.imagej.Dataset;
44 | import net.imagej.ImageJ;
45 |
46 | /**
47 | */
48 | @Plugin(type = Command.class,
49 | menuPath = "Plugins>CSBDeep>Demo>3D Denoising - Tribolium", headless = true)
50 | public class NetTribolium implements Command {
51 |
52 | @Parameter(type = ItemIO.INPUT)
53 | public Dataset input;
54 |
55 | @Parameter(type = ItemIO.OUTPUT)
56 | protected Dataset output;
57 |
58 | @Parameter(label = "Number of tiles", min = "1")
59 | protected int nTiles = 8;
60 |
61 | @Parameter(label="Show progress dialog")
62 | protected boolean showProgressDialog = true;
63 |
64 | @Parameter
65 | CommandService commandService;
66 |
67 | @Parameter
68 | UIService uiService;
69 |
70 | private String modelUrl = "http://csbdeep.bioimagecomputing.com/model-tribolium.zip";
71 |
72 | @Override
73 | public void run() {
74 |
75 | try {
76 | final CommandModule module = commandService.run(
77 | GenericNetwork.class, false,
78 | "input", input,
79 | "modelUrl", modelUrl,
80 | "blockMultiple", 8,
81 | "nTiles", nTiles,
82 | "showProgressDialog", showProgressDialog).get();
83 | output = (Dataset) module.getOutput("output");
84 | } catch (InterruptedException e) {
85 | e.printStackTrace();
86 | } catch (ExecutionException e) {
87 | e.printStackTrace();
88 | }
89 | }
90 |
91 | public static void main(final String... args) throws Exception {
92 | // create the ImageJ application context with all available services
93 | final ImageJ ij = new ImageJ();
94 |
95 | ij.launch(args);
96 |
97 | // ask the user for a file to open
98 | final File file = ij.ui().chooseFile(null, "open");
99 |
100 | if (file != null && file.exists()) {
101 | // load the dataset
102 | final Dataset dataset = ij.scifio().datasetIO().open(file
103 | .getAbsolutePath());
104 |
105 | // show the image
106 | ij.ui().show(dataset);
107 |
108 | // invoke the plugin
109 | ij.command().run(NetTribolium.class, true);
110 | }
111 |
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/commands/NetTubulin.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.commands;
31 |
32 | import java.io.File;
33 | import java.util.concurrent.ExecutionException;
34 |
35 | import org.scijava.ItemIO;
36 | import org.scijava.command.Command;
37 | import org.scijava.command.CommandModule;
38 | import org.scijava.command.CommandService;
39 | import org.scijava.plugin.Parameter;
40 | import org.scijava.plugin.Plugin;
41 |
42 | import net.imagej.Dataset;
43 | import net.imagej.ImageJ;
44 |
45 | /**
46 | */
47 | @Plugin(type = Command.class,
48 | menuPath = "Plugins>CSBDeep>Demo>Deconvolution - Microtubules", headless = true)
49 | public class NetTubulin implements Command {
50 |
51 | @Parameter(type = ItemIO.INPUT)
52 | public Dataset input;
53 |
54 | @Parameter(type = ItemIO.OUTPUT)
55 | protected Dataset output;
56 |
57 | @Parameter(label = "Number of tiles", min = "1")
58 | protected int nTiles = 8;
59 |
60 | @Parameter(label = "Batch size", min = "1")
61 | protected int batchSize = 10;
62 |
63 | @Parameter(label="Show progress dialog")
64 | protected boolean showProgressDialog = true;
65 |
66 | @Parameter
67 | CommandService commandService;
68 |
69 | private String url = "http://csbdeep.bioimagecomputing.com/model-tubulin.zip";
70 |
71 | @Override
72 | public void run() {
73 | try {
74 | final CommandModule module = commandService.run(
75 | GenericNetwork.class, false,
76 | "input", input,
77 | "modelUrl", url,
78 | "batchSize", batchSize,
79 | "blockMultiple", 8,
80 | "nTiles", nTiles,
81 | "showProgressDialog", showProgressDialog).get();
82 | output = (Dataset) module.getOutput("output");
83 | } catch (InterruptedException e) {
84 | e.printStackTrace();
85 | } catch (ExecutionException e) {
86 | e.printStackTrace();
87 | }
88 | }
89 |
90 | public static void main(final String... args) throws Exception {
91 | // create the ImageJ application context with all available services
92 | final ImageJ ij = new ImageJ();
93 |
94 | ij.launch(args);
95 |
96 | // ask the user for a file to open
97 | final File file = ij.ui().chooseFile(null, "open");
98 |
99 | if (file != null && file.exists()) {
100 | // load the dataset
101 | final Dataset dataset = ij.scifio().datasetIO().open(file
102 | .getAbsolutePath());
103 |
104 | // show the image
105 | ij.ui().show(dataset);
106 |
107 | // invoke the plugin
108 | ij.command().run(NetTubulin.class, true);
109 | }
110 |
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/converter/ByteRealConverter.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.converter;
31 |
32 | import net.imglib2.converter.Converter;
33 | import net.imglib2.type.numeric.RealType;
34 | import net.imglib2.type.numeric.integer.ByteType;
35 |
36 | /**
37 | * @author Stephan Saalfeld
38 | * @author Stephan Preibisch
39 | */
40 | public class ByteRealConverter> implements
41 | Converter
42 | {
43 |
44 | @Override
45 | public void convert(final ByteType input, final R output) {
46 | output.setReal(input.getByte());
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/converter/DoubleRealConverter.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.converter;
31 |
32 | import net.imglib2.converter.Converter;
33 | import net.imglib2.type.numeric.RealType;
34 | import net.imglib2.type.numeric.real.DoubleType;
35 |
36 | /**
37 | * @author Stephan Saalfeld
38 | * @author Stephan Preibisch
39 | */
40 | public class DoubleRealConverter> implements
41 | Converter
42 | {
43 |
44 | @Override
45 | public void convert(final DoubleType input, final R output) {
46 | output.setReal(input.getRealDouble());
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/converter/FloatRealConverter.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.converter;
31 |
32 | import net.imglib2.converter.Converter;
33 | import net.imglib2.type.numeric.RealType;
34 | import net.imglib2.type.numeric.real.FloatType;
35 |
36 | /**
37 | * @author Stephan Saalfeld
38 | * @author Stephan Preibisch
39 | */
40 | public class FloatRealConverter> implements
41 | Converter
42 | {
43 |
44 | @Override
45 | public void convert(final FloatType input, final R output) {
46 | output.setReal(input.getRealFloat());
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/converter/IntRealConverter.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.converter;
31 |
32 | import net.imglib2.converter.Converter;
33 | import net.imglib2.type.numeric.RealType;
34 | import net.imglib2.type.numeric.integer.IntType;
35 |
36 | /**
37 | * @author Stephan Saalfeld
38 | * @author Stephan Preibisch
39 | */
40 | public class IntRealConverter> implements
41 | Converter
42 | {
43 |
44 | @Override
45 | public void convert(final IntType input, final R output) {
46 | output.setReal(input.getInteger());
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/converter/LongRealConverter.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.converter;
31 |
32 | import net.imglib2.converter.Converter;
33 | import net.imglib2.type.numeric.RealType;
34 | import net.imglib2.type.numeric.integer.LongType;
35 |
36 | /**
37 | * @author Stephan Saalfeld
38 | * @author Stephan Preibisch
39 | */
40 | public class LongRealConverter> implements
41 | Converter
42 | {
43 |
44 | @Override
45 | public void convert(final LongType input, final R output) {
46 | output.setReal(input.getIntegerLong());
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/converter/RealIntConverter.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.converter;
31 |
32 | import net.imglib2.converter.Converter;
33 | import net.imglib2.type.numeric.RealType;
34 | import net.imglib2.type.numeric.integer.IntType;
35 |
36 | /**
37 | * @author Stephan Saalfeld
38 | * @author Stephan Preibisch
39 | */
40 | public class RealIntConverter> implements
41 | Converter
42 | {
43 |
44 | @Override
45 | public void convert(final R input, final IntType output) {
46 | output.set((int) input.getRealFloat());
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/io/DefaultInputProcessor.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.io;
31 |
32 | import java.util.ArrayList;
33 | import java.util.List;
34 |
35 | import de.csbdresden.csbdeep.network.model.Network;
36 | import de.csbdresden.csbdeep.task.DefaultTask;
37 | import de.csbdresden.csbdeep.util.DatasetHelper;
38 | import net.imagej.Dataset;
39 | import net.imglib2.RandomAccessibleInterval;
40 | import net.imglib2.converter.Converters;
41 | import net.imglib2.converter.RealFloatConverter;
42 | import net.imglib2.type.numeric.RealType;
43 | import net.imglib2.type.numeric.real.FloatType;
44 | import net.imglib2.view.Views;
45 |
46 | public class DefaultInputProcessor> extends DefaultTask
47 | implements InputProcessor
48 | {
49 |
50 | @Override
51 | public List> run(final Dataset input, Network network) {
52 |
53 | final List> output = new ArrayList<>();
54 |
55 | setStarted();
56 |
57 | log("Dataset type: " + input.getTypeLabelLong() +
58 | ", converting to FloatType.");
59 | DatasetHelper.logDim(this, "Dataset dimensions", input);
60 |
61 | RandomAccessibleInterval rai = Converters.convert(
62 | (RandomAccessibleInterval) input.getImgPlus(),
63 | new RealFloatConverter(), new FloatType());
64 |
65 | List droppedDims = network.dropSingletonDims();
66 |
67 | rai = dropSingletonDimensions(rai, droppedDims);
68 |
69 | // Add dimensions until it fits the input tensor
70 | while (rai.numDimensions() < network.getInputNode().getNodeShape().length) {
71 | rai = Views.addDimension(rai, 0, 0);
72 | }
73 |
74 | output.add(rai);
75 |
76 | setFinished();
77 |
78 | return output;
79 |
80 | }
81 |
82 | protected static RandomAccessibleInterval dropSingletonDimensions(RandomAccessibleInterval rai, List droppedDims) {
83 | RandomAccessibleInterval res = rai;
84 |
85 | for(int d = rai.numDimensions() - 1; d >= 0; --d) {
86 | if (droppedDims.contains(d)) {
87 | res = Views.hyperSlice((RandomAccessibleInterval)res, d, rai.min(d));
88 | }
89 | }
90 | return res;
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/io/InputProcessor.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.io;
31 |
32 | import java.util.List;
33 |
34 | import de.csbdresden.csbdeep.network.model.Network;
35 | import de.csbdresden.csbdeep.task.Task;
36 | import net.imagej.Dataset;
37 | import net.imglib2.RandomAccessibleInterval;
38 | import net.imglib2.type.numeric.RealType;
39 |
40 | public interface InputProcessor> extends Task {
41 |
42 | List> run(Dataset input, Network network);
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/io/OutputProcessor.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.io;
31 |
32 | import java.util.List;
33 |
34 | import de.csbdresden.csbdeep.network.model.ImageTensor;
35 | import de.csbdresden.csbdeep.task.Task;
36 | import net.imglib2.RandomAccessibleInterval;
37 | import net.imglib2.type.numeric.RealType;
38 |
39 | public interface OutputProcessor, O> extends Task {
40 |
41 | O run(final List> result, final ImageTensor node);
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/io/TableOutputProcessor.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.csbdresden.csbdeep.io;
30 |
31 | import java.util.List;
32 |
33 | import org.scijava.table.DefaultGenericTable;
34 | import org.scijava.table.GenericTable;
35 |
36 | import de.csbdresden.csbdeep.network.model.ImageTensor;
37 | import de.csbdresden.csbdeep.task.DefaultTask;
38 | import net.imglib2.RandomAccess;
39 | import net.imglib2.RandomAccessibleInterval;
40 | import net.imglib2.type.numeric.RealType;
41 |
42 | public class TableOutputProcessor> extends DefaultTask implements OutputProcessor {
43 |
44 | @Override
45 | public GenericTable run(List> result, ImageTensor node) {
46 |
47 | RandomAccessibleInterval data = result.get(0);
48 | GenericTable table = new DefaultGenericTable();
49 | table.setColumnCount((int) Math.max(1, data.dimension(1)));
50 | table.setRowCount((int) Math.max(1, data.dimension(0)));
51 | RandomAccess ra = data.randomAccess();
52 | for (int i = 0; i < data.dimension(0); i++) {
53 | for (int j = 0; j < data.dimension(1); j++) {
54 | ra.setPosition(i, 0);
55 | ra.setPosition(j, 1);
56 | table.set(j, i, ra.get().copy());
57 | }
58 | }
59 |
60 | return table;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/network/DefaultInputMapper.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.network;
31 |
32 | import java.util.*;
33 |
34 | import de.csbdresden.csbdeep.network.model.Network;
35 | import de.csbdresden.csbdeep.task.DefaultTask;
36 | import de.csbdresden.csbdeep.util.DatasetHelper;
37 | import net.imagej.Dataset;
38 | import net.imagej.axis.Axes;
39 | import net.imagej.axis.AxisType;
40 |
41 | public class DefaultInputMapper extends DefaultTask implements InputMapper {
42 |
43 | protected AxisType[] mapping = null;
44 |
45 | private static Map axesMap = Collections.unmodifiableMap(new HashMap() {
46 | {
47 | put('X', Axes.X);
48 | put('Y', Axes.Y);
49 | put('Z', Axes.Z);
50 | put('T', Axes.TIME);
51 | put('C', Axes.CHANNEL);
52 | }
53 | });
54 |
55 | @Override
56 | public void setMapping(final AxisType[] mapping) {
57 | this.mapping = mapping;
58 | }
59 |
60 | @Override
61 | public void run(final Dataset input, final Network network) {
62 |
63 | setStarted();
64 |
65 | DatasetHelper.assignUnknownDimensions(input);
66 |
67 | if (network.isInitialized()) {
68 | network.initMapping();
69 | }
70 |
71 | // if (network.getInputNode() != null) {
72 | // if(mapping != null) {
73 | // //TODO
74 | // // network input and output have default dimension reduction.
75 | // // if the mapping is set to something different for the input, make sure to remove the same dimension slots
76 | // network.getInputNode().setMapping(mapping);
77 | // }else {
78 | // mapping = network.getInputNode().getMapping();
79 | // }
80 | // }
81 |
82 | mapping = network.getInputNode().getMapping();
83 |
84 | setFinished();
85 |
86 | }
87 |
88 | public static List parseMappingStr(String mappingStr) {
89 | List mapping = new ArrayList<>();
90 | for(int i = 0; i < mappingStr.length(); i++) {
91 | mapping.add(axesMap.get(mappingStr.charAt(i)));
92 | }
93 | return mapping;
94 | }
95 |
96 | @Override
97 | public AxisType[] getMapping() {
98 | return mapping;
99 | }
100 |
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/network/DefaultInputValidator.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.network;
31 |
32 | import de.csbdresden.csbdeep.network.model.Network;
33 | import de.csbdresden.csbdeep.task.DefaultTask;
34 | import net.imagej.Dataset;
35 | import net.imagej.axis.Axes;
36 | import net.imagej.axis.AxisType;
37 | import net.imglib2.exception.IncompatibleTypeException;
38 |
39 | public class DefaultInputValidator extends DefaultTask implements InputValidator {
40 |
41 | @Override
42 | public void run(final Dataset input, final Network network) throws IncompatibleTypeException {
43 |
44 | setStarted();
45 |
46 | checkForTooManyDimensions(input, network);
47 |
48 | for (int i = 0; i < network.getInputNode().getNodeShape().length; i++) {
49 | AxisType axis = network.getInputNode().getNodeAxis(i);
50 | long size = network.getInputNode().getNodeShape()[i];
51 | checkIfAxesWithFixedSizeExists(input, axis, size);
52 | checkScalarAxes(input, axis, size);
53 | }
54 |
55 | setFinished();
56 |
57 | }
58 |
59 | private void checkForTooManyDimensions(Dataset input, Network network) {
60 | if(network.getInputNode().getNodeShape().length == 4) {
61 | if(input.dimension(Axes.TIME) > 1 && input.dimension(Axes.Z) > 1) {
62 | throw new IncompatibleTypeException(input, "Network is meant for 2D images and can handle one additional batch dimension (Z or TIME), " +
63 | "but this dataset contains data in both Z and TIME dimension.");
64 | }
65 | }
66 | }
67 |
68 | private void checkIfAxesWithFixedSizeExists(Dataset input, AxisType axis, long size) {
69 | if(size > 1 && !input.axis(axis).isPresent()) {
70 | throw new IncompatibleTypeException(input, "Input should have axis of type " + axis.getLabel() + " and size " + size);
71 | }
72 | }
73 |
74 | private void checkScalarAxes(Dataset input, AxisType axis, long size) {
75 | if(size == 1 && input.axis(axis).isPresent() && input.dimension(axis) != size) {
76 | throw new IncompatibleTypeException(input, "Input axis of type " + axis.getLabel() +
77 | " should have size " + size + " but has size " + input.dimension(axis));
78 | }
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/network/DefaultModelLoader.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.network;
31 |
32 | import java.io.FileNotFoundException;
33 |
34 | import de.csbdresden.csbdeep.network.model.Network;
35 | import de.csbdresden.csbdeep.task.DefaultTask;
36 | import net.imagej.Dataset;
37 |
38 | public class DefaultModelLoader extends DefaultTask implements ModelLoader {
39 |
40 | @Override
41 | public void run(final String modelName, final Network network,
42 | final String modelFileUrl, final Dataset input) throws FileNotFoundException {
43 |
44 | setStarted();
45 |
46 | if (!network.isInitialized()) {
47 | try {
48 | loadNetwork(modelName, network, modelFileUrl, input);
49 | } catch (FileNotFoundException e) {
50 | setFailed();
51 | throw e;
52 | }
53 | if (!network.isInitialized()) {
54 | setFailed();
55 | return;
56 | }
57 | network.preprocess();
58 | }
59 |
60 | setFinished();
61 |
62 | }
63 |
64 | protected void loadNetwork(final String modelName, final Network network,
65 | final String modelFileUrl, final Dataset input) throws FileNotFoundException {
66 |
67 | if(modelFileUrl.isEmpty()) return;
68 |
69 | boolean loaded = network.loadModel(modelFileUrl, modelName);
70 | if(!loaded) return;
71 | network.loadInputNode(input);
72 | network.loadOutputNode(input);
73 | network.initMapping();
74 |
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/network/InputMapper.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.network;
31 |
32 | import de.csbdresden.csbdeep.network.model.Network;
33 | import de.csbdresden.csbdeep.task.Task;
34 | import net.imagej.Dataset;
35 | import net.imagej.axis.AxisType;
36 |
37 | public interface InputMapper extends Task {
38 |
39 | void setMapping(final AxisType[] mapping);
40 |
41 | void run(Dataset input, Network network);
42 |
43 | AxisType[] getMapping();
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/network/InputValidator.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.network;
31 |
32 | import de.csbdresden.csbdeep.network.model.Network;
33 | import de.csbdresden.csbdeep.task.Task;
34 | import net.imagej.Dataset;
35 | import net.imglib2.exception.IncompatibleTypeException;
36 |
37 | public interface InputValidator extends Task {
38 |
39 | void run(Dataset input, Network network) throws IncompatibleTypeException;
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/network/ModelExecutor.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.network;
31 |
32 | import java.util.List;
33 | import java.util.concurrent.ExecutionException;
34 |
35 | import org.scijava.Cancelable;
36 |
37 | import de.csbdresden.csbdeep.network.model.Network;
38 | import de.csbdresden.csbdeep.task.Task;
39 | import de.csbdresden.csbdeep.tiling.AdvancedTiledView;
40 | import net.imglib2.type.numeric.RealType;
41 |
42 | public interface ModelExecutor> extends Task, Cancelable {
43 |
44 | List> run(List> input,
45 | Network network) throws ExecutionException;
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/network/ModelLoader.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.network;
31 |
32 | import java.io.FileNotFoundException;
33 |
34 | import de.csbdresden.csbdeep.network.model.Network;
35 | import de.csbdresden.csbdeep.task.Task;
36 | import net.imagej.Dataset;
37 |
38 | public interface ModelLoader extends Task {
39 |
40 | void run(String modelName, Network network, String modelFileUrl, Dataset input) throws FileNotFoundException;
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/network/model/Network.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.network.model;
31 |
32 | import java.io.FileNotFoundException;
33 | import java.util.List;
34 | import java.util.concurrent.Callable;
35 |
36 | import org.scijava.Cancelable;
37 | import org.scijava.Disposable;
38 |
39 | import de.csbdresden.csbdeep.imglib2.TiledView;
40 | import de.csbdresden.csbdeep.task.Task;
41 | import net.imagej.Dataset;
42 | import net.imglib2.RandomAccessibleInterval;
43 | import net.imglib2.type.numeric.RealType;
44 |
45 | public interface Network> extends
46 | Callable>>, Disposable, Cancelable
47 | {
48 |
49 | boolean loadModel(String pathOrURL, String modelName)
50 | throws FileNotFoundException;
51 |
52 | void preprocess();
53 |
54 | RandomAccessibleInterval execute(RandomAccessibleInterval tile)
55 | throws Exception;
56 |
57 | Task getStatus();
58 |
59 | ImageTensor getInputNode();
60 |
61 | ImageTensor getOutputNode();
62 |
63 | void loadInputNode(Dataset dataset);
64 |
65 | void loadOutputNode(Dataset dataset);
66 |
67 | void initMapping();
68 |
69 | boolean isInitialized();
70 |
71 | void resetTileCount();
72 |
73 | void setTiledView(TiledView tiledView);
74 |
75 | default void loadLibrary(){}
76 |
77 | /**
78 | * Set if singleton dimensions of the output image should be dropped. If the
79 | * tile size in one dimension is only one this could remove an important
80 | * dimension. Default value is true.
81 | */
82 | void setDropSingletonDims(final boolean dropSingletonDims);
83 |
84 | void calculateMapping();
85 |
86 | void doDimensionReduction();
87 |
88 | boolean libraryLoaded();
89 |
90 | void clear();
91 |
92 | List dropSingletonDims();
93 | }
94 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/network/model/NetworkSettings.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.csbdresden.csbdeep.network.model;
30 |
31 | import java.util.List;
32 |
33 | public class NetworkSettings {
34 |
35 | public List axesIn;
36 | public List axesOut;
37 | public List axesDivBy;
38 | public List tileOverlap;
39 | public List tilingAllowed;
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/network/model/tensorflow/TensorFlowRunner.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.network.model.tensorflow;
31 |
32 | import java.util.concurrent.ExecutionException;
33 |
34 | import javax.swing.*;
35 |
36 | import org.tensorflow.SavedModelBundle;
37 | import org.tensorflow.Tensor;
38 | import org.tensorflow.framework.TensorInfo;
39 |
40 | public class TensorFlowRunner {
41 |
42 | /*
43 | * runs graph on input tensor
44 | *
45 | */
46 | public static Tensor executeGraph(final SavedModelBundle model,
47 | final Tensor image, final TensorInfo inputTensorInfo,
48 | final TensorInfo outputTensorInfo) throws IllegalArgumentException, ExecutionException
49 | {
50 |
51 | final Tensor output_t = model.session().runner() //
52 | .feed(opName(inputTensorInfo), image) //
53 | .fetch(opName(outputTensorInfo)) //
54 | .run().get(0);
55 |
56 | if (output_t != null) {
57 |
58 | if (output_t.numDimensions() == 0) {
59 | showError("Output tensor has no dimensions");
60 | throw new ExecutionException("Output tensor has no dimensions", null);
61 | }
62 | }
63 | else {
64 | throw new NullPointerException("Output tensor is null");
65 | }
66 | return output_t;
67 | }
68 |
69 | /**
70 | * The SignatureDef inputs and outputs contain names of the form
71 | * {@code :}, where for this model,
72 | * {@code } is always 0. This function trims the {@code :0}
73 | * suffix to get the operation name.
74 | */
75 | private static String opName(final TensorInfo t) {
76 | final String n = t.getName();
77 | if (n.endsWith(":0")) {
78 | return n.substring(0, n.lastIndexOf(":0"));
79 | }
80 | return n;
81 | }
82 |
83 | public static void showError(final String errorMsg) {
84 | JOptionPane.showMessageDialog(null, errorMsg, "Error",
85 | JOptionPane.ERROR_MESSAGE);
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/normalize/DefaultInputNormalizer.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.normalize;
31 |
32 | import de.csbdresden.csbdeep.task.DefaultTask;
33 | import net.imagej.Dataset;
34 | import net.imagej.DatasetService;
35 | import net.imagej.ops.OpService;
36 | import net.imglib2.type.NativeType;
37 | import net.imglib2.type.numeric.RealType;
38 |
39 | public class DefaultInputNormalizer & NativeType>
40 | extends DefaultTask implements InputNormalizer
41 | {
42 |
43 | private Normalizer normalizer = new PercentileNormalizer<>();
44 |
45 | @Override
46 | public Dataset run(Dataset input, OpService opService,
47 | DatasetService datasetService)
48 | {
49 |
50 | setStarted();
51 |
52 | log("Normalize .. ");
53 |
54 | final Dataset output = normalizer.normalize(input, opService,
55 | datasetService);
56 |
57 | setFinished();
58 |
59 | return output;
60 |
61 | }
62 |
63 | public Normalizer getNormalizer() {
64 | return normalizer;
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/normalize/GenericMinMax.java:
--------------------------------------------------------------------------------
1 | /*
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.normalize;
31 |
32 | import java.util.Iterator;
33 |
34 | import org.scijava.plugin.Plugin;
35 |
36 | import net.imagej.ops.Op;
37 | import net.imagej.ops.Ops;
38 | import net.imagej.ops.special.function.AbstractUnaryFunctionOp;
39 | import net.imglib2.type.numeric.RealType;
40 | import net.imglib2.util.Pair;
41 | import net.imglib2.util.ValuePair;
42 |
43 | /**
44 | * {@link Op} to calculate the {@code stats.minMax}.
45 | *
46 | * @author Stephan Preibisch
47 | * @author Stephan Saalfeld
48 | * @author Deborah Schmidt
49 | * @param input type
50 | */
51 | @Plugin(type = Ops.Stats.MinMax.class, label = "Statistics: MinMax",
52 | priority = -1)
53 | public class GenericMinMax> extends
54 | AbstractUnaryFunctionOp, Pair> implements Ops.Stats.MinMax
55 | {
56 |
57 | /**
58 | * Compute the min and max for any {@link Iterable}
59 | *
60 | * @param input - the input that has to just be {@link Iterable}
61 | */
62 | public Pair calculate(final Iterable input) {
63 |
64 | System.out.println("Generic min max calculator");
65 |
66 | // create a cursor for the image (the order does not matter)
67 | final Iterator iterator = input.iterator();
68 |
69 | // initialize min and max with the first image value
70 | I type = iterator.next();
71 |
72 | final I min = type.copy();
73 | final I max = type.copy();
74 |
75 | // loop over the rest of the data and determine min and max value
76 | while (iterator.hasNext()) {
77 | // we need this type more than once
78 | type = iterator.next();
79 |
80 | if (type.compareTo(min) < 0) min.set(type);
81 |
82 | if (type.compareTo(max) > 0) max.set(type);
83 | }
84 | return new ValuePair<>(min, max);
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/normalize/InputNormalizer.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.normalize;
31 |
32 | import de.csbdresden.csbdeep.task.Task;
33 | import net.imagej.Dataset;
34 | import net.imagej.DatasetService;
35 | import net.imagej.ops.OpService;
36 | import net.imglib2.type.NativeType;
37 | import net.imglib2.type.numeric.RealType;
38 |
39 | public interface InputNormalizer & NativeType> extends
40 | Task
41 | {
42 |
43 | Dataset run(Dataset input, OpService opService,
44 | DatasetService datasetService);
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/normalize/Normalizer.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.normalize;
31 |
32 | import net.imagej.Dataset;
33 | import net.imagej.DatasetService;
34 | import net.imagej.ops.OpService;
35 |
36 | public interface Normalizer {
37 |
38 | Dataset normalize(Dataset im, OpService opService,
39 | DatasetService datasetService);
40 |
41 | void setup(float[] percentiles, float[] destValues, boolean clip);
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/normalize/Percentile.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.normalize;
31 |
32 | import net.imagej.ops.OpService;
33 | import net.imglib2.RandomAccessibleInterval;
34 | import net.imglib2.type.numeric.RealType;
35 |
36 | public interface Percentile> {
37 |
38 | float[] computePercentiles(final RandomAccessibleInterval im,
39 | final float[] percentiles, OpService opService);
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/normalize/PercentileNormalizer.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.normalize;
31 |
32 | import net.imagej.Dataset;
33 | import net.imagej.DatasetService;
34 | import net.imagej.axis.AxisType;
35 | import net.imagej.ops.OpService;
36 | import net.imglib2.Cursor;
37 | import net.imglib2.RandomAccess;
38 | import net.imglib2.RandomAccessibleInterval;
39 | import net.imglib2.type.NativeType;
40 | import net.imglib2.type.numeric.RealType;
41 | import net.imglib2.type.numeric.real.FloatType;
42 |
43 | public class PercentileNormalizer & NativeType>
44 | implements Normalizer
45 | {
46 |
47 | private float[] percentiles = new float[] { 3, 99.7f };
48 | private float[] destValues = new float[] { 0, 1 };
49 | private float[] resValues;
50 | private boolean clip = false;
51 |
52 | protected float min;
53 | protected float max;
54 | protected float factor;
55 |
56 | public float normalize( final T val ) {
57 | if ( clip ) { return Math.max(
58 | min,
59 | Math.min( max, ( val.getRealFloat() - resValues[0] ) * factor + min ) ); }
60 | return Math.max( 0, ( val.getRealFloat() - resValues[0] ) * factor + min );
61 | }
62 |
63 | @Override
64 | public Dataset normalize(final Dataset im, OpService opService,
65 | DatasetService datasetService)
66 | {
67 | HistogramPercentile percentile = new HistogramPercentile<>();
68 | resValues = percentile.computePercentiles((RandomAccessibleInterval) im
69 | .getImgPlus(), percentiles, opService);
70 | min = destValues[0];
71 | max = destValues[1];
72 | if(resValues[1] - resValues[0] < 0.0000001) factor = 1;
73 | else factor = (destValues[1] - destValues[0]) / (resValues[1] - resValues[0]);
74 |
75 | long[] dims = new long[im.numDimensions()];
76 | im.dimensions(dims);
77 | AxisType[] axes = new AxisType[im.numDimensions()];
78 | for (int i = 0; i < axes.length; i++) {
79 | axes[i] = im.axis(i).type();
80 | }
81 |
82 | final Dataset output = datasetService.create(new FloatType(), dims,
83 | "normalized input", axes);
84 |
85 | final RandomAccess in = (RandomAccess) im.getImgPlus().randomAccess();
86 | final Cursor out = (Cursor) output.getImgPlus()
87 | .localizingCursor();
88 | while (out.hasNext()) {
89 | out.fwd();
90 | in.setPosition(out);
91 | out.get().set(normalize(in.get()));
92 | }
93 |
94 | return output;
95 | }
96 |
97 | @Override
98 | public void setup(final float[] percentiles, final float[] destValues,
99 | boolean clip)
100 | {
101 | assert (percentiles.length == 2);
102 | assert (destValues.length == 2);
103 | this.percentiles = percentiles;
104 | this.destValues = destValues;
105 | this.clip = clip;
106 | }
107 |
108 | public float[] getResValues() {
109 | return resValues;
110 | }
111 |
112 | }
113 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/task/DefaultTaskManager.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.task;
31 |
32 | import org.scijava.Context;
33 | import org.scijava.log.LogService;
34 | import org.scijava.plugin.Parameter;
35 |
36 | import java.util.ArrayList;
37 | import java.util.List;
38 |
39 | public class DefaultTaskManager implements TaskManager {
40 |
41 | protected final List tasks;
42 | protected final TaskPresenter taskPresenter;
43 |
44 | @Parameter
45 | protected LogService logger;
46 |
47 | @Parameter
48 | private Context context;
49 |
50 | public DefaultTaskManager(boolean headless) {
51 | tasks = new ArrayList<>();
52 | taskPresenter = new DefaultTaskPresenter(this, headless);
53 | }
54 |
55 | @Override
56 | public void initialize() {
57 | context.inject(taskPresenter);
58 | taskPresenter.initialize();
59 | }
60 |
61 | @Override
62 | public void logWarning(String msg) {
63 | taskPresenter.logWarning(msg);
64 | logger.warn(msg);
65 | }
66 |
67 | @Override
68 | public void add(final Task task) {
69 | tasks.add(task);
70 | task.setManager(this);
71 | taskPresenter.addTask(task.getTitle());
72 | }
73 |
74 | @Override
75 | public boolean isCanceled() {
76 | return false;
77 | }
78 |
79 | @Override
80 | public void cancel(String reason) {
81 | for (final Task task : tasks) {
82 | task.cancel(reason);
83 | }
84 | }
85 |
86 | @Override
87 | public String getCancelReason() {
88 | return null;
89 | }
90 |
91 | @Override
92 | public void debug(final String msg) {
93 | taskPresenter.debug(msg);
94 | logger.debug(msg);
95 | }
96 |
97 | @Override
98 | public void log(final String msg) {
99 | taskPresenter.log(msg);
100 | logger.info(msg);
101 | }
102 |
103 | @Override
104 | public void logError(final String msg) {
105 | taskPresenter.logError(msg);
106 | logger.error(msg);
107 | }
108 |
109 | @Override
110 | public void finalizeSetup() {
111 | taskPresenter.show();
112 | }
113 |
114 | @Override
115 | public void update(final Task task) {
116 | final int index = tasks.indexOf(task);
117 | if (task.isStarted()) {
118 | taskPresenter.setTaskStarted(index);
119 | }
120 | if (task.isFailed()) {
121 | taskPresenter.setTaskFailed(index);
122 | }
123 | if (task.isFinished()) {
124 | taskPresenter.setTaskDone(index);
125 | }
126 | }
127 |
128 | @Override
129 | public void close() {
130 | taskPresenter.close();
131 | }
132 |
133 | }
134 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/task/Task.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.task;
31 |
32 | import org.scijava.Cancelable;
33 |
34 | public interface Task extends Cancelable {
35 |
36 | void setManager(TaskManager manager);
37 |
38 | boolean isStarted();
39 |
40 | boolean isFinished();
41 |
42 | boolean isFailed();
43 |
44 | void setStarted();
45 |
46 | void setIdle();
47 |
48 | void setFailed();
49 |
50 | void setFinished();
51 |
52 | void setFinished(boolean finished);
53 |
54 | boolean hasMultipleSteps();
55 |
56 | int numSteps();
57 |
58 | void setNumSteps(int steps);
59 |
60 | void nextStep();
61 |
62 | boolean hasIterations();
63 |
64 | int numIterations();
65 |
66 | void addIteration();
67 |
68 | void startNewIteration();
69 |
70 | void setIterations(int iterations);
71 |
72 | void nextIteration();
73 |
74 | void debug(String msg);
75 |
76 | void log(String msg);
77 |
78 | void logError(String msg);
79 |
80 | int getCurrentIteration();
81 |
82 | void setCurrentIteration(int currentIteration);
83 |
84 | int getCurrentStep();
85 |
86 | void setCurrentStep(int currentStep);
87 |
88 | String getTitle();
89 |
90 | void setTitle(String title);
91 |
92 | void logWarning(String s);
93 | }
94 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/task/TaskForce.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.task;
31 |
32 | public class TaskForce extends DefaultTask {
33 |
34 | private final Task[] tasks;
35 | private final TaskPresenter taskPresenter;
36 |
37 | public TaskForce(final String codeName, final Task[] tasks,
38 | final TaskPresenter taskPresenter)
39 | {
40 | setTitle(codeName);
41 | this.tasks = tasks;
42 | this.taskPresenter = taskPresenter;
43 | }
44 |
45 | public void update(int index) {
46 | boolean allFinished = true;
47 | setIdle();
48 | int numSteps = 0;
49 | int currentStep = 0;
50 | for (final Task task : tasks) {
51 | if (!task.isFinished()) {
52 | allFinished = false;
53 | }
54 | else {
55 | numSteps += task.numSteps();
56 | currentStep += task.numSteps();
57 | }
58 | if (task.isStarted()) {
59 | setStarted();
60 | numSteps += task.numSteps();
61 | currentStep += task.getCurrentStep();
62 | }
63 | if (task.isFailed()) {
64 | setFailed();
65 | break;
66 | }
67 | }
68 | if (!isFailed() && allFinished) {
69 | setFinished();
70 | }
71 | setNumSteps(numSteps);
72 | setCurrentStep(currentStep);
73 | if (numSteps() > 1) {
74 | taskPresenter.setTaskNumSteps(index, numSteps());
75 | taskPresenter.setTaskStep(index, getCurrentStep());
76 | }
77 | }
78 |
79 | public Task[] getTasks() {
80 | return tasks;
81 | }
82 |
83 | @Override
84 | public void cancel(String reason) {
85 | for (final Task task : tasks) {
86 | task.cancel(reason);
87 | }
88 | }
89 |
90 | @Override
91 | public void setStarted() {
92 | started = true;
93 | failed = false;
94 | updateManager();
95 | }
96 |
97 | @Override
98 | public void setIdle() {
99 | started = false;
100 | failed = false;
101 | updateManager();
102 | }
103 |
104 | @Override
105 | public void setFailed() {
106 | updateManager();
107 | }
108 |
109 | @Override
110 | public void setFinished() {
111 | setFinished(true);
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/task/TaskForceManager.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.task;
31 |
32 | import java.util.ArrayList;
33 | import java.util.List;
34 |
35 | public class TaskForceManager extends DefaultTaskManager {
36 |
37 | private final List taskForces;
38 |
39 | public TaskForceManager(boolean headless) {
40 | super(headless);
41 | taskForces = new ArrayList<>();
42 | }
43 |
44 | @Override
45 | public void add(final Task task) {}
46 |
47 | @Override
48 | public void cancel(String reason) {
49 | for (final Task task : taskForces) {
50 | task.cancel(reason);
51 | }
52 | }
53 |
54 | @Override
55 | public void update(final Task task) {
56 |
57 | int index = taskForces.indexOf(task);
58 | if (index == -1) {
59 | TaskForce taskForce = null;
60 | for (int i = 0; i < taskForces.size() && index < 0; i++) {
61 | for (final Task subtask : taskForces.get(i).getTasks()) {
62 | if (task.equals(subtask)) {
63 | index = i;
64 | taskForce = taskForces.get(i);
65 | break;
66 | }
67 | }
68 | }
69 | if (index < 0 || taskForce == null) return;
70 | taskForce.update(index);
71 | }
72 | else {
73 | final TaskForce taskForce = taskForces.get(index);
74 | if (taskForce.isStarted()) {
75 | taskPresenter.setTaskStarted(index);
76 | if (task.numSteps() > 1) {
77 | taskPresenter.setTaskNumSteps(index, task.numSteps());
78 | taskPresenter.setTaskStep(index, task.getCurrentStep());
79 | }
80 | }
81 | if (taskForce.isFailed()) {
82 | taskPresenter.setTaskFailed(index);
83 | }
84 | if (taskForce.isFinished()) {
85 | taskPresenter.setTaskDone(index);
86 | }
87 | }
88 | }
89 |
90 | public void createTaskForce(final String codeName,
91 | final T... tasks)
92 | {
93 | final TaskForce taskForce = new TaskForce(codeName, tasks, taskPresenter);
94 | taskForces.add(taskForce);
95 | taskForce.setManager(this);
96 | taskPresenter.addTask(taskForce.getTitle());
97 | for (final Task task : tasks) {
98 | task.setManager(this);
99 | }
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/task/TaskManager.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.task;
31 |
32 | import org.scijava.Cancelable;
33 |
34 | public interface TaskManager extends Cancelable {
35 |
36 | void initialize();
37 |
38 | void add(Task task);
39 |
40 | void debug(String msg);
41 |
42 | void log(String msg);
43 |
44 | void logError(String msg);
45 |
46 | void finalizeSetup();
47 |
48 | void update(Task task);
49 |
50 | void close();
51 |
52 | void logWarning(String msg);
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/task/TaskPresenter.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.task;
31 |
32 | public interface TaskPresenter {
33 |
34 | void initialize();
35 |
36 | void addTask(String title);
37 |
38 | void setTaskDone(int index);
39 |
40 | void setTaskFailed(int index);
41 |
42 | void setTaskStarted(int index);
43 |
44 | void setTaskInProgress(int index);
45 |
46 | void setTaskNumSteps(final int index, final int numSteps);
47 |
48 | void setTaskStep(final int index, final int step);
49 |
50 | void debug(String msg);
51 |
52 | void log(String msg);
53 |
54 | void logError(String msg);
55 |
56 | void close();
57 |
58 | void show();
59 |
60 | void logWarning(String msg);
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/tiling/AdvancedTiledView.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.tiling;
31 |
32 | import java.util.ArrayList;
33 | import java.util.HashMap;
34 | import java.util.List;
35 | import java.util.Map;
36 |
37 | import de.csbdresden.csbdeep.imglib2.TiledView;
38 | import net.imagej.axis.AxisType;
39 | import net.imglib2.RandomAccessibleInterval;
40 | import net.imglib2.type.numeric.RealType;
41 |
42 | public class AdvancedTiledView> extends TiledView {
43 |
44 | private final Map originalDims;
45 | private final AxisType[] originalAxes;
46 | private List> processedTiles;
47 | // protected int blockMultiple;
48 | // protected long blockWidth;
49 |
50 | public AdvancedTiledView(final RandomAccessibleInterval source,
51 | final long[] blockSize, final long[] overlap, final AxisType[] axes)
52 | {
53 | super(source, blockSize, overlap);
54 | processedTiles = new ArrayList<>();
55 | originalDims = new HashMap<>();
56 | this.originalAxes = axes;
57 | }
58 |
59 | public long[] getOverlapComplete() {
60 | long[] overlap = new long[originalAxes.length];
61 | for(int i = 0; i < numDimensions(); i++) {
62 | overlap[i] = super.getOverlap()[i];
63 | }
64 | return overlap;
65 | }
66 |
67 | public Map getOriginalDims() {
68 | return originalDims;
69 | }
70 |
71 | public List> getProcessedTiles() {
72 | return processedTiles;
73 | }
74 |
75 | public AxisType[] getOriginalAxes() {
76 | return originalAxes;
77 | }
78 |
79 | public void dispose() {
80 | // if(originalDims != null) {
81 | // originalDims.clear();
82 | // }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/tiling/DefaultInputTiler.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.tiling;
31 |
32 | import java.util.List;
33 | import java.util.stream.Collectors;
34 |
35 | import de.csbdresden.csbdeep.task.DefaultTask;
36 | import net.imagej.axis.AxisType;
37 | import net.imglib2.RandomAccessibleInterval;
38 | import net.imglib2.type.numeric.RealType;
39 |
40 | public class DefaultInputTiler> extends DefaultTask
41 | implements InputTiler
42 | {
43 |
44 | @Override
45 | public List> run(
46 | final List> input, final AxisType[] axes,
47 | final Tiling tiling, final Tiling.TilingAction[] tilingActions)
48 | {
49 |
50 | setStarted();
51 |
52 | final List output = input.stream().map(image -> tiling.preprocess(image,
53 | axes, tilingActions, this)).collect(Collectors.toList());
54 |
55 | setFinished();
56 |
57 | return output;
58 |
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/tiling/DefaultOutputTiler.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.tiling;
31 |
32 | import java.util.ArrayList;
33 | import java.util.List;
34 |
35 | import de.csbdresden.csbdeep.task.DefaultTask;
36 | import net.imagej.axis.AxisType;
37 | import net.imglib2.RandomAccessibleInterval;
38 | import net.imglib2.type.numeric.RealType;
39 |
40 | public class DefaultOutputTiler> extends DefaultTask
41 | implements OutputTiler
42 | {
43 |
44 | @Override
45 | public List> run(
46 | final List> input, final Tiling tiling,
47 | final AxisType[] axisTypes)
48 | {
49 |
50 | setStarted();
51 |
52 | final List> output = new ArrayList<>();
53 |
54 | if(input != null) {
55 | for (AdvancedTiledView image : input) {
56 | output.add(tiling.postprocess(this, image, axisTypes));
57 | }
58 |
59 | }
60 |
61 | setFinished();
62 |
63 | return output;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/tiling/InputTiler.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.tiling;
31 |
32 | import java.util.List;
33 |
34 | import de.csbdresden.csbdeep.task.Task;
35 | import net.imagej.axis.AxisType;
36 | import net.imglib2.RandomAccessibleInterval;
37 | import net.imglib2.type.numeric.RealType;
38 |
39 | public interface InputTiler> extends Task {
40 |
41 | List> run(
42 | List> input, AxisType[] axes,
43 | Tiling tiling, Tiling.TilingAction[] tilingActions);
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/tiling/OutputTiler.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.tiling;
31 |
32 | import java.util.List;
33 |
34 | import de.csbdresden.csbdeep.task.Task;
35 | import net.imagej.axis.AxisType;
36 | import net.imglib2.RandomAccessibleInterval;
37 | import net.imglib2.type.numeric.RealType;
38 |
39 | public interface OutputTiler> extends Task {
40 |
41 | List> run(List> input,
42 | Tiling tiling, AxisType[] axisTypes);
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/tiling/Tiling.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.tiling;
31 |
32 | import de.csbdresden.csbdeep.task.Task;
33 | import net.imagej.axis.AxisType;
34 | import net.imglib2.RandomAccessibleInterval;
35 | import net.imglib2.type.numeric.RealType;
36 |
37 | public interface Tiling> {
38 |
39 | enum TilingAction {
40 | NO_TILING, // e.g. Channel
41 | TILE_WITH_PADDING, // e.g. X,Y,Z
42 | TILE_WITHOUT_PADDING // e.g. TIME
43 | }
44 |
45 | AdvancedTiledView preprocess(RandomAccessibleInterval input, AxisType[] axes, TilingAction[] tilingActions, Task parent);
46 |
47 | RandomAccessibleInterval postprocess(Task parent,
48 | final AdvancedTiledView results, AxisType[] axisTypes);
49 |
50 | int getTilesNum();
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/de/csbdresden/csbdeep/util/ArrayHelper.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.util;
31 |
32 | import java.util.ArrayList;
33 | import java.util.List;
34 |
35 | public class ArrayHelper {
36 |
37 | public static void replaceNegativeIndicesWithUnusedIndices(
38 | final List arr)
39 | {
40 | final List indices = new ArrayList<>();
41 | for (int i = 0; i < arr.size(); i++) {
42 | indices.add(arr.get(i));
43 | }
44 | for (int i = 0; i < arr.size(); i++) {
45 | if (!indices.contains(i)) {
46 | for (int j = 0; j < arr.size(); j++) {
47 | if (arr.get(j) == null) {
48 | arr.set(j, i);
49 | break;
50 | }
51 | }
52 | }
53 | }
54 | }
55 |
56 | public static int[] toIntArray(final List list) {
57 | final int[] ret = new int[list.size()];
58 | for (int i = 0; i < ret.length; i++)
59 | ret[i] = list.get(i);
60 | return ret;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/mpicbg/csbd/commands/GenericNetwork.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package mpicbg.csbd.commands;
31 |
32 | /*
33 | * The CSBDeep code moved from the mpicbg.csbd package to de.csbdresden.csbdeep.
34 | */
35 | @Deprecated
36 | public class GenericNetwork
37 | {
38 | }
39 |
--------------------------------------------------------------------------------
/src/test/java/de/csbdresden/csbdeep/commands/GenericNetworkTest.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.commands;
31 |
32 | import static junit.framework.TestCase.assertNotNull;
33 |
34 | import java.io.File;
35 | import java.net.URL;
36 | import java.util.concurrent.ExecutionException;
37 |
38 | import org.junit.Test;
39 | import org.scijava.module.Module;
40 |
41 | import de.csbdresden.csbdeep.CSBDeepTest;
42 | import net.imagej.Dataset;
43 | import net.imagej.axis.Axes;
44 | import net.imagej.axis.AxisType;
45 | import net.imglib2.type.NativeType;
46 | import net.imglib2.type.numeric.RealType;
47 | import net.imglib2.type.numeric.integer.ByteType;
48 | import net.imglib2.type.numeric.integer.UnsignedIntType;
49 | import net.imglib2.type.numeric.real.FloatType;
50 |
51 | public class GenericNetworkTest extends CSBDeepTest {
52 |
53 | @Test
54 | public void testMissingNetwork() throws ExecutionException, InterruptedException {
55 | launchImageJ();
56 | final Dataset input = createDataset(new FloatType(), new long[]{2,2}, new AxisType[]{Axes.X, Axes.Y});
57 | final Module module = ij.command().run(GenericNetwork.class,
58 | false, "input", input, "modelFile", new File(
59 | "/some/non/existing/path.zip")).get();
60 | }
61 |
62 | @Test
63 | public void testNonExistingNetworkPref() throws ExecutionException, InterruptedException {
64 | launchImageJ();
65 | String bla = new GenericNetwork().getModelFileKey();
66 | ij.prefs().put(GenericNetwork.class, bla, "/something/useless");
67 | final Dataset input = createDataset(new FloatType(), new long[]{2,2}, new AxisType[]{Axes.X, Axes.Y});
68 | ij.command().run(GenericNetwork.class,
69 | true, "input", input, "modelUrl", "http://csbdeep.bioimagecomputing.com/model-tubulin.zip").get();
70 | }
71 |
72 | @Test
73 | public void testGenericNetwork() {
74 | launchImageJ();
75 | for (int i = 0; i < 1; i++) {
76 |
77 | testDataset(new FloatType(), new long[] { 10, 10, 10 }, new AxisType[] {
78 | Axes.X, Axes.Y, Axes.Z });
79 | testDataset(new UnsignedIntType(), new long[] { 10, 10, 10 },
80 | new AxisType[] { Axes.X, Axes.Y, Axes.Z });
81 | testDataset(new ByteType(), new long[] { 10, 10, 10 }, new AxisType[] {
82 | Axes.X, Axes.Y, Axes.Z });
83 |
84 | if (i % 10 == 0) System.out.println(i);
85 | }
86 |
87 | }
88 |
89 | public & NativeType> void testDataset(final T type,
90 | final long[] dims, final AxisType[] axes) {
91 |
92 | URL networkUrl = this.getClass().getResource("denoise3D/model.zip");
93 |
94 | final Dataset input = createDataset(type, dims, axes);
95 | try {
96 | final Module module = ij.command().run(GenericNetwork.class,
97 | false, "input", input, "modelFile", new File(networkUrl.getPath())).get();
98 | Dataset output = (Dataset) module.getOutput("output");
99 | assertNotNull(output);
100 | testResultAxesAndSize(input, output);
101 | } catch (InterruptedException e) {
102 | e.printStackTrace();
103 | } catch (ExecutionException e) {
104 | e.printStackTrace();
105 | }
106 |
107 | }
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/src/test/java/de/csbdresden/csbdeep/commands/GenericNetworksMismatchTest.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.commands;
31 |
32 | import static org.junit.Assert.assertNotNull;
33 |
34 | import java.io.File;
35 | import java.net.URL;
36 |
37 | import org.junit.Test;
38 | import org.scijava.module.Module;
39 |
40 | import de.csbdresden.csbdeep.CSBDeepTest;
41 | import net.imagej.Dataset;
42 | import net.imagej.axis.Axes;
43 | import net.imagej.axis.AxisType;
44 | import net.imglib2.type.numeric.real.FloatType;
45 |
46 | public class GenericNetworksMismatchTest extends CSBDeepTest {
47 |
48 | @Test
49 | public void test3DNetworkWith3DInputImage() {
50 |
51 | launchImageJ();
52 |
53 | Dataset input = createDataset(new FloatType(), new long[] { 10, 20, 1 }, new AxisType[] {
54 | Axes.X, Axes.Y, Axes.Z });
55 |
56 | test("denoise3D/model.zip", input);
57 |
58 | }
59 |
60 | @Test
61 | public void test2DNetworkWith2DInputImage() {
62 |
63 | launchImageJ();
64 |
65 | Dataset input = createDataset(new FloatType(), new long[] { 10, 10, 20 }, new AxisType[] {
66 | Axes.X, Axes.Y, Axes.Z });
67 |
68 | test("denoise2D/model.zip", input);
69 | test("denoise2D/model.zip", input);
70 |
71 | }
72 |
73 | @Test
74 | public void test3DNetworkWith2DInputImage() {
75 |
76 | launchImageJ();
77 |
78 | Dataset input = createDataset(new FloatType(), new long[] { 10, 20 }, new AxisType[] {
79 | Axes.X, Axes.Y });
80 |
81 | test("denoise3D/model.zip", input);
82 |
83 | }
84 |
85 | @Test
86 | public void test2DNetworkWith3DInputImage() {
87 |
88 | launchImageJ();
89 |
90 | Dataset input = createDataset(new FloatType(), new long[] { 10, 20, 30 }, new AxisType[] {
91 | Axes.X, Axes.Y, Axes.Z });
92 |
93 | test("denoise2D/model.zip", input);
94 |
95 | }
96 |
97 | private void test(String network, Dataset input) {
98 | URL networkUrl = this.getClass().getResource(network);
99 | try {
100 | final Module module = ij.command().run(GenericNetwork.class,
101 | false,
102 | "input", input,
103 | "modelFile", new File(networkUrl.getPath()),
104 | "overlap", 2).get();
105 | assertNotNull(module);
106 | final Dataset output = (Dataset) module.getOutput("output");
107 | assertNotNull(output);
108 | testResultAxesAndSize(input, output);
109 | } catch (Exception e) {
110 | e.printStackTrace();
111 | }
112 | }
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/src/test/java/de/csbdresden/csbdeep/commands/GenericNetworksMultipleCallsTest.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.commands;
31 |
32 | import static org.junit.Assert.assertEquals;
33 | import static org.junit.Assert.assertNotEquals;
34 | import static org.junit.Assert.assertNotNull;
35 |
36 | import java.io.File;
37 | import java.net.URL;
38 | import java.util.concurrent.Future;
39 |
40 | import org.junit.Test;
41 | import org.scijava.command.CommandModule;
42 | import org.scijava.module.Module;
43 |
44 | import de.csbdresden.csbdeep.CSBDeepTest;
45 | import net.imagej.Dataset;
46 | import net.imagej.axis.Axes;
47 | import net.imagej.axis.AxisType;
48 | import net.imglib2.type.numeric.real.FloatType;
49 |
50 | public class GenericNetworksMultipleCallsTest extends CSBDeepTest {
51 |
52 | @Test
53 | public void testMultipleGenericNetworks() {
54 |
55 | launchImageJ();
56 |
57 | String[] networks = {"denoise2D/model.zip",
58 | "denoise3D/model.zip"};
59 |
60 | Dataset input = createDataset(new FloatType(), new long[] { 10, 10, 10 }, new AxisType[] {
61 | Axes.X, Axes.Y, Axes.Z });
62 |
63 | for (int i = 0; i < 3; i++) {
64 | for(String networkSrc : networks) {
65 | URL networkUrl = this.getClass().getResource(networkSrc);
66 | final Future future = ij.command().run(GenericNetwork.class,
67 | false,
68 | "input", input,
69 | "modelFile", new File(networkUrl.getPath()),
70 | "overlap", 2);
71 | assertNotEquals(null, future);
72 | final Module module = ij.module().waitFor(future);
73 | final Dataset output = (Dataset) module.getOutput("output");
74 | assertNotNull(output);
75 | printDim("input", input);
76 | printAxes("input", input);
77 | printDim("output", output);
78 | printAxes("output", output);
79 | for (int j = 0; j < input.numDimensions(); j++) {
80 | assertEquals(input.dimension(j), output.dimension(j));
81 | assertEquals(input.axis(j).type(), output.axis(j).type());
82 | }
83 | }
84 | }
85 |
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/src/test/java/de/csbdresden/csbdeep/commands/GenericTableNetworkTest.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.commands;
31 |
32 | import static junit.framework.TestCase.assertNotNull;
33 |
34 | import java.io.File;
35 | import java.net.URL;
36 | import java.util.concurrent.ExecutionException;
37 |
38 | import org.junit.Test;
39 | import org.scijava.module.Module;
40 | import org.scijava.table.GenericTable;
41 |
42 | import de.csbdresden.csbdeep.CSBDeepTest;
43 | import net.imagej.Dataset;
44 | import net.imagej.axis.Axes;
45 | import net.imagej.axis.AxisType;
46 | import net.imglib2.type.numeric.real.FloatType;
47 |
48 | public class GenericTableNetworkTest extends CSBDeepTest {
49 |
50 | @Test
51 | public void testGenericNetwork() {
52 | launchImageJ();
53 |
54 | URL networkUrl = this.getClass().getResource("denoise2D/model.zip");
55 |
56 | final Dataset input = createDataset(new FloatType(), new long[] { 3, 3, 3 }, new AxisType[] {
57 | Axes.X, Axes.Y, Axes.Z });
58 |
59 | try {
60 | final Module module = ij.command().run(GenericTableNetwork.class,
61 | false, "input", input, "modelFile", new File(networkUrl.getPath())).get();
62 | GenericTable output = (GenericTable) module.getOutput("output");
63 | assertNotNull(output);
64 | System.out.println(output);
65 | } catch (InterruptedException | ExecutionException e) {
66 | e.printStackTrace();
67 | }
68 |
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/src/test/java/de/csbdresden/csbdeep/commands/NetIsoTest.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.commands;
31 |
32 | import static org.junit.Assert.*;
33 |
34 | import java.util.concurrent.Future;
35 |
36 | import org.junit.Test;
37 | import org.scijava.command.CommandModule;
38 | import org.scijava.module.Module;
39 |
40 | import de.csbdresden.csbdeep.CSBDeepTest;
41 | import net.imagej.Dataset;
42 | import net.imagej.axis.Axes;
43 | import net.imagej.axis.AxisType;
44 | import net.imglib2.type.NativeType;
45 | import net.imglib2.type.numeric.RealType;
46 | import net.imglib2.type.numeric.real.FloatType;
47 |
48 | public class NetIsoTest extends CSBDeepTest {
49 |
50 | @Test
51 | public void testNetIsoInvalidDataset() {
52 | launchImageJ();
53 | final Dataset input = createDataset(new FloatType(), new long[] {5, 10}, new AxisType[]
54 | {Axes.X, Axes.Y});
55 | final Dataset result = runPlugin(NetIso.class, input);
56 | assertNull(result);
57 | }
58 |
59 | @Test
60 | public void testNetIso() {
61 | testDataset(new FloatType(), new long[] { 5, 10, 2, 5 }, new AxisType[] {
62 | Axes.X, Axes.Y, Axes.CHANNEL, Axes.Z });
63 | }
64 |
65 | public & NativeType> void testDataset(final T type,
66 | final long[] dims, final AxisType[] axes)
67 | {
68 |
69 | launchImageJ();
70 | final Dataset input = createDataset(type, dims, axes);
71 | final Future future = ij.command().run(NetIso.class, false,
72 | "input", input, "scale", 1.5);
73 | assertNotEquals(null, future);
74 | final Module module = ij.module().waitFor(future);
75 | final Dataset output = (Dataset) module.getOutput("output");
76 |
77 | assertNotNull(output);
78 | testResultAxesAndSize(input, output);
79 | }
80 |
81 | @Override
82 | protected void testResultAxesAndSize(final Dataset input,
83 | final Dataset output)
84 | {
85 | printDim("input", input);
86 | printAxes("input", input);
87 | printDim("output", output);
88 | printAxes("output", output);
89 | int i_output = 0;
90 | for (int i = 0; i < input.numDimensions(); i++) {
91 | final AxisType axis = input.axis(i).type();
92 | if (axis == Axes.Z) {
93 | assertTrue(
94 | "Z axis dimension size output should be greater than input size ",
95 | output.dimension(i_output) > input.dimension(i));
96 | }else {
97 | if (axis == Axes.CHANNEL) {
98 | assertTrue(
99 | "Since the iso network is probabilistic, the channels should double",
100 | output.dimension(i_output) == input.dimension(i)*2);
101 | }
102 | else {
103 | assertEquals(input.dimension(i), output.dimension(i_output));
104 | }
105 | }
106 | assertEquals(axis, output.axis(i_output).type());
107 | i_output++;
108 | }
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/src/test/java/de/csbdresden/csbdeep/commands/NetPlanariaTest.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.commands;
31 |
32 | import static junit.framework.TestCase.assertNotNull;
33 | import static org.junit.Assert.assertNull;
34 |
35 | import org.junit.Test;
36 |
37 | import de.csbdresden.csbdeep.CSBDeepTest;
38 | import net.imagej.Dataset;
39 | import net.imagej.axis.Axes;
40 | import net.imagej.axis.AxisType;
41 | import net.imglib2.type.NativeType;
42 | import net.imglib2.type.numeric.RealType;
43 | import net.imglib2.type.numeric.integer.ByteType;
44 | import net.imglib2.type.numeric.real.FloatType;
45 |
46 | public class NetPlanariaTest extends CSBDeepTest {
47 |
48 | @Test
49 | public void testPlanariaFloatTypeXY() {
50 | testDataset(new FloatType(), new long[] { 4, 3 }, new AxisType[] {
51 | Axes.X, Axes.Y });
52 | }
53 |
54 | @Test
55 | public void testPlanariaFloatTypeXYZ() {
56 | testDataset(new FloatType(), new long[] { 4, 3, 2 }, new AxisType[] {
57 | Axes.X, Axes.Y, Axes.Z });
58 | }
59 |
60 | @Test
61 | public void testPlanariaFloatTypeXYZC() {
62 | testDataset(new FloatType(), new long[] { 3, 4, 10, 1 }, new AxisType[] {
63 | Axes.X, Axes.Y, Axes.Z, Axes.CHANNEL });
64 | }
65 |
66 | @Test
67 | public void testPlanariaInvalidDataset() {
68 | launchImageJ();
69 | final Dataset input = createDataset(new FloatType(), new long[] { 3, 4, 10, 2 }, new AxisType[]
70 | { Axes.X, Axes.Y, Axes.Z, Axes.CHANNEL });
71 | final Dataset result = runPlugin(NetPlanaria.class, input);
72 | assertNull(result);
73 | }
74 |
75 | @Test
76 | public void testPlanariaFloatTypeXZY() {
77 | testDataset(new FloatType(), new long[] { 5, 10, 1 }, new AxisType[] {
78 | Axes.X, Axes.Z, Axes.Y });
79 | }
80 |
81 | @Test
82 | public void testNetPlanariaByteType() {
83 | testDataset(new ByteType(), new long[] { 20, 10, 5 }, new AxisType[] {
84 | Axes.X, Axes.Y, Axes.Z });
85 | }
86 |
87 | public & NativeType> void testDataset(final T type,
88 | final long[] dims, final AxisType[] axes)
89 | {
90 |
91 | launchImageJ();
92 | final Dataset input = createDataset(type, dims, axes);
93 | final Dataset output = runPlugin(NetPlanaria.class, input);
94 | assertNotNull(output);
95 | testResultAxesAndSize(input, output);
96 | }
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/src/test/java/de/csbdresden/csbdeep/commands/NetProjectTest.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.commands;
31 |
32 | import static junit.framework.TestCase.assertNotNull;
33 | import static org.junit.Assert.assertNull;
34 |
35 | import org.junit.Ignore;
36 | import org.junit.Test;
37 |
38 | import de.csbdresden.csbdeep.CSBDeepTest;
39 | import net.imagej.Dataset;
40 | import net.imagej.axis.Axes;
41 | import net.imagej.axis.AxisType;
42 | import net.imglib2.type.NativeType;
43 | import net.imglib2.type.numeric.RealType;
44 | import net.imglib2.type.numeric.integer.ByteType;
45 | import net.imglib2.type.numeric.real.FloatType;
46 |
47 | public class NetProjectTest extends CSBDeepTest {
48 |
49 | @Test
50 | public void testNetProjectInvalidDatasetXY() {
51 | launchImageJ();
52 | final Dataset input = createDataset(new FloatType(), new long[] {5, 10}, new AxisType[]
53 | {Axes.X, Axes.Y});
54 | final Dataset result = runPlugin(NetProject.class, input);
55 | assertNull(result);
56 | }
57 |
58 | @Test
59 | public void testNetProjectInvalidDatasetXYZT() {
60 | launchImageJ();
61 | final Dataset input = createDataset(new FloatType(), new long[] {5, 10, 5, 10}, new AxisType[]
62 | {Axes.X, Axes.Y, Axes.Z, Axes.TIME});
63 | final Dataset result = runPlugin(NetProject.class, input);
64 | assertNull(result);
65 | }
66 |
67 | // @Ignore
68 | @Test
69 | public void testNetProject_Float_XYZ() {
70 | testDataset(new FloatType(), new long[] { 10, 5, 3 }, new AxisType[] {
71 | Axes.X, Axes.Y, Axes.Z });
72 | }
73 |
74 | @Ignore
75 | @Test
76 | public void testNetProject_Float_ZXY() {
77 | testDataset(new FloatType(), new long[] { 2, 5, 10 }, new AxisType[] {
78 | Axes.Z, Axes.X, Axes.Y });
79 | }
80 |
81 | @Ignore
82 | @Test
83 | public void testNetProject_Float_XZY() {
84 | testDataset(new FloatType(), new long[] { 10, 2, 5 }, new AxisType[] {
85 | Axes.X, Axes.Z, Axes.Y });
86 | }
87 |
88 | @Ignore
89 | @Test
90 | public void testNetProject_Byte_XZY() {
91 | testDataset(new ByteType(), new long[] { 5, 2, 10 }, new AxisType[] {
92 | Axes.X, Axes.Z, Axes.Y });
93 | }
94 |
95 | public & NativeType> void testDataset(final T type,
96 | final long[] dims, final AxisType[] axes)
97 | {
98 |
99 | launchImageJ();
100 | final Dataset input = createDataset(type, dims, axes);
101 | final Dataset output = runPlugin(NetProject.class, input);
102 | assertNotNull(output);
103 | testResultAxesAndSizeByRemovingAxis(input, output, Axes.Z);
104 | }
105 |
106 | }
107 |
--------------------------------------------------------------------------------
/src/test/java/de/csbdresden/csbdeep/commands/NetTriboliumTest.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.commands;
31 |
32 | import static junit.framework.TestCase.assertNotNull;
33 |
34 | import org.junit.Assert;
35 | import org.junit.Test;
36 |
37 | import de.csbdresden.csbdeep.CSBDeepTest;
38 | import net.imagej.Dataset;
39 | import net.imagej.axis.Axes;
40 | import net.imagej.axis.AxisType;
41 | import net.imglib2.type.NativeType;
42 | import net.imglib2.type.numeric.RealType;
43 | import net.imglib2.type.numeric.real.FloatType;
44 |
45 | public class NetTriboliumTest extends CSBDeepTest {
46 |
47 | @Test
48 | public void testNetTriboliumInvalidDataset() {
49 | launchImageJ();
50 | final Dataset input = createDataset(new FloatType(), new long[] {5, 10, 10, 2}, new AxisType[]
51 | {Axes.X, Axes.Y, Axes.TIME, Axes.CHANNEL});
52 | final Dataset result = runPlugin(NetTribolium.class, input);
53 | Assert.assertNull(result);
54 | }
55 |
56 | @Test
57 | public void testNetTriboliumXYZ() {
58 | testDataset(new FloatType(), new long[] {5, 10, 2}, new AxisType[]
59 | {Axes.X, Axes.Y, Axes.Z});
60 | }
61 |
62 | @Test
63 | public void testNetTriboliumXZY() {
64 | testDataset(new FloatType(), new long[] { 5, 2, 10 }, new AxisType[] {
65 | Axes.X, Axes.Z, Axes.Y });
66 | }
67 |
68 | @Test
69 | public void testNetTriboliumXY() {
70 | testDataset(new FloatType(), new long[] {5, 10}, new AxisType[]
71 | {Axes.X, Axes.Y});
72 | }
73 |
74 | public & NativeType> void testDataset(final T type,
75 | final long[] dims, final AxisType[] axes)
76 | {
77 |
78 | launchImageJ();
79 | final Dataset input = createDataset(type, dims, axes);
80 | final Dataset output = runPlugin(NetTribolium.class, input);
81 | assertNotNull(output);
82 | testResultAxesAndSize(input, output);
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/test/java/de/csbdresden/csbdeep/commands/NetTubulinTest.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.commands;
31 |
32 | import static org.junit.Assert.assertNotNull;
33 | import static org.junit.Assert.assertNull;
34 |
35 | import org.junit.Test;
36 |
37 | import de.csbdresden.csbdeep.CSBDeepTest;
38 | import net.imagej.Dataset;
39 | import net.imagej.axis.Axes;
40 | import net.imagej.axis.AxisType;
41 | import net.imglib2.type.NativeType;
42 | import net.imglib2.type.numeric.RealType;
43 | import net.imglib2.type.numeric.real.FloatType;
44 |
45 | public class NetTubulinTest extends CSBDeepTest {
46 |
47 | @Test
48 | public void testNetTubulinInvalidDataset() {
49 | launchImageJ();
50 | final Dataset input = createDataset(new FloatType(), new long[] {15, 5, 3, 3}, new AxisType[]
51 | {Axes.X, Axes.Y, Axes.Z, Axes.TIME});
52 | final Dataset result = runPlugin(NetTubulin.class, input);
53 | assertNull(result);
54 | }
55 |
56 | @Test
57 | public void testNetTubulinXY() {
58 | testDataset(new FloatType(), new long[] { 3, 4 }, new AxisType[] {
59 | Axes.X, Axes.Y });
60 | }
61 |
62 | @Test
63 | public void testNetTubulinXYZ() {
64 | testDataset(new FloatType(), new long[] { 3, 4, 5 }, new AxisType[] {
65 | Axes.X, Axes.Y, Axes.TIME });
66 | }
67 |
68 | public & NativeType> void testDataset(final T type,
69 | final long[] dims, final AxisType[] axes)
70 | {
71 |
72 | launchImageJ();
73 | final Dataset input = createDataset(type, dims, axes);
74 | final Dataset output = runPlugin(NetTubulin.class, input);
75 | assertNotNull(output);
76 | testResultAxesAndSize(input, output);
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/test/java/de/csbdresden/csbdeep/commands/OOMThrowingNetwork.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.commands;
31 |
32 | import java.util.ArrayList;
33 | import java.util.List;
34 | import java.util.concurrent.ExecutionException;
35 |
36 | import org.scijava.ItemIO;
37 | import org.scijava.command.Command;
38 | import org.scijava.plugin.Parameter;
39 | import org.scijava.plugin.Plugin;
40 |
41 | import de.csbdresden.csbdeep.network.ModelExecutor;
42 | import de.csbdresden.csbdeep.network.model.Network;
43 | import de.csbdresden.csbdeep.task.DefaultTask;
44 | import de.csbdresden.csbdeep.tiling.AdvancedTiledView;
45 | import de.csbdresden.csbdeep.tiling.Tiling;
46 | import net.imagej.axis.AxisType;
47 | import net.imglib2.RandomAccessibleInterval;
48 |
49 | @Plugin(type = Command.class)
50 | public class OOMThrowingNetwork extends GenericNetwork
51 | {
52 |
53 | @Parameter
54 | Tiling.TilingAction[] actions;
55 |
56 | @Parameter(type = ItemIO.OUTPUT)
57 | List nTilesHistory = new ArrayList();
58 |
59 | @Parameter(type = ItemIO.OUTPUT)
60 | List batchSizeHistory = new ArrayList();
61 |
62 | private class OOMThrowingModelExecutor extends DefaultTask implements ModelExecutor {
63 | @Override
64 | public List run(List input, Network network) {
65 | throw new OutOfMemoryError();
66 | }
67 | }
68 |
69 | @Override
70 | public void initialize() {
71 | }
72 |
73 | @Override
74 | protected ModelExecutor initModelExecutor() {
75 | return new OOMThrowingModelExecutor();
76 | }
77 |
78 | @Override
79 | public void run() throws OutOfMemoryError {
80 |
81 | nTilesHistory.clear();
82 | batchSizeHistory.clear();
83 |
84 | inputTiler = initInputTiler();
85 | modelExecutor = initModelExecutor();
86 | initTiling();
87 |
88 | List list = new ArrayList();
89 | list.add(getInput().getImgPlus());
90 |
91 | try {
92 | tryToTileAndRunNetwork(list);
93 | }
94 | catch(OutOfMemoryError e) {
95 | } catch (ExecutionException e) {
96 | e.printStackTrace();
97 | }
98 |
99 | }
100 |
101 | @Override
102 | protected List tileAndRunNetwork(List input) throws ExecutionException {
103 | AxisType[] finalInputAxes = new AxisType[getInput().numDimensions()];
104 | Tiling.TilingAction[] tilingActions = actions;
105 | dummyTiling(finalInputAxes);
106 | final List tiledInput = inputTiler.run(
107 | input, finalInputAxes, tiling, tilingActions);
108 | nTiles = tiling.getTilesNum();
109 | if(tiledInput == null) return null;
110 | return modelExecutor.run(tiledInput, network);
111 | }
112 |
113 |
114 | public void dummyTiling(final AxisType[] finalInputAxes) {
115 | for (int i = 0; i < input.numDimensions(); i++) {
116 | finalInputAxes[i] = input.axis(i).type();
117 | }
118 | }
119 |
120 | @Override
121 | protected void handleOutOfMemoryError() {
122 | nTilesHistory.add(nTiles);
123 | batchSizeHistory.add(batchSize);
124 | super.handleOutOfMemoryError();
125 | }
126 |
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/src/test/java/de/csbdresden/csbdeep/commands/OOMThrowingTest.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.csbdresden.csbdeep.commands;
30 |
31 | import static org.junit.Assert.assertEquals;
32 | import static org.junit.Assert.assertNotEquals;
33 |
34 | import java.util.List;
35 | import java.util.concurrent.Future;
36 |
37 | import org.junit.Test;
38 | import org.scijava.command.CommandModule;
39 | import org.scijava.module.Module;
40 |
41 | import de.csbdresden.csbdeep.tiling.Tiling;
42 | import net.imagej.Dataset;
43 | import net.imagej.ImageJ;
44 | import net.imagej.axis.Axes;
45 | import net.imagej.axis.AxisType;
46 | import net.imglib2.type.numeric.real.FloatType;
47 |
48 | public class OOMThrowingTest {
49 |
50 | @Test
51 | public void testHandlingOfOOMs() {
52 | ImageJ ij = new ImageJ();
53 | final Dataset input = ij.dataset().create(new FloatType(), new long[]{10,20,30}, "", new AxisType[]{Axes.X, Axes.Y, Axes.Z});
54 | final Future future = ij.command().run(OOMThrowingNetwork.class, false,
55 | "input", input,
56 | "nTiles", 1,
57 | "overlap", 0,
58 | "blockMultiple", 10,
59 | "actions", new Tiling.TilingAction[]{Tiling.TilingAction.TILE_WITH_PADDING, Tiling.TilingAction.TILE_WITH_PADDING, Tiling.TilingAction.TILE_WITH_PADDING});
60 | assertNotEquals(null, future);
61 | final Module module = ij.module().waitFor(future);
62 | List nTilesHistory = (List) module.getOutput("nTilesHistory");
63 | List batchSizeHistory = (List) module.getOutput("batchSizeHistory");
64 | assertEquals(nTilesHistory.size(), batchSizeHistory.size());
65 | assertEquals(4, nTilesHistory.size());
66 | assertEquals(1, nTilesHistory.get(0));
67 | assertEquals(2, nTilesHistory.get(1));
68 | assertEquals(4, nTilesHistory.get(2));
69 | assertEquals(6, nTilesHistory.get(3));
70 | assertEquals(1, batchSizeHistory.get(0));
71 | assertEquals(1, batchSizeHistory.get(1));
72 | assertEquals(1, batchSizeHistory.get(2));
73 | assertEquals(1, batchSizeHistory.get(3));
74 | }
75 |
76 | @Test
77 | public void testHandlingOfOOMsSmallDataset() {
78 | ImageJ ij = new ImageJ();
79 | final Dataset input = ij.dataset().create(new FloatType(), new long[]{3,4,5}, "", new AxisType[]{Axes.X, Axes.Y, Axes.TIME});
80 | final Future future = ij.command().run(OOMThrowingNetwork.class, false,
81 | "input", input,
82 | "nTiles", 1,
83 | "overlap", 0,
84 | "blockMultiple", 10,
85 | "actions", new Tiling.TilingAction[]{Tiling.TilingAction.TILE_WITH_PADDING, Tiling.TilingAction.TILE_WITH_PADDING, Tiling.TilingAction.TILE_WITH_PADDING});
86 | assertNotEquals(null, future);
87 | final Module module = ij.module().waitFor(future);
88 | List nTilesHistory = (List) module.getOutput("nTilesHistory");
89 | List batchSizeHistory = (List) module.getOutput("batchSizeHistory");
90 | assertEquals(nTilesHistory.size(), batchSizeHistory.size());
91 | assertEquals(1, nTilesHistory.size());
92 | assertEquals(1, nTilesHistory.get(0));
93 | assertEquals(1, batchSizeHistory.get(0));
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/src/test/java/de/csbdresden/csbdeep/commands/TestCSBDeepCommand.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.csbdresden.csbdeep.commands;
30 |
31 | import java.io.File;
32 | import java.io.IOException;
33 | import java.util.concurrent.ExecutionException;
34 |
35 | import org.scijava.command.Command;
36 | import org.scijava.command.CommandService;
37 | import org.scijava.module.Module;
38 | import org.scijava.plugin.Parameter;
39 | import org.scijava.ui.UIService;
40 |
41 | import net.imagej.Dataset;
42 | import net.imagej.ImageJ;
43 |
44 | public class TestCSBDeepCommand implements Command {
45 |
46 | @Parameter
47 | Dataset input;
48 |
49 | @Parameter
50 | protected boolean normalizeInput = true;
51 | @Parameter
52 | protected float percentileBottom = 3.0f;
53 | @Parameter
54 | protected float percentileTop = 99.8f;
55 |
56 | @Parameter
57 | CommandService command;
58 |
59 | @Parameter
60 | UIService ui;
61 |
62 | @Override
63 | public void run() {
64 | try {
65 | Module module = command.run(GenericNetwork.class, false, "input", input,
66 | "normalizeInput", normalizeInput,
67 | "percentileBottom", percentileBottom,
68 | "percentileTop", percentileTop,
69 | "modelUrl", "http://csbdeep.bioimagecomputing.com/model-project.zip").get();
70 | ui.show(module.getOutput("output"));
71 | } catch (InterruptedException e) {
72 | e.printStackTrace();
73 | } catch (ExecutionException e) {
74 | e.printStackTrace();
75 | }
76 |
77 | }
78 |
79 | public static void main(final String[] args) throws IOException {
80 | // create the ImageJ application context with all available services
81 | final ImageJ ij = new ImageJ();
82 |
83 | ij.launch(args);
84 |
85 | // ask the user for a file to open
86 | final File file = ij.ui().chooseFile(null, "open");
87 |
88 | if (file != null && file.exists()) {
89 | // load the dataset
90 | final Dataset dataset = ij.scifio().datasetIO().open(file
91 | .getAbsolutePath());
92 |
93 | // show the image
94 | ij.ui().show(dataset);
95 |
96 | // invoke the plugin
97 | ij.command().run(TestCSBDeepCommand.class, true);
98 | }
99 | }
100 |
101 | }
102 |
--------------------------------------------------------------------------------
/src/test/java/de/csbdresden/csbdeep/commands/TestSwingThreadCommand.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.csbdresden.csbdeep.commands;
30 |
31 | import java.util.concurrent.ExecutionException;
32 |
33 | import org.scijava.Context;
34 | import org.scijava.command.Command;
35 | import org.scijava.download.DownloadService;
36 | import org.scijava.io.location.BytesLocation;
37 | import org.scijava.io.location.FileLocation;
38 | import org.scijava.io.location.Location;
39 | import org.scijava.plugin.Parameter;
40 | import org.scijava.task.Task;
41 | import org.scijava.thread.ThreadService;
42 | import org.scijava.util.ByteArray;
43 | import org.scijava.widget.Button;
44 |
45 | import net.imagej.ImageJ;
46 |
47 | public class TestSwingThreadCommand implements Command {
48 |
49 | @Parameter
50 | DownloadService downloadService;
51 |
52 | @Parameter
53 | Context context;
54 |
55 | @Parameter
56 | ThreadService threadService;
57 |
58 | @Parameter(label = "Download ZIP",
59 | callback = "downloadZipButton")
60 | private Button button;
61 |
62 | private void downloadZipButton() {
63 | threadService.run(() -> {
64 | System.out.println("Download ZIP from button");
65 | downloadZip();
66 | System.out.println("Done button action");
67 | });
68 | }
69 |
70 | @Override
71 | public void run() {
72 | System.out.println("Download ZIP from run method");
73 | downloadZip();
74 | System.out.println("Done run action");
75 | }
76 |
77 | private void downloadZip() {
78 |
79 | ByteArray byteArray = new ByteArray(1048576);
80 | BytesLocation bytes = new BytesLocation(byteArray);
81 |
82 | final Location zipLocation = new FileLocation(getClass().getResource("denoise2D/model.zip").getPath());
83 |
84 | Task task = this.downloadService.download(zipLocation, bytes).task();
85 |
86 | try {
87 | task.waitFor();
88 | } catch (InterruptedException e) {
89 | e.printStackTrace();
90 | } catch (ExecutionException e) {
91 | e.printStackTrace();
92 | }
93 |
94 | }
95 |
96 | public static void main(final String[] args) {
97 | final ImageJ ij = new ImageJ();
98 | ij.launch(args);
99 | ij.command().run(TestSwingThreadCommand.class, true);
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/src/test/java/de/csbdresden/csbdeep/network/TestNetwork.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.network;
31 |
32 | import de.csbdresden.csbdeep.network.model.tensorflow.TensorFlowNetwork;
33 | import net.imagej.Dataset;
34 | import net.imglib2.type.numeric.RealType;
35 | import org.tensorflow.framework.TensorInfo;
36 |
37 | public abstract class TestNetwork> extends
38 | TensorFlowNetwork
39 | {
40 |
41 | protected long[] inputShape;
42 | protected long[] outputShape;
43 | protected int inputCount = 1;
44 | protected int outputCount = 1;
45 |
46 | public TestNetwork()
47 | {
48 | super(null);
49 | }
50 |
51 | @Override
52 | public void loadInputNode(final Dataset dataset) {
53 | super.loadInputNode( dataset);
54 | if (inputCount > 0) {
55 | inputNode.setName("input");
56 | inputNode.setNodeShape(inputShape);
57 | inputNode.initializeNodeMapping();
58 | }
59 | }
60 |
61 | @Override
62 | public void loadOutputNode(Dataset dataset) {
63 | super.loadOutputNode(dataset);
64 | if (outputCount > 0) {
65 | outputNode.setName("output");
66 | outputNode.setNodeShape(outputShape);
67 | outputNode.initializeNodeMapping();
68 | }
69 | }
70 |
71 | @Override
72 | protected void logTensorShape(String title, final TensorInfo tensorInfo) {
73 | log("cannot log tensorinfo shape of test networks");
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/src/test/java/de/csbdresden/csbdeep/network/TestNetworkSingle2D2D.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.network;
31 |
32 | import net.imglib2.type.numeric.RealType;
33 |
34 | public class TestNetworkSingle2D2D> extends
35 | TestNetwork
36 | {
37 |
38 | public TestNetworkSingle2D2D()
39 | {
40 | super();
41 | inputShape = new long[]{-1,-1,-1,1};
42 | outputShape = new long[]{-1,-1,-1,1};
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/test/java/de/csbdresden/csbdeep/network/TestNetworkSingle3D2D.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.network;
31 |
32 | import net.imglib2.type.numeric.RealType;
33 |
34 | public class TestNetworkSingle3D2D> extends
35 | TestNetwork
36 | {
37 |
38 | public TestNetworkSingle3D2D()
39 | {
40 | super();
41 | inputShape = new long[]{-1,-1,-1,-1,1};
42 | outputShape = new long[]{-1,-1,-1,1};
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/test/java/de/csbdresden/csbdeep/network/TestNetworkSingle3D3D.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.network;
31 |
32 | import net.imglib2.type.numeric.RealType;
33 |
34 | public class TestNetworkSingle3D3D> extends
35 | TestNetwork
36 | {
37 |
38 | public TestNetworkSingle3D3D()
39 | {
40 | super();
41 | inputShape = new long[]{-1,-1,-1,-1,1};
42 | outputShape = new long[]{-1,-1,-1,-1,1};
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/test/java/de/csbdresden/csbdeep/network/model/tensorflow/TensorflowTest.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.csbdresden.csbdeep.network.model.tensorflow;
30 |
31 | import org.junit.Ignore;
32 | import org.junit.Test;
33 |
34 | import net.imagej.ImageJ;
35 |
36 | public class TensorflowTest {
37 |
38 | @Test
39 | @Ignore
40 | public void testTensorflowService() {
41 | ImageJ ij = new ImageJ();
42 | ij.ui().setHeadless(true);
43 | ij.command().run(TensorflowCommand.class, false);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/test/java/de/csbdresden/csbdeep/tasks/InputProcessorTest.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.tasks;
31 |
32 | import static org.junit.Assert.assertEquals;
33 |
34 | import java.util.List;
35 |
36 | import org.junit.Ignore;
37 | import org.junit.Test;
38 |
39 | import de.csbdresden.csbdeep.io.DefaultInputProcessor;
40 | import de.csbdresden.csbdeep.io.InputProcessor;
41 | import net.imagej.Dataset;
42 | import net.imagej.ImageJ;
43 | import net.imagej.axis.Axes;
44 | import net.imagej.axis.AxisType;
45 | import net.imglib2.RandomAccessibleInterval;
46 | import net.imglib2.type.numeric.real.FloatType;
47 |
48 | public class InputProcessorTest {
49 |
50 | @Test
51 | @Ignore
52 | public void run() {
53 | final ImageJ ij = new ImageJ();
54 |
55 | final Dataset input = ij.dataset().create(new FloatType(), new long[] { 10,
56 | 50, 100 }, "", new AxisType[] { Axes.Z, Axes.X, Axes.Y });
57 |
58 | final InputProcessor inputProcessor = new DefaultInputProcessor();
59 |
60 | final List> output = inputProcessor.run(
61 | input, null);
62 |
63 | assertEquals(1, output.size());
64 | assertEquals(10, output.get(0).dimension(0));
65 | assertEquals(50, output.get(0).dimension(1));
66 | assertEquals(100, output.get(0).dimension(2));
67 | assertEquals(1, output.get(0).dimension(3));
68 |
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/src/test/java/de/csbdresden/csbdeep/tasks/PseudoNetwork.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * CSBDeep: CNNs for image restoration of fluorescence microscopy.
4 | * %%
5 | * Copyright (C) 2017 - 2020 Deborah Schmidt, Florian Jug, Benjamin Wilhelm
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.csbdresden.csbdeep.tasks;
31 |
32 | import java.io.FileNotFoundException;
33 | import java.util.List;
34 |
35 | import org.scijava.io.location.Location;
36 |
37 | import de.csbdresden.csbdeep.network.model.DefaultNetwork;
38 | import de.csbdresden.csbdeep.network.model.ImageTensor;
39 | import de.csbdresden.csbdeep.task.Task;
40 | import net.imagej.Dataset;
41 | import net.imglib2.RandomAccessibleInterval;
42 | import net.imglib2.type.numeric.RealType;
43 |
44 | public class PseudoNetwork> extends DefaultNetwork {
45 |
46 | private long[] inputShape;
47 | private boolean initialized = false;
48 |
49 | public PseudoNetwork(Task associatedTask) {
50 | super(associatedTask);
51 | }
52 |
53 | @Override
54 | public boolean loadModel(final String pathOrURL, final String modelName)
55 | throws FileNotFoundException {
56 | return true;
57 | }
58 |
59 | @Override
60 | public void loadInputNode(final Dataset dataset) {
61 | inputNode = new ImageTensor();
62 | inputNode.initializeNodeMapping();
63 | }
64 |
65 | @Override
66 | public void loadOutputNode(Dataset dataset) {
67 | outputNode = new ImageTensor();
68 | outputNode.initializeNodeMapping();
69 | }
70 |
71 | @Override
72 | protected boolean loadModel(final Location source, final String modelName) {
73 | initialized = true;
74 | return true;
75 | }
76 |
77 | @Override
78 | public void preprocess() {
79 | initMapping();
80 | calculateMapping();
81 | }
82 |
83 | @Override
84 | public void initMapping() {
85 | inputNode.setMappingDefaults();
86 | }
87 |
88 | @Override
89 | public List dropSingletonDims() {
90 | return null;
91 | }
92 |
93 | @Override
94 | public void calculateMapping() {
95 |
96 | for (int i = 0; i < inputNode.getNodeShape().length; i++) {
97 | outputNode.setNodeAxis(i, inputNode.getNodeAxis(i));
98 | }
99 | handleDimensionReduction();
100 | inputNode.generateMapping();
101 | outputNode.generateMapping();
102 |
103 | System.out.println("INPUT NODE: ");
104 | inputNode.printMapping();
105 | System.out.println("OUTPUT NODE: ");
106 | outputNode.printMapping();
107 | }
108 |
109 | private void handleDimensionReduction() {
110 | getOutputNode().initialize(inputNode.getImage());
111 | }
112 |
113 | @Override
114 | public RandomAccessibleInterval execute(
115 | final RandomAccessibleInterval tile) throws Exception
116 | {
117 |
118 | return tile;
119 |
120 | }
121 |
122 | @Override
123 | public boolean isInitialized() {
124 | return initialized;
125 | }
126 |
127 | @Override
128 | public void doDimensionReduction() {}
129 |
130 | @Override
131 | public boolean libraryLoaded() {
132 | return true;
133 | }
134 |
135 | public long[] getInputShape() {
136 | return inputShape;
137 | }
138 |
139 | public void setInputShape(final long[] inputShape) {
140 | this.inputShape = inputShape;
141 | }
142 |
143 | }
144 |
--------------------------------------------------------------------------------
/src/test/resources/de/csbdresden/csbdeep/commands/denoise2D/model.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSBDeep/CSBDeep_fiji/00aeb1298d5650bcfe3c00f4d2451cad79d51038/src/test/resources/de/csbdresden/csbdeep/commands/denoise2D/model.zip
--------------------------------------------------------------------------------
/src/test/resources/de/csbdresden/csbdeep/commands/denoise3D/model.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSBDeep/CSBDeep_fiji/00aeb1298d5650bcfe3c00f4d2451cad79d51038/src/test/resources/de/csbdresden/csbdeep/commands/denoise3D/model.zip
--------------------------------------------------------------------------------
/src/test/resources/de/csbdresden/csbdeep/commands/isoNet/model.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSBDeep/CSBDeep_fiji/00aeb1298d5650bcfe3c00f4d2451cad79d51038/src/test/resources/de/csbdresden/csbdeep/commands/isoNet/model.zip
--------------------------------------------------------------------------------
/src/test/resources/de/csbdresden/csbdeep/commands/upsampling3D/model.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CSBDeep/CSBDeep_fiji/00aeb1298d5650bcfe3c00f4d2451cad79d51038/src/test/resources/de/csbdresden/csbdeep/commands/upsampling3D/model.zip
--------------------------------------------------------------------------------