Skip to content

Commit

Permalink
Merge pull request #21 from ratt-ru/islet
Browse files Browse the repository at this point in the history
Added option to filter out islands below a certain size
  • Loading branch information
o-smirnov authored Jan 9, 2023
2 parents 1b16b4d + 878747f commit 5e3ad86
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions breizorro/breizorro.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ def main():
help='If an island specified by coordinates does not exist, do not throw an error')
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', 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')
parser.add_argument('--invert', action="store_true",
Expand Down Expand Up @@ -288,6 +290,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 >= 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
Expand Down

0 comments on commit 5e3ad86

Please sign in to comment.