Mercurial > repos > imgteam > crop_image
annotate crop_image.py @ 1:2852af87036d draft default tip
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
| author | imgteam |
|---|---|
| date | Fri, 09 Jan 2026 14:55:04 +0000 |
| parents | d52317f0ac21 |
| children |
| rev | line source |
|---|---|
|
0
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
1 import argparse |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
2 import os |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
3 |
|
1
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
4 import dask.array as da |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
5 import giatools |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
6 import giatools.image |
|
0
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
7 import numpy as np |
|
1
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
8 |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
9 # Fail early if an optional backend is not available |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
10 giatools.require_backend('omezarr') |
|
0
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
11 |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
12 |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
13 def crop_image( |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
14 image_filepath: str, |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
15 labelmap_filepath: str, |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
16 output_ext: str, |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
17 output_dir: str, |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
18 skip_labels: frozenset[int], |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
19 ): |
|
1
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
20 axes = giatools.default_normalized_axes |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
21 image = giatools.Image.read(image_filepath, normalize_axes=axes) |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
22 labelmap = giatools.Image.read(labelmap_filepath, normalize_axes=axes) |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
23 |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
24 # Establish compatibility of multi-channel/frame/etc. images with single-channel/frame/etc. label maps |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
25 original_labelmap_shape = labelmap.shape |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
26 for image_s, labelmap_s, (axis_idx, axis) in zip(image.shape, labelmap.shape, enumerate(axes)): |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
27 if image_s > 1 and labelmap_s == 1 and axis not in 'YX': |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
28 target_shape = list(labelmap.shape) |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
29 target_shape[axis_idx] = image_s |
|
0
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
30 |
|
1
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
31 # Broadcast the labelmap data to the target shape without copying |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
32 if hasattr(labelmap.data, 'compute'): |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
33 labelmap.data = da.broadcast_to(labelmap.data, target_shape) # `data` is Dask array |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
34 else: |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
35 labelmap.data = np.broadcast_to(labelmap.data, target_shape, subok=True) # `data` is NumPy array |
|
0
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
36 |
|
1
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
37 # Validate that the shapes of the images are compatible |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
38 if image.shape != labelmap.shape: |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
39 labelmap_shape_str = str(original_labelmap_shape) |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
40 if labelmap.shape != original_labelmap_shape: |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
41 labelmap_shape_str = f'{labelmap_shape_str}, broadcasted to {labelmap.shape}' |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
42 raise ValueError( |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
43 f'Shape mismatch between image {image.shape} and label map {labelmap_shape_str}, with {axes} axes.', |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
44 ) |
|
0
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
45 |
|
1
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
46 # Extract the image crops |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
47 for label in giatools.image._unique(labelmap.data): |
|
0
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
48 if label in skip_labels: |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
49 continue |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
50 roi_mask = (labelmap.data == label) |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
51 roi = crop_image_to_mask(image.data, roi_mask) |
|
1
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
52 roi_image = giatools.Image(roi, image.axes).normalize_axes_like(image.original_axes) |
|
0
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
53 roi_image.write(os.path.join(output_dir, f'{label}.{output_ext}')) |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
54 |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
55 |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
56 def crop_image_to_mask(data: np.ndarray, mask: np.ndarray) -> np.ndarray: |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
57 """ |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
58 Crop the `data` array to the minimal bounding box in `mask`. |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
59 |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
60 The arguments are not modified. |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
61 """ |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
62 assert data.shape == mask.shape |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
63 |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
64 # Crop `data` to the convex hull of the mask in each dimension |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
65 for dim in range(data.ndim): |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
66 mask1d = mask.any(axis=tuple(i for i in range(mask.ndim) if i != dim)) |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
67 mask1d_indices = np.where(mask1d)[0] |
|
1
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
68 |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
69 # Convert `mask1d_indices` to a NumPy array if it is a Dask array |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
70 if hasattr(mask1d_indices, 'compute'): |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
71 mask1d_indices = mask1d_indices.compute() |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
72 |
|
0
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
73 mask1d_indices_cvxhull = np.arange(min(mask1d_indices), max(mask1d_indices) + 1) |
|
1
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
74 |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
75 # Crop the `data` to the minimal bounding box |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
76 if hasattr(data, 'compute'): |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
77 data = da.take(data, axis=dim, indices=mask1d_indices_cvxhull) # `data` is a Dask array |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
78 else: |
|
2852af87036d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 52a95105291e38f3410e347ed3b60d6acd6d5daa
imgteam
parents:
0
diff
changeset
|
79 data = data.take(axis=dim, indices=mask1d_indices_cvxhull) # `data` is a NumPy array |
|
0
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
80 |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
81 return data |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
82 |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
83 |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
84 if __name__ == "__main__": |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
85 parser = argparse.ArgumentParser() |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
86 parser.add_argument('image', type=str) |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
87 parser.add_argument('labelmap', type=str) |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
88 parser.add_argument('skip_labels', type=str) |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
89 parser.add_argument('output_ext', type=str) |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
90 parser.add_argument('output_dir', type=str) |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
91 args = parser.parse_args() |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
92 |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
93 crop_image( |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
94 image_filepath=args.image, |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
95 labelmap_filepath=args.labelmap, |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
96 output_ext=args.output_ext, |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
97 output_dir=args.output_dir, |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
98 skip_labels=frozenset( |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
99 int(label.strip()) for label in args.skip_labels.split(',') if label.strip() |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
100 ) if args.skip_labels.strip() else frozenset(), |
|
d52317f0ac21
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/crop_image/ commit 7a5037206d267aa7d9b7e5e062327c3464942471
imgteam
parents:
diff
changeset
|
101 ) |
