From 8083d23f6e25c7795cb0059097c89c7d7486f629 Mon Sep 17 00:00:00 2001 From: Leonid Kostrykin Date: Tue, 12 Mar 2024 10:03:52 +0100 Subject: [PATCH 1/2] Add `orientationpy` tool Squashed commit of the following: commit cc32b97f4e9870a8617c6f0c096fce1e1cd291d7 Author: Leonid Kostrykin Date: Tue Mar 12 09:42:34 2024 +0100 Fix XML commit d71932d07dff31374af80cd87ce06818501205b1 Author: Leonid Kostrykin Date: Mon Mar 11 22:45:22 2024 +0000 Update help commit 59199b165d60c7fc181bbc3155143ad478526b82 Author: Leonid Kostrykin Date: Mon Mar 11 22:42:17 2024 +0000 Fix version commit ebbf868e66ccf4af53281ff04124d0cdc6a9c401 Author: Leonid Kostrykin Date: Mon Mar 11 22:41:13 2024 +0000 Replace `--bin_size` -> `--max_precision` commit a815c3344a1c394275bcf2d880ab9d0931173ae7 Author: Leonid Kostrykin Date: Mon Mar 11 22:22:04 2024 +0000 Fix commit e48ecdf0165586967f726bef9fb46b1968904ebd Author: Leonid Kostrykin Date: Mon Mar 11 21:47:35 2024 +0000 Fix tool commit 7c2ae177d9cd26452ba15ca483fad3051d2325b6 Author: Leonid Kostrykin Date: Mon Mar 11 21:18:51 2024 +0000 Fix commit 699e642187864def6dcf849f17b9fe23a4c4e206 Author: Leonid Kostrykin Date: Mon Mar 11 20:29:53 2024 +0000 Add tests commit 047bcf484fe23ea5448cbe4317a8b10c65877b64 Author: Leonid Kostrykin Date: Mon Mar 11 20:23:55 2024 +0000 Fix commit e68144e67a3f4b56778562401466495c2ec2feea Author: Leonid Kostrykin Date: Mon Mar 11 18:21:16 2024 +0000 Add commit e0e912fbc182a9a7f743b0db07b2f419bf6293cd Author: Leonid Kostrykin Date: Mon Mar 11 18:18:11 2024 +0000 Add `orientationpy` tool --- tools/orientationpy/.shed.yml | 8 ++ tools/orientationpy/orientationpy-cli.py | 54 +++++++++++++ tools/orientationpy/orientationpy.xml | 97 +++++++++++++++++++++++ tools/orientationpy/test-data/input1.tif | Bin 0 -> 456 bytes tools/orientationpy/test-data/input2.tif | Bin 0 -> 456 bytes 5 files changed, 159 insertions(+) create mode 100644 tools/orientationpy/.shed.yml create mode 100644 tools/orientationpy/orientationpy-cli.py create mode 100644 tools/orientationpy/orientationpy.xml create mode 100644 tools/orientationpy/test-data/input1.tif create mode 100644 tools/orientationpy/test-data/input2.tif diff --git a/tools/orientationpy/.shed.yml b/tools/orientationpy/.shed.yml new file mode 100644 index 00000000..6219470f --- /dev/null +++ b/tools/orientationpy/.shed.yml @@ -0,0 +1,8 @@ +categories: + - Imaging +description: Compute image orientation +long_description: Compute image orientation based on OrientationPy. +name: orientationpy +owner: imgteam +homepage_url: https://github.com/bmcv +remote_repository_url: https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/orientationpy \ No newline at end of file diff --git a/tools/orientationpy/orientationpy-cli.py b/tools/orientationpy/orientationpy-cli.py new file mode 100644 index 00000000..955fb7d5 --- /dev/null +++ b/tools/orientationpy/orientationpy-cli.py @@ -0,0 +1,54 @@ +import argparse +import csv + +import numpy as np +import orientationpy +import skimage.io +import skimage.util + + +if __name__ == '__main__': + + parser = argparse.ArgumentParser() + parser.add_argument('input', type=str) + parser.add_argument('--mode', type=str, required=True) + parser.add_argument('--sigma', type=float, required=True) + parser.add_argument('--min_coherency', type=float, required=True) + parser.add_argument('--min_energy', type=float, required=True) + parser.add_argument('--max_precision', type=int, required=True) + parser.add_argument('--output_angle_tsv', type=str, default=None) + args = parser.parse_args() + + im = skimage.io.imread(args.input) + im = skimage.util.img_as_float(im) + im = np.squeeze(im) + assert im.ndim == 2 + + Gy, Gx = orientationpy.computeGradient(im, mode=args.mode) + structureTensor = orientationpy.computeStructureTensor([Gy, Gx], sigma=args.sigma) + orientations = orientationpy.computeOrientation(structureTensor, computeEnergy=True, computeCoherency=True) + + # Compute angle according to https://bigwww.epfl.ch/demo/orientationj/#dist: + mask = np.logical_and( + orientations['coherency'] >= args.min_coherency, + orientations['energy'] >= args.min_energy * orientations['energy'].max(), + ) + angles = orientations['theta'][mask] + weights = orientations['coherency'][mask] + bin_size = 1 if args.max_precision == 0 else pow(10, -args.max_precision) + hist, bin_edges = np.histogram( + angles, + range=(-90, +90), + weights=weights, + bins=round(180 / bin_size), + ) + hidx = np.argmax(hist) + angle = (bin_edges[hidx] + bin_edges[hidx + 1]) / 2 + angle = round(angle, args.max_precision) + + # Write results + if args.output_angle_tsv: + with open(args.output_angle_tsv, 'w') as fp: + writer = csv.writer(fp, delimiter='\t', lineterminator='\n') + writer.writerow(['Angle']) + writer.writerow([angle]) diff --git a/tools/orientationpy/orientationpy.xml b/tools/orientationpy/orientationpy.xml new file mode 100644 index 00000000..8914220d --- /dev/null +++ b/tools/orientationpy/orientationpy.xml @@ -0,0 +1,97 @@ + + with OrientationPy + + 0.2.0.4 + 0 + + + operation_3443 + + + orientationj + + + orientationpy + scikit-image + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Compute the orientation of 2-D images in degrees using OrientationPy. + + OrientationPy is the pythonic successor to the well-loved OrientationJ Fiji Plugin. + It is a library that takes in images and computes the orientation of the greylevels. + A key step is the computation of image gradients, for a number of different techniques is supported. + + For more information on ``--min_energy`` and ``--min_coherency`` see: https://epfl-center-for-imaging.gitlab.io/orientationpy/orientationpy_examples/plot_fibres_2d.html#plot-hsv-composition + + + 10.1007/s10237-011-0325-z + + diff --git a/tools/orientationpy/test-data/input1.tif b/tools/orientationpy/test-data/input1.tif new file mode 100644 index 0000000000000000000000000000000000000000..203bc1bbc90a378dff3f5c1f222e4acf0d78444d GIT binary patch literal 456 zcmebD)MDUZU|`^9U|?inU<9&QftV4A&BVwI7Iy%OGeg-Rb!i16)DUQ_N1t0V4$^n1_l6<#uPgM literal 0 HcmV?d00001 diff --git a/tools/orientationpy/test-data/input2.tif b/tools/orientationpy/test-data/input2.tif new file mode 100644 index 0000000000000000000000000000000000000000..2e52fea5948aa48328c2c13de7321f505fba6ddf GIT binary patch literal 456 zcmebD)MDUZU|`^9U|?inU<9&QftV4A&BVwI7Iy%OGeg-Rb!i16(!6M_V{&EDv#fEkSqX_#uPgM literal 0 HcmV?d00001 From 638a048cada9f2648bfb338122e85beca70df58a Mon Sep 17 00:00:00 2001 From: Leonid Kostrykin Date: Tue, 12 Mar 2024 11:32:29 +0100 Subject: [PATCH 2/2] Update tools/orientationpy/orientationpy.xml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Björn Grüning --- tools/orientationpy/orientationpy.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/orientationpy/orientationpy.xml b/tools/orientationpy/orientationpy.xml index 8914220d..106f4c4a 100644 --- a/tools/orientationpy/orientationpy.xml +++ b/tools/orientationpy/orientationpy.xml @@ -44,7 +44,7 @@ - +