From ab417a9339d5e2bb9c45c2c298db99934c9ed055 Mon Sep 17 00:00:00 2001 From: IanHeywood Date: Fri, 6 Jan 2023 16:10:17 +0000 Subject: [PATCH 1/2] Added option to filter out islands below a certain size --- breizorro/breizorro.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/breizorro/breizorro.py b/breizorro/breizorro.py index ebae692..a4afc23 100644 --- a/breizorro/breizorro.py +++ b/breizorro/breizorro.py @@ -149,6 +149,8 @@ def main(): help='List of islands to remove from input mask. e.g. --remove-islands 1 18 20 20h10m13s,14d15m20s') parser.add_argument('--extract-islands', dest='extract_isl', metavar='N|COORD', type=str, nargs='+', help='List of islands to extract from input mask. e.g. --extract-islands 1 18 20 20h10m13s,14d15m20s') + parser.add_argument('--minimum-size', dest='minsize', default=False, + help='Remove islands that have areas fewer than or equal to the specified number of pixels') parser.add_argument('--make-binary', action="store_true", help='Replace all island numbers with 1') parser.add_argument('--invert', action="store_true", @@ -282,6 +284,14 @@ def load_fits_or_region(filename): new_mask_image[mask_image == isl] = isl mask_image = new_mask_image + if args.minsize: + LOGGER.info(f"Removing islands that occupy fewer than or equal to {args.minsize} pixels") + mask_image = mask_image != 0 + island_labels, num_features = label(mask_image) + island_areas = numpy.array(scipy.ndimage.sum(mask_image,island_labels, numpy.arange(island_labels.max()+1))) + min_mask = island_areas >= int(args.minsize) + mask_image = min_mask[island_labels.ravel()].reshape(island_labels.shape) + if args.make_binary: LOGGER.info(f"Converting mask to binary") mask_image = mask_image!=0 From 878747f9885f6437a74f05fd5c63edc506ca0829 Mon Sep 17 00:00:00 2001 From: IanHeywood Date: Mon, 9 Jan 2023 12:40:05 +0000 Subject: [PATCH 2/2] Fix option type for --mininum-size --- breizorro/breizorro.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/breizorro/breizorro.py b/breizorro/breizorro.py index a4afc23..bd85ccb 100644 --- a/breizorro/breizorro.py +++ b/breizorro/breizorro.py @@ -149,7 +149,7 @@ def main(): help='List of islands to remove from input mask. e.g. --remove-islands 1 18 20 20h10m13s,14d15m20s') parser.add_argument('--extract-islands', dest='extract_isl', metavar='N|COORD', type=str, nargs='+', help='List of islands to extract from input mask. e.g. --extract-islands 1 18 20 20h10m13s,14d15m20s') - parser.add_argument('--minimum-size', dest='minsize', default=False, + parser.add_argument('--minimum-size', dest='minsize', type=int, help='Remove islands that have areas fewer than or equal to the specified number of pixels') parser.add_argument('--make-binary', action="store_true", help='Replace all island numbers with 1') @@ -289,7 +289,7 @@ def load_fits_or_region(filename): mask_image = mask_image != 0 island_labels, num_features = label(mask_image) island_areas = numpy.array(scipy.ndimage.sum(mask_image,island_labels, numpy.arange(island_labels.max()+1))) - min_mask = island_areas >= int(args.minsize) + min_mask = island_areas >= args.minsize mask_image = min_mask[island_labels.ravel()].reshape(island_labels.shape) if args.make_binary: