# HG changeset patch
# User imgteam
# Date 1712244398 0
# Node ID 1faa7e3c94ff26ac084f1ab32ffe6110fc45481d
# Parent f312d414f234a167c5d5a86ca24c492817d6f724
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/slice_image/ commit c045f067a57e8308308cf6329060c7ccd3fc372f
diff -r f312d414f234 -r 1faa7e3c94ff creators.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/creators.xml Thu Apr 04 15:26:38 2024 +0000
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff -r f312d414f234 -r 1faa7e3c94ff slice_image.py
--- a/slice_image.py Mon Nov 13 22:12:22 2023 +0000
+++ b/slice_image.py Thu Apr 04 15:26:38 2024 +0000
@@ -9,12 +9,9 @@
import skimage.util
-def slice_image(input_file, out_folder, label=None, label_out_folder=None, window_size=64,
- stride=1, bg_thresh=1, limit_slices=False, n_thresh=5000, seed=None):
- # TODO NOT Implemented:process labels
- # --> label and label_out_folder useless so far
+def slice_image(input_file, out_folder, window_size=64, stride=1, bg_thresh=1, limit_slices=False, n_thresh=5000, seed=None):
- # primarily for testing purposes:
+ # Primarily for testing purposes
if seed is not None:
random.seed(seed)
@@ -40,7 +37,7 @@
sum_image = skimage.util.img_as_uint(sum_image)
g = skimage.feature.greycomatrix(sum_image, [1, 2], [0, np.pi / 2], nnormed=True, symmetric=True)
hom = np.var(skimage.feature.greycoprops(g, prop='homogeneity'))
- if hom > bg_thresh: # 0.0005
+ if hom > bg_thresh:
continue
if limit_slices:
@@ -54,19 +51,22 @@
if __name__ == "__main__":
parser = argparse.ArgumentParser()
- parser.add_argument('input_file', type=argparse.FileType('r'), help='input file')
- parser.add_argument('out_folder', help='out folder')
- parser.add_argument('--label', dest='label_file', default=None, help='auxiliary label file to split in the same way')
- parser.add_argument('--label_out_folder', dest='label_out_folder', default=None, help='label out folder')
- parser.add_argument('--stride', dest='stride', type=int, default=1, help='applied stride')
- parser.add_argument('--window_size', dest='window_size', type=int, default=64, help='size of resulting patches')
- parser.add_argument('--bg_thresh', dest='bg_thresh', type=float, default=0, help='skip patches without information using a treshold')
- parser.add_argument('--limit_slices', dest='limit_slices', type=bool, default=False, help='limit amount of slices')
- parser.add_argument('--n_thresh', dest='n_thresh', type=int, default=5000, help='amount of slices')
- parser.add_argument('--seed', dest='seed', type=int, default=None, help='seed for random choice of limited slices')
+ parser.add_argument('input_file', type=argparse.FileType('r'), help='Input file')
+ parser.add_argument('out_folder', help='Output directory')
+ parser.add_argument('--stride', dest='stride', type=int, default=1, help='Applied stride')
+ parser.add_argument('--window_size', dest='window_size', type=int, default=64, help='Size of resulting patches')
+ parser.add_argument('--bg_thresh', dest='bg_thresh', type=float, default=0, help='Skip background patches without information using a treshold')
+ parser.add_argument('--n_thresh', dest='n_thresh', type=int, default=5000, help='Maximum number of slices to retain')
+ parser.add_argument('--seed', dest='seed', type=int, default=None, help='Seed for random choice of slices')
args = parser.parse_args()
- slice_image(args.input_file.name, args.out_folder,
- label=args.label_file, label_out_folder=args.label_out_folder,
- stride=args.stride, window_size=args.window_size, bg_thresh=args.bg_thresh,
- limit_slices=args.limit_slices, n_thresh=args.n_thresh, seed=args.seed)
+ slice_image(
+ args.input_file.name,
+ args.out_folder,
+ stride=args.stride,
+ window_size=args.window_size,
+ bg_thresh=args.bg_thresh,
+ limit_slices=args.n_thresh > 0,
+ n_thresh=args.n_thresh,
+ seed=args.seed,
+ )
diff -r f312d414f234 -r 1faa7e3c94ff slice_image.xml
--- a/slice_image.xml Mon Nov 13 22:12:22 2023 +0000
+++ b/slice_image.xml Thu Apr 04 15:26:38 2024 +0000
@@ -1,5 +1,12 @@
-
+
+
+ creators.xml
+ tests.xml
+
+
+
+
operation_3443
@@ -12,34 +19,35 @@
scipy
tifffile
-
- 0:
+ --n_thresh '$n_thresh'
#end if
- #if $control_rng:
- --seed $seed
+
+ #if len('$seed') > 0:
+ --seed '$seed'
#end if
+
&& ls -l ./out
- ]]>
-
+
+ ]]>
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
@@ -47,25 +55,38 @@
+
-
-
-
-
-
-
-
+
+
+
+
+
+
- **What it does**
+
+ **Slices an image into multiple smaller, square-shaped patches.**
+
+ For overlapping patches, set the stride to a value smaller than the patch size.
+ For non-overlapping patches, set the stride to a value identical to the patch size (or larger).
+ If the stride is set to a value larger than the patch size, parts of the original image will be skipped.
- Slices image into multiple smaller patches.
+ Optionally, patches entirely corresponding to image background are discarded.
+ To decide whether a patch corresponds to image background, the `homogeneity`_ of its `gray-level co-occurrence matrix`_ is considered.
+
+ .. _homogeneity: https://scikit-image.org/docs/stable/api/skimage.feature.html#skimage.feature.graycoprops
+ .. _gray-level co-occurrence matrix: https://scikit-image.org/docs/stable/api/skimage.feature.html#skimage.feature.graycomatrix
+
+ In addition, the number of the remaining patches can be reduced by specifying a maximum number of patches to retain.
+ Those will be selected randomly.
+
10.1016/j.jbiotec.2017.07.019
diff -r f312d414f234 -r 1faa7e3c94ff tests.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests.xml Thu Apr 04 15:26:38 2024 +0000
@@ -0,0 +1,95 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+